cancel
Showing results for 
Search instead for 
Did you mean: 

[PAYH] $_SESSION not working now

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

Re: [PAYH] $_SESSION not working now

Finally Resolved it Gabe Smiley
I needed to add the SID to my redirect string thus
header("Refresh: 0; url=admin/protected/index.php?".SID);

That's all it was
This now makes sense of what you were saying because SID is PHPSESSID so the code above passes the session id to the receiving page.
I upload these two test pages to prove this point
Example #1 A session example: page1.php

<?php
// page1.php
session_start();
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green';
$_SESSION['animal']  = 'cat';
$_SESSION['time']    = time();
// Works if session cookie was accepted
echo '<br /><a href="page2.php">page 2</a>';
// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>

After viewing page1.php, the second page page2.php will magically contain the session data. Read the session reference for information on propagating session ids as it, for example, explains what the constant SID is all about.

Example #2 A session example: page2.php

<?php
// page2.php
session_start();
echo 'Welcome to page #2<br />';
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal'];  // cat
echo date('Y m d H:i:s', $_SESSION['time']);
// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php">page 1</a>';
?>

i got this info from http://uk2.php.net/manual/en/function.session-start.php
Thanks very much for all your help and patience Gabe
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Bingo!
I wonder why the session cookie isn't being accepted from PAYH. Not blocked client-side? Ideally, it's more secure as a cookie. For my own site on PAYH I set session.use_only_cookies on. Any way, glad it's working via the uri.
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

CORRECTION, It's not over yet.
Even though it works now as explained in the post above, each visit to a page in the admin/protected area sends me back to the login page.
Remember, the first lines of code in all pages in the admin area are...
<?php
session_start();

if(!$_SESSION['userisvalid'])
{
header("Refresh: 0; url=../../login.php");
exit();
}
?>

I've tried it with and without the SID on the end of the redirect string but it always sends me back to the login page.
The PHPSESSID is different for each visit
On the live site, once you've logged in you can go in and out of the admin area until you log out?
What do I do now? Huh
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Thinks... the difference between the test pages and your site is that the first test page links to the second rather than redirecting. It may be that the session data hasn't been written before the redirect on your page. Tentatively: try session_write_close() before the redirect.
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

Yes tried that mate, no joy.
Those two test pages prove that it won't work without putting the SID into the string but just when i thought i had fixed it i get this new problem that once it's gone through the login process and got me in to the admin area, i cant move around because the $_SESSION['userisvalid'] variable is empty and so it sends me back to the login page which then creates a new SID. Vicious cirlce Angry
Still can't get my head round what's different about the two platforms.
Here's some more infor from php.net
A session created with session_start will only be available to pages within the directory tree of the page that first created it.
i.e. If the page that first creates the session is /dir1/dir2/index.php and the user then goes to any page above dir2 (e.g. /dir1/index.php), session_start will create a new session rather than use the existing one.

Don't know if relevent or not
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Test page works without appending SID for me, also on PAYH. Sure you're not refusing cookies from your plushost domain?
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

definately doesn't work for me.
Done it at home and work now, same result.
It will only work if i include the SID in the redirect but then i've still got this other issue where it keeps returning to the login
It's doin my ed in now Angry
how can i guarantee that i'm not blocking them from plushost?
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Depends on your browser. Assuming you're getting a cookie from your site on ccgi, check your plushost site isn't in your list of exceptions, or write a short script to set a cookie, park it on plushost and check it works.
If you're stuck with the uri method, you will need to pass the session id to all subsequent pages explicitly.
Try editing your testpage as echo '<br /><a href="page2.php?PHPSESSID=' . session_id() . '">page 2</a>';
See that now appears in the uri? You could then use javascript to pass that to any subsequent pages - not such a secure method but it should work.
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

Perhaps I should explain that I don't know the first thing about cookies
I wouldn't know how to write a script to set a cookie and park on plushost. I don't know what any of that means.
I've checked my internet options, there are no restrictions on cookies at all.
I still don't see why its different on the two platforms but i know that i cant go live on PAYH. There are so many changes i have to make
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

[PAYH] $_SESSION PlusNet Staff help required

Hi
Is there something fundamentally different about payh plathform that is stopping the $_SESSION variables working?
I've lost 2 days trying to make my exsisting CCGI code work on the new platform.
I've also taken up an awful lot of Gabe's time. See previous thread
Will Plusnet staff please help
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

Check the exceptions list, or whatever your browser uses for a list of always-accept, always-deny, etc.
See test examples under setcookie in the php manual.
You can set session cookies on PAYH. In that respect, there is no difference. Plenty of others, but not that one.
You can see the php settings for sessions via phpinfo:
<?php
phpinfo();
?>
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

OK, done the setcookie
it didn't write anything to my cookies
I've done the phpinfo and had a browse at the session stuff. What should i see thats relevent to this issue?
session.use_cookies is on
session.use_only_cookies is off
anything else?
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: [PAYH] $_SESSION not working now

I don't know why, but it does sound like you are unable to accept cookies from your plushost domain, session or otherwise. Do you have access to another browser: one you've never used with your plushost pages?
Gabe
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

yes i've got both google chrome and firefox, i'll give them i try but i'm not hopeful
EDIT:
Same result in both Gabe Sad
Any help from PlusNet staff yet?
The transistion from ccgi to payh is proving to be very painful
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: [PAYH] $_SESSION not working now

You know this problem as well as me now Gabe.
is there an alternative way to acheive what I'm trying to. i.e. user login to a protected area.
I know i can use the new protected directories method of the PAYH platform but I don't like it because you can't build your own login page. You have to go with the popup dialog login box.
I just don't know what to try next