Page 1 of 1

session lost when meta refresh

Posted: Fri Jul 14, 2006 4:52 pm
by yamobe
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

Posted: Fri Jul 14, 2006 4:59 pm
by John Cartwright
and where does $session_variable come from?

try

Code: Select all

echo '<pre>'; print_r($_SESSION); echo '</pre>';
and see if there are any contents.

Posted: Fri Jul 14, 2006 5:56 pm
by PrObLeM
you do use:

Code: Select all

$_SESSION['session_name'] = 'some value';
right?

Posted: Fri Jul 14, 2006 5:58 pm
by RobertGonzalez
$session_variable has no value until you define it. Set it to something then try it and it should work.

Posted: Fri Jul 14, 2006 5:59 pm
by Ward
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">

Posted: Fri Jul 14, 2006 7:06 pm
by yamobe
I tried this

Code: Select all

echo '<pre>'; print_r($_SESSION); echo '</pre>';
when i run the page I get
Array(
session_variable => its value
)

When the page refresh I get
Array(
)


I also tried

Code: Select all

session_write_close();
without results...

any other ideas? I'm stuck here :(

Posted: Fri Jul 14, 2006 7:27 pm
by Chris Corbyn
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.

Posted: Fri Jul 14, 2006 7:49 pm
by yamobe
d11wtq 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.
register_globals is ON, but security is not an issue here... I don't care about it

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

Posted: Fri Jul 14, 2006 9:55 pm
by RobertGonzalez
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.

Posted: Sat Jul 15, 2006 3:35 am
by Chris Corbyn
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.
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).

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.