Here is the code I am working with. I have been trying to get this to work for the last few days, sorry I am new to php. What I am trying to do is have it remember the user that logs in and auto login once the cookie has been set the next time they revisit. The problem that I am having is that it will remember the username and password but won't auto login just fills in the username and password for them. Could someone please help.
<?php
header("Expires: Tue, 01 Jan 1985 07:15:30 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$acheck=1;
$member=1;
$config = "includes/config_inc.php";
$emlibs = "includes/mail_lib.php";
require($config);
require($emlibs);
$ip = $REMOTE_ADDR;
$timestamp = time();
$affun = trim($affun);
$affpw = trim($affpw);
$rememberme = $HTTP_COOKIE_VARS['RememberMe'];
$affuid = $HTTP_COOKIE_VARS['AFFUID'];
$affpwd = $HTTP_COOKIE_VARS['AFFPWD'];
$remember=($remember);
$forget=($forget);
if(!$rememberme)
{
$remember_cookie="1";
}
if ($action == "Login")
{
$mcheck = "/templates/affiliate_signup.tpl";
$fp=fopen($prog_path.$mcheck,"r");
$validate=fread($fp,filesize($prog_path.$mcheck));
fclose($fp);
if (!stristr($validate, "$spchara"))
{
$license=1;
}
if (!stristr($validate, "$spcharb"))
{
$license=1;
}
if (!$license)
{
$mysqlaff = mysql_query("select * from $mysqltable_aff where aff_name='$affun' and aff_pass='$affpw'");
if ($rowaff = mysql_fetch_array($mysqlaff))
{
$dbid = $rowaff["aff_id"];
$dbuser = $rowaff["aff_name"];
$dbpass = $rowaff["aff_pass"];
$lastlogin = $rowaff["this_login"];
}
$attempt=1;
if ($affun != "" && $affun == "$dbuser" && $affpw == "$dbpass")
{
$affid = $HTTP_SESSION_VARS['affid']=$dbid;
$auser = $HTTP_SESSION_VARS['auser']=$affun;
$alogin = $HTTP_SESSION_VARS['alogin']=1;
$update = mysql_query("update $mysqltable_aff set this_login = '$timestamp', last_login = '$lastlogin', remote_ip = '$ip' where aff_id = '$affid'");
if ($remember==on && $alogin)
{
@setcookie("RememberMe",1,time()+15552000,"/","",0);
@setcookie("AFFUID",$dbuser,time()+15552000,"/","",0);
@setcookie("AFFPWD",$dbpass,time()+15552000,"/","",0);
}
elseif ($forget==on && $alogin)
{
@setcookie("RememberMe","",time()+1,"/","",0);
@setcookie("AFFUID","",time()+1,"/","",0);
@setcookie("AFFPWD","",time()+1,"/","",0);
}
if (!$session_php && $alogin)
{
header ("Location:index.php");
}
elseif ($session_php && $alogin)
{
header ("Location:index.php?".sid);
}}}}
if ($action == "Logout")
{
session_unset();
session_destroy();
$logout=1;
}
if ($license)
{
echo "<b>Please email <a href=\"mailto:$admin_email;?subject=Error: #437\">$admin_email</a> quoting error number #437.</b>";
}
else
{
include "templates/affiliate_login.tpl";
}
?>
Thank you in advance. I am trying to learn this the best I can.