<?php
$utype = $_POST['type'];
$username=$_POST['username'];
$pre = $_POST['pre'];
$fname = $_POST['fname'];
$fname = ucwords($fname);
$lname = $_POST['lname'];
$lname = ucwords($lname);
$address = $_POST['address'];
$city = $_POST['city'];
$city = ucwords($city);
$province=$_POST['province'];
$pcode = $_POST['pcode'];
$pcode = mb_strtoupper($pcode);
$area_code = $_POST['area_code'];
$number1= $_POST['number1'];
$number2= $_POST['number2'];
$phnum = "(".$area_code.")".$number1."-".$number2;
$email = $_POST['nemail'];
$opass=$_POST['pass1'];
$pass = md5($_POST['pass1']);
$time=date("F j, Y");
$status="Not Activated";
if($email=="" || $username=="" || $fname=="" || $lname=="" || $address=="" or $pass==""){ die("<script language='JavaScript'>
window.alert('Not Enough Data Provided!')</script>
<meta http-equiv='REFRESH' content='0; r egister.php'>");;
}
include 'db_connect.php';
$sql = "select * from estatedeal_login where username = '".strtolower($username)."' OR email = '".strtolower($email)."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
if($row){
die("<script language='JavaScript'>
window.alert('Username/E-mail address already Exists!')</script>
<meta http-equiv='REFRESH' content='0; register.php'>");;
}
$sql="INSERT INTO estatedeal_login (username, email, password, utype, opass, time, status)
VALUES ('$username', '$email', '$pass', '$utype', '$opass', '$time', '$status')";
$result=mysql_query($sql);
if($result){
$sql2="Select uid from estatedeal_login where email='$email' AND password='$pass'";
$result2=mysql_query($sql2);
$row=mysql_fetch_array($result2);
$uid=$row["uid"];
$sql3="INSERT INTO estate_userinfo(uid, pre, fname, lname, address, city, province, pcode, phnum, email) VALUES ('$uid', '$pre', '$fname', '$lname', '$address', '$city', '$province', '$pcode', '$phnum', '$email')";
$result3=mysql_query($sql3) or die("<script language='JavaScript'>
window.alert('Sorry, Database Error!')</script>
<meta http-equiv='REFRESH' content='0; register.php'>");;
if ($result3){
$hour = time() + 3600*2;
setcookie('USERNAME_COOKIE', $email, $hour);
setcookie('PASSWORD_COOKIE', $pass, $hour);
if($utype=="Realtor"){ die("<meta http-equiv='REFRESH' content='0; regRealtor.php'>");; }
echo "<script language='JavaScript'>
window.location ='main.php';</script>";
}
}
else{
die(mysql_error());
}
?>
以上是我的代码。它在 mysql 中正确插入数据字段,但不在客户端设置 cookie。如果我尝试使用我在数据库中插入的信息登录,则用于设置 cookie 的相同代码在登录页面上可以正常工作。还有更多设置cookie的选项吗?
$hour = time() + 3600*2;
setcookie('USERNAME_COOKIE', $email, $hour);
setcookie('PASSWORD_COOKIE', $pass, $hour);