Page 1 of 1

Cookie question

Posted: Mon Dec 01, 2003 10:21 am
by Ahms
Quick question. Just moved to a new host, this script worked on my old server but now it's not:

Code: Select all

<?php

mysql_connect('*****', '*****, '*****');
mysql_select_db('*****');

$username = $_POST&#1111;'login'];
$password = $_POST&#1111;'password'];

$query = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'");

if (mysql_num_rows($query) > 0) &#123;
	setcookie ('guildname', $username, "31104000", "/");
	include 'welcome.php';
&#125;
else &#123;
	include 'failed.php';
&#125;

mysql_close();
?>

Basically what's happening is that the cookie isn't setting. It worked fine on my old server but not now, am I doing something wrong? The Apache and PHP versions are the same, the only difference is that this new host uses mySQL 4x while the old one used 3x, I don't know if that makes a difference or not. Please let me know if I'm too vague and you need more information, thanks!

Posted: Mon Dec 01, 2003 1:11 pm
by xisle
have you tried adding the domain to your cookie?

Code: Select all

$domain=explode(".", $HTTP_HOST);     		
$domain&#1111;0]="";     		
$domain=implode(".", $domain);
					  
// set 365 day expiration..86400 per day				
$die = $now +31536000;	

 if(!$c=setcookie("guildname", $username, $die, "/", "$domain")) &#123;    
    print"whatever";
    exit;
 &#125;

Posted: Mon Dec 01, 2003 9:20 pm
by Ahms
Set the domain but nothing happened. I check temp files and find that no cookie at all is setting :(

Posted: Mon Dec 01, 2003 9:45 pm
by m3mn0n
Not sure about the cookies, but you should encrypt the passwords in the database. :wink:

Posted: Mon Dec 01, 2003 9:57 pm
by Ahms
Will do lol

I got it to work btw! I just changed it to this:

Code: Select all

setcookie ("guildname", $username, time()+3600, "/");
I'm glad it works now but WHY is it working now?

Posted: Mon Dec 01, 2003 10:01 pm
by m3mn0n
Thats the proper syntax as described here: [php_man]setcookie[/php_man]

Why did it set time to a static value before?

Posted: Mon Dec 01, 2003 10:08 pm
by Ahms
I had it like this before on my old server:

Code: Select all

setcookie ('guildname', $username, "31104000", "/");
There it actually worked fine. But I did move to a new server, is just really picky or something?

Posted: Mon Dec 01, 2003 10:22 pm
by m3mn0n
Most likely a newer server. Or just a differently configured server. That's why it's best to code keeping in mind that it should work on all platforms and with all (or atleast most) setting types.