Page 1 of 1

PHP Sessions

Posted: Thu Jul 28, 2005 9:54 am
by farid
Hi!!

I have a program that in the first page has a text box, and a submit button,in the second page I call the text box called var in PHP and I make it a Variable session, and in the third page I call such variable, but it says it is undefined, the session_start() is already put in the first page. The funny thing is that in works only for some computers.

CODE first page:

Code: Select all

<form name="form1" method="post" action="2.php">
  <?php 
print_r($_SESSION);
?>
  <p> 
    <input name="var" type="text" id="var" size="20" maxlength="20">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
2 page:

Code: Select all

<form name="form1" method="post" action="3.php">
  <?php 
$_SESSION['var']=$_POST['var'];
echo "pag inter", "<br>";
print_r($_SESSION);
?>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
3 page:

Code: Select all

<form name="form1" method="post" action="1.php">
  <?php 
echo $var=$_SESSION['var'];
print_r($_SESSION);
?>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
Hope someone can help me!! Thanks in advance!!

Posted: Thu Jul 28, 2005 10:12 am
by timvw
You need to call session_start in page2 and page3 too...

Posted: Thu Jul 28, 2005 10:31 am
by farid
yeah, it is called also in such pages, sorry I did not explain that :oops:

Posted: Thu Jul 28, 2005 10:34 am
by farid
Ok, I do not know what happened but, the session works now for only the second page, it appears on the

Code: Select all

print_r ($_SESSION);
But the Array is empty on the third page

:cry:

Posted: Thu Jul 28, 2005 11:36 am
by josh
Try changing

Code: Select all

echo $var=$_SESSION['var'];
to

Code: Select all

$var=$_SESSION['var'];
echo $var;

Posted: Thu Jul 28, 2005 11:59 am
by farid
Nope, It does not works. The message that appears is:

Notice: Undefined index: var in D:\inetpub\InetGREGION9\php\fichas\3.php on line 10
Array ( )

Posted: Thu Jul 28, 2005 12:21 pm
by josh
So var is being set, its just that $array[$var] doesn't exist? In which case your sessions are working fine.

Or wait, was "line 10" the print_r($_SESSION); ?




Suggestion to admins: Make a way for php tags to start counting lines at a specified #

Posted: Thu Jul 28, 2005 12:31 pm
by nielsene
jshpro2 wrote: Suggestion to admins: Make a way for php tags to start counting lines at a specified #
There is
viewtopic.php?t=21171

Just nobody uses it...

Code: Select all

echo &quote; starting from line 10&quote;;

Posted: Thu Jul 28, 2005 12:38 pm
by josh
mmm, never read past feyd's first post in that topic. Thanks

Posted: Thu Jul 28, 2005 12:47 pm
by farid
Ok, the thing is that the variable: $var says that does not exist, so when I write the print_r ($_SESSION) it prints the values of such session, which is an array, so that is why it says Array ().

Posted: Thu Jul 28, 2005 1:01 pm
by josh
mm ok so it IS the session like you said, mind posting the entire code for page 2 and 3 ?

Posted: Thu Jul 28, 2005 1:41 pm
by farid
done it, if I do it like that it do works, is like the $_SESSION is the same thing as the $_POST, which of course is totally different but it does not behaves like that. :oops: :cry:

Posted: Thu Jul 28, 2005 3:39 pm
by farid
But it stills does not works the session, and I must make it work, 'cause a system that I have done of about 40 web pages of php depend on sessions.

please heeeelp!!!

Posted: Thu Jul 28, 2005 5:28 pm
by farid
someone heeeeeeeeeeeelp!! Do somebody knows if it has to do with a problem in the php ini file??

Posted: Thu Jul 28, 2005 5:34 pm
by John Cartwright
farid wrote:Ok, the thing is that the variable: $var says that does not exist, so when I write the print_r ($_SESSION) it prints the values of such session, which is an array, so that is why it says Array ().
If it only outputs Array() that means you have an empty array, thus your session vars were not set or your session was not started on that page.

By the way, please make use of the edit button instead of posting 3 posts in a row :P