Hello,
I am pretty new to PHP and programming in general.
I am using the $SESSION variable and keep getting the error "undefinded index" after trying to reference a variable from a different page in my script.
After searching the forums and following the suggestions I was unable to find an answer to my issue. After going through the documentation I think I found the answer but am unsure becuase out of more than a dozen posts I did not see anyone even reference the function I used.
I am using IIS 5.0, and PHP 4.3.2, IE6sp1 and am accessing as "localhost"
If I run page1.php I get "undefined index error" unless, in the same window I open page1.php again by retyping the URL(back or reload wont work):
This does not work (it gives 'undefined index' error):
<?php
//page1.php
session_start();
$_SESSION['count'] =1;
header('Location: page2.php');
?>
<?
//page2.php
session_start();
echo $_SESSION['count'];
?>
This does work:
<?php
//page1.php
session_start();
$_SESSION['count'] =1;
header('Location: page2.php?' . SID . '');
?>
<?
//page2.php
session_start();
echo $_SESSION['count'];
?>
If I use a hyperlink to page2.php instead of header() the variables are also passed successfully.
Can anyone give me input on this? Does anybody have any more drawbacks or quirks when using header() . Any issues with using SID the way I did?
Should I just forget about using header()?
if you can give me good input on ANY of my questions I really appreciate it.
chesterguyca (thats %ca for Canada)
PS... And I hope this post also helps someone experiencing the same problem.