Connecting Tech Pros Worldwide Help | Site Map

PHP Session Variable

  #1  
Old July 2nd, 2009, 01:51 PM
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85
Hello,
I'm new to php,

I'm storing temp variable in SESSION

Expand|Select|Wrap|Line Numbers
  1. $_SESSION['temp']='value';
when i go from one php page to other php page, the session variable is accessible
but when i go to the other page in a subdirectory.. the SESSION variable is not accesible..

am i missing some php configuration?

pls help

regards,
Nitin Sawant
  #2  
Old July 2nd, 2009, 02:09 PM
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,063
Provided Answers: 2

re: PHP Session Variable


Quote:
but when i go to the other page in a subdirectory
PHP does not have a GOTO command!
  #3  
Old July 2nd, 2009, 03:08 PM
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85

re: PHP Session Variable


Hello code green,
I'm navigating from one page to another page in subdirectory
suppose: current page 'index1.php'
then in that page i write
Expand|Select|Wrap|Line Numbers
  1. <a href='std/index2.php'>go to subdirectory</a>
  2.  
then the session variable is lost when i navigate to 'index2.php' in std subdirectory..
  #4  
Old July 2nd, 2009, 03:25 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: PHP Session Variable


is in that page the session restarted?
  #5  
Old July 2nd, 2009, 03:49 PM
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85

re: PHP Session Variable


nope, the session is not restarted..

in index1.php page i wrote..
Expand|Select|Wrap|Line Numbers
  1. if (!isset($_SESSION)) {
  2.         session_start();
  3. }
  4. $_SESSION['temp']='value';
  5.  
and in the index2.php page in std directory i'm trying to retrieve the variable
Expand|Select|Wrap|Line Numbers
  1. $var=$_SESSION['temp'];
  2.  
  #6  
Old July 2nd, 2009, 04:24 PM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9

re: PHP Session Variable


Quote:
Originally Posted by code green View Post
PHP does not have a GOTO command!
It does now :P
  #7  
Old July 2nd, 2009, 04:40 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: PHP Session Variable


Quote:
Originally Posted by NitinSawant View Post
nope, the session is not restarted..
as I thought… you need to open a session first:
Quote:
Originally Posted by php.net
Note: […] Also note that you must start your session using session_start() before use of $_SESSION becomes available. […]
  #8  
Old July 3rd, 2009, 04:21 AM
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85

re: PHP Session Variable


But i'm starting the session on index page only
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
  #9  
Old July 3rd, 2009, 05:35 AM
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85

re: PHP Session Variable


well, what i was missing is adding 'session_start();' on every page...

nevermind, i got it..

prob. solved


regards,
Nitin Sawant
  #10  
Old July 3rd, 2009, 10:56 AM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9

re: PHP Session Variable


Quote:
Originally Posted by NitinSawant View Post
well, what i was missing is adding 'session_start();' on every page...

nevermind, i got it..

prob. solved


regards,
Nitin Sawant
That's exactly what Dormilich told you to do. :)
  #11  
Old July 6th, 2009, 04:39 PM
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,075

re: PHP Session Variable


Quote:
Originally Posted by code green View Post
PHP does not have a GOTO command!
Thanks for the laugh starting my Monday, it's been a sh*tty week.







Dan
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
can i assign value returned from javascript function to php session variable rahullko05 answers 2 March 14th, 2009 06:00 PM
PHP session variable problem maingroup answers 3 December 7th, 2007 02:58 AM
php session variable Jack answers 3 July 4th, 2007 01:05 AM
PHP session variable twinklyblue answers 23 June 7th, 2007 06:23 AM