Hi am trying to make an auto login form. Once person signs up, he no longer needs to login and is automatically directed to his profile page thanks to a cookie storing his values.
I have been working with two files. 1) Index and 2) Registration However even after a successful registration, when I refresh the "index page", I still get redirected to the "Registration Page" meaning neither the Cookie nor variable Im trying to pass onto another window aren't working. What might I be missing ? Thanks
index.php
Registration.phpPHP Code:<?php
$cookie_name = $_POST['$name'];
$cookie_value = $_POST['$email'];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
if(!isset($_COOKIE[$cookie_name])) {
// echo "Cookie named '" . $cookie_name . "' is not set!";
header('Location: registration.php');
} else {
header('Location: http://www.cnn.com');
}
?>
ThanksPHP Code:<?php
$name="";
$email="";
$msg_to_user="";
//$numsRows="";
//$sql="";
if ($_POST['name']!=""){
include_once "connect_to_mysql.php";
$name= $_POST['name'];
$email= $_POST['email'];
$sql = mysql_query("SELECT*FROM users WHERE email ='$email'");
$numRows = mysql_num_rows($sql);
//echo $numRows;
if(!$email) {
$msg_to_user='Please input a Valid Email Address';
}else if ($numRows > 0){
$msg_to_user='<br/></br><h4><font color= "FF0000"> Email is already in the system </font></h4>';
} else {
$sql_insert = mysql_query("INSERT INTO users (name,email) VALUES('$name','$email')") or die (mysql_error());
$msg_to_user='<br/></br><h4><font color= "FF0000">Thanks you have been added successfully</font></h4>';
$cookie_name = $_POST['$name'];
$cookie_value = $_POST['$email'];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
//$name="";
//$email="";
}
}
?>





Reply With Quote
