Jump to content

Cookie Question Again!


Zepo.

Recommended Posts

function login($mes){
global $config;

if (isset($_COOKIE["user"])){
$out[body].="<br />
<center>
<table width='90%' border='0' cellspacing='1' cellpadding='1' bgcolor='#00000'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong>Login</strong>
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='100%' valign='center' align='left'><center>
<b>You are already logged in!</center></td></tr>
</table>
</center><br /><br /><br /><br />";

}else{

$out[body].="
<br />
<center>
<table width='400' border='0' cellspacing='1' bgcolor='#000000' cellpadding='1'>
<form method='post'>
<tr bgcolor='$config[altcolor]'>
<td background='$config[bg]' width='100%' valign='center' align='left' colspan='2'>
<strong>Login</strong>";
if(isset($mes)){
$out[body].="<font color='red'>(Incorrect Login)</red>";
}
$out[body].="
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'>Username</td>
<td width='60%' valign='center' align='center'><input type='text' name='login[name]' class='input' value='$login[name]' size='32' maxlength='15'></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'>Password</td>
<td width='60%' valign='center' align='center'><input type='password' class='input' name='login[pass]' value='' size='32' maxlength='15'></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'>Login Length</td>
<td width='60%' valign='center' align='center'>  <select class='button' name='login[clength]'>
<option value='60'>1 Hour</option>
<option value='1440'>1 Day</option>
<option value='10080'>1 Week</option>
<option value='43200'>1 Month</option>
<option value='-1' selected='selected'>Forever</option>
</select></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td><a href='./register.php'>Register Now!</a></td>
<td width='100%' valign='top' align='right'>
<input type='hidden' name='act' value='setlogin'>
<input type='submit' class='button' name='submit' value='Login >>'></td>
</form>
</tr>
</table>
<br /><br />
<table width='400' border='0' cellspacing='1' cellpadding='2' bgcolor='#000000'>
<form method='post' action='./forgotpw.php'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong>Forgot Password?</strong>
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'>Username</td>
<td width='60%' valign='center' align='center'><input type='text' name='login[name]' class='input' value='' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'><img src='./includes/captcha.php' /></td>
<td width='60%' valign='center' align='center'>Enter the text you see in the image.<br />
<input class='input' type='text' name='login[capt]' value='' size='40' maxlength='13'></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='100%' valign='top' align='right' colspan='2'>
<input type='submit' class='button' name='submit' value='Resend >>'></td>
</form>
</tr>
</table>
</center><br /><br />";
}

include("$config[html]");
}


function set($login){
global $config;

if(!mysql_num_rows(mysql_query("SELECT id FROM members WHERE name='$login[name]' AND password='$login[pass]'"))){
$mes="1";
login($mes);
exit;
}

$getid=mysql_query("SELECT id,act FROM members WHERE name='$login[name]'");
$getid=mysql_fetch_array($getid);

if($getid[act] == 0){
error("Your account is not activated yet, you must click the link provided in your welcome email.");
}

//Set Cookies
setcookie(tid,$getid[id],$login[clength]);
setcookie(user,$login[name],$login[clength]);
setcookie(pass,$login[pass],$login[clength]);
}

 

Full code, the login lengths arn't working....

Link to comment
Share on other sites

setcookie(tid,$getid[id],$login[clength]);

setcookie(user,$login[name],$login[clength]);

setcookie(pass,$login[pass],$login[clength]);

 

Try print_r($login) right above that, and see if it says clength is set.

 

It's also worth noting, it's a bad practice to not use quotes there, since PHP treats plain text as constants.  If a constant for that plain text isn't set, then it will treat it like it was wrapped in quotes, but I've seen a few problems caused by that before.

Link to comment
Share on other sites

I think if you would read the definition of the expire parameter, it would help - http://php.net/setcookie

 

The current time on the server + the amount you add to the current time is what the examples in the manual and the later code in your other thread on this problem is sending to the browser in the cookie. However, the current time in the browser is what determines when the cookie is deleted. If the browser is in a later time zone than the server, the expire time that you are using in the cookie could already be past and the cookie would be deleted as soon as the browser closes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.