session lost when meta refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yamobe
Forum Newbie
Posts: 13
Joined: Mon Jun 19, 2006 9:42 am

session lost when meta refresh

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

you do use:

Code: Select all

$_SESSION['session_name'] = 'some value';
right?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

$session_variable has no value until you define it. Set it to something then try it and it should work.
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post 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">
yamobe
Forum Newbie
Posts: 13
Joined: Mon Jun 19, 2006 9:42 am

Post 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 :(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
yamobe
Forum Newbie
Posts: 13
Joined: Mon Jun 19, 2006 9:42 am

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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