(RESOLVED) Setting Cookies (Pt. 2)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

(RESOLVED) Setting Cookies (Pt. 2)

Post 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');
	}
Last edited by LuiePL on Thu Aug 31, 2006 7:45 pm, edited 1 time in total.
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post by LuiePL »

Anyone?
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What does the iframe have to do with the cookie?
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post 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").
Post Reply