PHP - What are the various methods to pass data from one web page to another web page?

What are the various methods to pass data from one web page to another web page?

Different methods to pass data from one web page to another:

1. Store the data in a session variable. By storing the data, the data can be passed from one page to another.

2. Store data in a cookie: By storing data in a persistent cookie, data can be passed from one form to another.

3. Set the data in a hidden field and post the data using a submit button.

Short note on passing parameter by reference and returning parameter by reference with examples.

Passing parameter by reference: In PHP, variables can be passed by reference so as to modify them. Variables, statements which have new and references returned from function can be passed.

Example: references returned from function
<?php
Function &sample()
{
     $a =1;
     Return &a;
}
Foo(bar());
?>

Returning parameter by reference: Returning parameter by reference is used when a function to find to which variable a reference should be bound.

Example:
$obj = new foo;
$myValue = &$obj->getValue();    // $myValue is a reference to $obj-value, which is 42.
$obj->value = 2;
echo $myValue;

How many ways I can redirect a PHP page?

1. Header function in PHP redirects to a new URL

Example:
<?php
      header("Location: http://www.redirecturl.com/");
?>

2. http_redirect() is also used to redirect to a new page or URL.

Syntax:
void http_redirect ( [string url [, array params [, bool session = FALSE [, int status]]]] )

Here, the URL is the path of the new page. params can be some query parameters followed by whether the session information needs to be passed and the custom response status code.
PHP - Describe how PHP Works.
Describe how PHP Works - Any PHP web page first interacts with the interpreter once a request I sent from the browser...
PHP - Explain how to work with Permissions in PHP.
Explain how to work with Permissions in PHP - Permissions in PHP are very similar to UNIX. Each file has three types of permissions....
PHP - Describe how to create a simple AD rotator script without using database in PHP.
How to create a simple AD rotator script without using database in PHP - Following are the steps to create a simple AD rotator script without using database in PHP....
Post your comment