SESSIONS [solved]
Moderator: General Moderators
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
SESSIONS [solved]
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.
Many thanks.
Last edited by anthony88guy on Tue Feb 21, 2006 1:06 pm, edited 3 times in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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()
Code: Select all
domain: .example.com
path: /-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
So im trying to use the following:
But it still doesn’t work... Its kind of late (1:20am) so I'll play around with it tomorrow.
Code: Select all
session_set_cookie_params(900, '/', '.theeliteforces.com');- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
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...
It echoes "Session = logged" but I don’t get redirected...
Here is what is at the top of the page...
Thanks, Anthony
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';
}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();-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
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();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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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');
?>-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
ohh damn, I feel stupid. Thanks...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'); ?>
EDIT: works like magic