top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

In How many ways ,one can pass the variable through navigation between the pages in PHP?

+1 vote
452 views

I have just started learning PHP. So Can anyone tell me that How many methods are there to pass the variable through navigation between the different pages ?

posted May 22, 2014 by Amritpal Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

Most of the programmers who start learning PHP after other non web centric languages like c/c++/perl/python where that they can just pass around global variables from one module/file to another , think that they can do just that from one php script to another across different invocations of URL.

This in not possible in PHP as it is a state less language (HTTP is a stateless protocol) and every request is a new request. The two possible alternative ways in which you can do this is
1) Maintain a session variable. Session variables can be persisted between different invocations
2) Have the variables being shared in DB such that the different PHP pages can access them.

Another possible option is cookies and in HTML5 you also have an option of local storage but these are client side storage options and if the browsers disable them then you have no workarounds.

answer May 22, 2014 by Shyam Purkayastha
0 votes

1.GET or QUERY STRING
2.POST
By using these two ways ,You can have the variables being shared in your database and can make different PHP pages to access variables.

answer May 23, 2014 by Mohit Sharma
Similar Questions
0 votes

I want to use session to pass variables through pages using php.
Site structure is:
1. header.php
2. column.php
3. footer.php
4. index.php
Pages 1, 2 & 3 are included into the index.php.

In header.php page, there is a drop down, in which links(cities) are placed where users will select city.
Now, I want to do code to store selected values into a variable and pass to multiple pages.

Please help on this..

+1 vote

I am trying to pass a "PHP variable" from Apache (2.2.15) to Tomcat (7.0.27) but without success. The apache is used as front-end server of tomcat using mod_proxy_ajp.

I verified that I can pass only variable set by Apache (e.g. using SetEnv directive); How I can pass a variable set by PHP to Tomcat?

...