Forum Moderators: coopster

Message Too Old, No Replies

php sending variables from one webpage to other

same variables in different webpage

         

ksugam

9:15 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



Hello,
I have a menu page which uses GET to take the value of 2 variables from the URL....
Now i have a list of links on the menu page. I want to forward the values of this two variables to all the pages tht exist on the menu page...

say for example: I use GET to fetch the month from the URL:

www.example.com?month=January

I store this is variable $month on the menu page....
The menu page has links like Visitors, Page Views, etc...

So when the user clicks on Visitors link, I want to send this $month variable to Visitors page....

How can i do this?

Thanks!

darrenG

10:09 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



The most obvious answer is to use append a query string containing the data you need to pass, also known as GET.

Alternatively, you could store the data in the SESSION array, or, a la .NET, make the page into a giant form, and use POST.

Depending on the amount of data, and other factors, you may choose to store the data in files, or in a database and pull the data as required.

menace_sa

6:22 am on Feb 12, 2008 (gmt 0)

10+ Year Member



Sessions is the best way

Add session_start(); right at the top of your php on all pages. Once you get the month variable assign it to a session variable like $_SESSION["month"] = $month;

Then when accessing $month = $_SESSION["month"];

Thats it, should be accessible throughout

ksugam

5:40 pm on Feb 12, 2008 (gmt 0)

10+ Year Member



Great...
One more question....
So when i assign $_SESSION['month'], everything works fine....What this does is, it passes the month selected by the user on menu page to any other page listed in the menu page.....Similarly, when the user is on other page, he/she can again change the month on tht particular page (which i was getting using the $_GET)....
so now my assignment on other page is $month=$_SESSION['month']....so the month entered on other page does not work....
How can i make $_GET and $_SESSION both work simultaneously on same page?

Is there a way like, if the link is clicked once, use $_SESSION, but if the user enters month in the other page, use $_GET?

eelixduppy

6:41 pm on Feb 12, 2008 (gmt 0)



Something like the following should do:

session_start();
$month = (isset($_SESSION['month']))? $_SESSION['month']: $_GET['month'];

This checks to see if the session variable 'month' is set and if it is, it makes $month take on that value. If not, it gets the value from the GET url query.

ksugam

7:16 pm on Feb 12, 2008 (gmt 0)

10+ Year Member



This is not wht i am looking for....
The session variable 'month' is definitely set....
Wht i want is, i want to chk if the user has input month on the other page
When the user is taken from menu page to the other page, the session variable month is used, but when the user enters a new month on other page, how to get tht?

ksugam

8:19 pm on Feb 12, 2008 (gmt 0)

10+ Year Member



Got it....
I was looking for this:

$month=(isset($_GET['month']))?$_GET['month']:$_SESSION['month'];

Thanks all for your help....

eelixduppy

9:28 pm on Feb 12, 2008 (gmt 0)



Sorry, I misunderstood what you were looking for. Glad you got it resolved.