Page 1 of 1
SESSIONS [solved]
Posted: Sun Feb 19, 2006 7:16 pm
by anthony88guy
Okay... so I have a members area located at a sub-domain, but I have a login on the domain (home page). So in order for me to get the login to work I must send the form to a login script on that sub-domain. What would be the best route to link the domain and the sub-domain? Some type of cookie, linked to the database? When I go to the homepage and you’re logged in through the sub-domain, you should be redirect to the sub-domain, but you’re not since the session doesn’t exist for that domain. I hope thats understandable.
Many thanks.
Posted: Sun Feb 19, 2006 7:28 pm
by Burrito
you could pass the sessID as a form var and then reset the session on the other 'domain'
Posted: Sun Feb 19, 2006 7:35 pm
by feyd
you can set the cookie to match against the domain and web root, which will get the browser to send it when accessing any part of your domain, be they subdomain or not.
session_set_cookie_params()
Posted: Sun Feb 19, 2006 8:08 pm
by anthony88guy
Do I have to set the cookie params once, or on each page? I think I read each page.
Thanks for your help.
Posted: Sun Feb 19, 2006 8:14 pm
by feyd
each page that uses sessions.
Posted: Mon Feb 20, 2006 12:20 am
by anthony88guy
So im trying to use the following:
Code: Select all
session_set_cookie_params(900, '/', '.theeliteforces.com');
But it still doesn’t work... Its kind of late (1:20am) so I'll play around with it tomorrow.
Posted: Mon Feb 20, 2006 12:32 am
by feyd
what other code is this being used with? If you're using a
header() redirection the cookie may not set as the browser may choose to ignore it, or you server didn't send the cookie.
session_write_close() can help fix the latter.
Posted: Mon Feb 20, 2006 11:47 am
by anthony88guy
Thanks a great deal, everything works great.
-anthony
Posted: Mon Feb 20, 2006 6:20 pm
by anthony88guy
Okay, so now that I have the sessions working on all sub-domains and domains. I'm having an issue when you’re logged in, if you go back to the home page you should be directed to the sub-domain where the member’s area is located, but your not. I have a $_SESSION variable that holds the value if your logged in your not.
Here is what I have...
Code: Select all
if($_SESSION['loggedin'] == 1)
{
header('http://members.theeliteforces.com/index.php');
}
if($_SESSION['loggedin'] == 1)
{
echo 'Session = logged';
}
else
{
echo 'Session = not logged';
}
It echoes "Session = logged" but I don’t get redirected...
Here is what is at the top of the page...
Code: Select all
ob_start();
session_write_close();
session_set_cookie_params(0, '/', '.theeliteforces.com');
session_start();
Thanks, Anthony
Posted: Mon Feb 20, 2006 7:33 pm
by feyd
the close should come after the session is started...
Posted: Tue Feb 21, 2006 12:45 pm
by anthony88guy
feyd wrote:the close should come after the session is started...
Code: Select all
session_set_cookie_params(0, '/', '.theeliteforces.com');
session_start();
session_write_close();
This is how I’m starting most of the pages, depending if its the login page where ob_start(); is at the top.
Now I wont be redirect from the domain to sub-domain on login with the session_write_close(); being declared
after the session is started.
What I don’t get is I have a little test shown in the above post, where it echoes’s out session = logged, but it won’t re-direct…under the some conditional statement.
Thanks for your help once again, Anthony
Posted: Tue Feb 21, 2006 12:54 pm
by feyd
your header call is missing one tiny piece of crucial information: Location.
Code: Select all
<?php
header('Location: http://example.com/full/url/to/script.php');
?>
Posted: Tue Feb 21, 2006 1:01 pm
by anthony88guy
feyd wrote:your header call is missing one tiny piece of crucial information: Location.
Code: Select all
<?php
header('Location: http://example.com/full/url/to/script.php');
?>
ohh damn, I feel stupid. Thanks...
EDIT: works like magic