我在注册后自动登录到我的帐户页面有问题。请帮忙,这是我的代码。我正在尝试登录用户,没有任何电子邮件确认。
<?php
@ob_start();session_start();
if($_SESSION['LOGIN_ID'] > 0)
header("location:myaccount.php");
$invalidcaptcha = 0;
if($_POST['register_submit'])
{
$ip = getIP();
$emailid = $_POST['emailid'];
$pwd = $_POST['pwd'];
$confirm = '1';
$blocked = '0';
$ccode = base64_encode($email);
$ures = mysql_query("select id from user where emailid='".mysql_real_escape_string($_POST['emailid'])."'");
if(mysql_num_rows($ures) > 0 )
{
header("location:login.php?emailexist=1");
}
else if($_POST['security_code']==$_SESSION['freecap_word_hash'])
{
mysql_query("insert into user set emailid='".mysql_real_escape_string($emailid)."',pwd='".md5($pwd)."',blocked='".$blocked."',confirm='".$confirm."',ccode='".$ccode."',reg_date=now(),reg_ip='".$ip."'");
$i_id = mysql_insert_id();
$res=mysql_query("SELECT id, emailid, pwd FROM users WHERE emailid='$emailid'");
$row=mysql_fetch_array($res);
$count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row
$_SESSION['LOGIN_ID'] = $row['userId'];
header("Location: myaccount.php");
}
}
?>
您这里使用的是userid
$_SESSION['LOGIN_ID'] = $row['userId'];
And not using userId column in SELECT QUERY.
除了这个问题,$i_id等于$row["userId"]就不需要使用第二个SELECT QUERY。
在您的例子中,您只需要在这个查询中添加userId列:
SELECT id, emailid, pwd, userId FROM
但是这个查询是额外的,正如我提到的。
这是另一个特别的地方,停止使用mysql_*,它在PHP 7中已经被废弃和关闭,你可以使用mysqli_*或PDO。
最好使用预处理语句,这将节省您的代码与SQL注入。