cancel
Showing results for 
Search instead for 
Did you mean: 

[PAYH] $_SESSION not working now

SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

[PAYH] $_SESSION not working now

Hi
Why is this not working on the PAYH platform?
I know it will have something to do with php version 5+
here is a bit of code that is working on the ccgi platform (php v4) but not on PAYH (php v5)
This bit is on my login page

if($name == $row['logon_name'] and $pwd == $row['pwd'])
{
session_start();

$_SESSION['username'] = $row['user_name'];
$_SESSION['password'] = $pwd;
$_SESSION['jobtitle'] = $row['job_title'];
$_SESSION['userisvalid'] = True;
header("Refresh: 0; url=admin/protected/index.php");
exit();
}else{
$badnameorpwd = "<p class='redalert'>Login credentials are not valid!";
$action = "fail";
}

This bit is on the receiving page

<?php
session_start();
if(!$_SESSION['userisvalid'])
{
header("Refresh: 0; url=../../login.php");
exit();
}
?>
46 REPLIES 46
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

I can't immediately spot the problem, but can confirm that $_SESSION is working on PAYH.
Gabe
prichardson
Grafter
Posts: 1,503
Thanks: 1
Registered: ‎05-04-2007

Re: [PAYH] $_SESSION not working now

What actually happens?
Does it attempt the redirect at all to admin/protected/index.php at all?
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

Sorry, It's failing at the receiving page
<?php
session_start();
if(!$_SESSION['userisvalid'])
{
header("Refresh: 0; url=../../login.php");
exit();
}
?>

It seems to be reading the value of $_SESSION['userisvalid'] as not true so it redirects you back to the login page.
This bit of code is the first few lines of all pages in my admin area.
Peter_Vaughan
Grafter
Posts: 14,469
Registered: ‎30-07-2007

Re: [PAYH] $_SESSION not working now

Can you try printing the session id from the call to session_id() after session_start() in both pages to see if they are the same?
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Or check the PHPSESSID (or whatever you've called it) cookie. If the session id is retained but not the data, chances are it's only getting written after the redirect. Try it with session_write_close() before the redirect.
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

Thanks guys
Peter: The session_id is different on each page
Gabe: I'm not using any cookies
The code is identical for my live site on th PN ccgi platform and my trial site on the PAYH platform?
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Unless you have session.use_cookies off then you are using cookies, and if you're not then you need to add the id to the redirect header. Try it with session_write_close() before the redirect.
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

Hi Gabe
Tried that and makes no difference.
Something must be different about php 4 and 5 thats causing this I'm sure but I dont know what.
My php v4 works perfectly well using the code i posted Huh
Bri
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

The session_id is different on each page call
none of the $_SESSION variables are being passed
I've demonstrated it with simple

echo "Session ID = ".session_id();
echo "User = ".$_SESSION['username'];
echo "Job = ".$_SESSION['jobdesc'];
echo "Nickname = ".$_SESSION['nickname'];

etc etc etc
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Just to confirm: does the PHPSESSID cookie ever get written?
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

sorry Gabe, I don't even know what that means!
I haven't done anything with session cookies before.
When i first put a copy of my live site on the PAYH platform, i had to do loads of re-writing because v5 is so different. ie. In php v4.2, if you link to a page with something like ../leaguetables.php?divid=3 then the $divid variable is automatically created but in version 5 you have to do $divid=$_GET['divid']; or $_POST['divid']; if it comes from a textbox on a form etc
Is something different in v5 about the $_SESSION variables?
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Sorry to be obscure. Session ids are passed either via a cookie (default) or via the uri. If you look in your cookies, you should find one called PHPSESSID. The value should be the same as the id you echo.
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

Nope, there's no PHPSESSID cookie
I'm totally stumped Sad
Why does it work on the PN ccgi platform???????
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

A cookie should be set during your session on ccgi (please confirm). It'll vanish when the session ends.
On the new site, you could try testing the page without the redirect. When the page is served without the redirect, do you see the session id in the uri, or a PHPSESSID cookie?
Gabe