Page 1 of 1

(RESOLVED) Setting Cookies (Pt. 2)

Posted: Mon Aug 28, 2006 11:53 pm
by LuiePL
This is sort of a continuation of this article.

I moved this site over to it's new, permanant, address, and I've run into an issue. I have a login on the left side of the page which is meant to give easy and quick access to the members only section of the site. When I login, it brings me to the main members page with all the "logged in" info being displayed properly, except the left login part still shows the username/password boxes, and I threw in an "echo "cookie not set";" in to it, and that shows up as well. The left login page is in the "members" subdomain, which I thought was the problem, beacuse I had it in the root directory at first. But that didn't make a difference.

However, when I go directly to the php page itself, it's showing me as logged in. This makes no sense to me what so ever.

I can't get this to work in FF 1.5 or IE 6

Index:

Code: Select all

if ($_SERVER['REQUEST_METHOD'] == "POST")
	{
		$check = ( isset($_POST['set']) ) ? $_POST['set'] : ''; //The 'set' is if the user wants to be remembered
		$cookie_data = $name;
		$expiry = 0; //Expire when the browser is closed
		$directory = "/";
		$domain = "members.mydomain.com";
	
		if ( $check )
			{
				$expiry = time() + 365*84000;
			}
	
		setcookie ("user", $cookie_data, $expiry, $directory, $domain, "0");
		header('Location: http://members.mydomain.com/index.php');
	}

Posted: Wed Aug 30, 2006 5:10 pm
by LuiePL
Anyone?

Posted: Thu Aug 31, 2006 7:44 pm
by LuiePL
I got it working now.

I ended up using <IFRAME> on the page, and changing the cookie domain to ".mydomain.com". That way, no matter what subdomain it's on, the <IFRAME> height works correctly.

When I get the website to my liking, my next endeavor will be the wonderful world of AJAX. But that's another topic all together. Hopefully this will help out someone else if they run into a similar problem.

Posted: Thu Aug 31, 2006 8:20 pm
by RobertGonzalez
What does the iframe have to do with the cookie?

Posted: Thu Aug 31, 2006 11:08 pm
by LuiePL
Everah wrote:What does the iframe have to do with the cookie?
I'm using:

Code: Select all

if (isset($_COOKIE['cookie'])) {
<IFRAME src='page.php' height='250'></IFRAME>
}
else {
<IFRAME src='page.php' height='150'></IFRAME>
}
Because, once the user is logged in, there's less information in it, so I ended up having a lot of blank space. I noticed with it being kept at "members.mydomain.com" on the other subdomains it wasn't resizing properly, because the domain wasn't the proper one for that subdomain (ie "www.mydomain.com").