top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Use of session variables to pass variables through pages using php

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..

posted Aug 25, 2014 by anonymous

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

1 Answer

0 votes

You can try session variable in the following way -

//On page 1
$_SESSION['varname'] = $var_value;

//On page 2
$var_value = $_SESSION['varname'];
answer Aug 25, 2014 by Salil Agrawal
Similar Questions
+1 vote

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 ?

0 votes

I would like to make a timeout length to session variables, so that if a user didn't use the browser page for let's say 5 minutes - the session variables would expire and the user would need to login again.

Q: What's the best way to implement this functionality?

0 votes

I have a question about using a php user class and session variables. Let's say that I have managed to create a user class that finds a particular person from the database query.

As I move about the site from page to page it would be nice to be able to use the current user inside the user class without needing to re – look them up in the database multiple times

Q: so is there a way to combine the current active user in the class with session variables so that they can be used multiple times? If so, how would this work?

+1 vote

Why I can't read static variables of a child class, even so the variable is protected or public?

Here's what I tried:

class A {
 protected static $foo = "bar";

class B {
 public function readFoo() {
 return self::$foo;

When now calling B::readFoo, I get the following error:

var_dump((new B())->readFoo());

PHP Fatal error: Access to undeclared static property: B::$foo in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. B->readFoo() php shell code:1

Fatal error: Access to undeclared static property: B::$foo in php shell
code on line 1

Call Stack:
 86.2643 231224 1. {main}() php shell code:0
 86.2666 231352 2. B->readFoo() php shell code:1
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.