session lost when meta refresh
Moderator: General Moderators
session lost when meta refresh
hello, this is a piece of my code mypage.php
<?php
session_start();
echo $session_variable;
?>
<META HTTP-EQUIV="refresh" content="5;URL=http://.../mypage.php">
when I enter mypage.php there is no problem, and $session_variable is correct
after 5 seconds, the page refresh with the html code and get this error:
Notice: Undefined variable: session_variable in C:\Archivos de programa\Apache Group\Apache2\htdocs\mypage.php on line 2
then I enter again to mypage.php and when it refresh there is no problem
any idea?
this:
<SCRIPT LANGUAGE="javascript">
setTimeout("location.href='mypage.php'",5000)
</SCRIPT>
doesn't work well for my aplication, so it is not a possible thing to do
<?php
session_start();
echo $session_variable;
?>
<META HTTP-EQUIV="refresh" content="5;URL=http://.../mypage.php">
when I enter mypage.php there is no problem, and $session_variable is correct
after 5 seconds, the page refresh with the html code and get this error:
Notice: Undefined variable: session_variable in C:\Archivos de programa\Apache Group\Apache2\htdocs\mypage.php on line 2
then I enter again to mypage.php and when it refresh there is no problem
any idea?
this:
<SCRIPT LANGUAGE="javascript">
setTimeout("location.href='mypage.php'",5000)
</SCRIPT>
doesn't work well for my aplication, so it is not a possible thing to do
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
and where does $session_variable come from?
try and see if there are any contents.
try
Code: Select all
echo '<pre>'; print_r($_SESSION); echo '</pre>';you do use:
right?
Code: Select all
$_SESSION['session_name'] = 'some value';- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Maybe your session is not being saved before you refresh. Call 'session_write_close()' before you refresh, and see if that fixes it.
Code: Select all
<?php
session_start();
$_SESSION['myVar'] = "testing";
session_write_close();
?>
<META HTTP-EQUIV="refresh" content="5;URL=http://.../mypage.php">I tried this
when i run the page I get
Array(
session_variable => its value
)
When the page refresh I get
Array(
)
I also tried
without results...
any other ideas? I'm stuck here
Code: Select all
echo '<pre>'; print_r($_SESSION); echo '</pre>';Array(
session_variable => its value
)
When the page refresh I get
Array(
)
I also tried
Code: Select all
session_write_close();any other ideas? I'm stuck here
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
register_globals is ON, but security is not an issue here... I don't care about itd11wtq wrote:I think you're going to have to post the entire page contents. FYI, $session_variable is not the same as $_SESSION['session_variable'] and will only work if register_globals is ON in php.ini. That's not good since it allows your script to be "injected" with globals from GET/POST etc.
I have 2 pages that are exactly the same with the only difference that one of them use the refresh and the other doesn't
The one that refresh has this problem, the other doesnt...
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Yeah it's not good practise to use register_globals. For a start it's ambiguous where the data is even coming from, and it just makes for poor coding (not saying your code is poor, just referring generally to the use of register_globals).Everah wrote:Post the first few lines of each sessioned page. And seriously, I would turn register_globals off. Even if you are testing on a development platform, it is never a good idea to develop as thought they were on. It is just good practise.
If the session is being turned on and off so sequentially as you describe then I'd still rather see the actual code because it sounds like a logic issue.