Jump to content

Cookies


neex1233

Recommended Posts

<?php 
/* $con make a connection with database */
$con=mysql_connect("localhost","root",""); 

//select  database
mysql_select_db("users"); 

/* Below two commands will store the data in variables came from form input */
$username=$_POST['user'];
$password=$_POST['pass'];

/* below two commands are sql injection which stops extra characters as input */
$user=mysql_real_escape_string($username);
$pass=mysql_real_escape_string($password);

$query=mysql_query("SELECT * FROM users where
user='$user' AND 
pass='$pass' "); 

$count=mysql_num_rows($query);
if($count==1) 
/* $count checks if username and password are in same row */
{ 
echo "Login Successful";
$hour = 86400*365;  
/* $hour sets cookie storage time for 1 hour */

/* setcookie() function sets cookie after login */
ob_start();
ob_clean();
setcookie("username", $_POST['user']); 
setcookie("password", $_POST['pass']);

header("location:/"); 
/* header() funtion redirect user to members page */
}
else
{ 
echo "Username or password is incorrect";
}
?>

 

 

And

 

<?php
ob_start();
ob_clean();
$user = $_COOKIE['username'];
if(isset($user))
{

}
else 
{
header("location: /users/login.php");
}
?>

 

I know the cookies exist, because I looked in Add 'n Edit Cookies.

Link to comment
https://forums.phpfreaks.com/topic/222106-cookies/#findComment-1149127
Share on other sites

It's not the actual making of the cookie that's the problem, it's the detection of the cookie. The cookie is made fine, I've checked in Add 'n Edit Cookies, but this code:

<?php
ob_start();
ob_clean();
$user = $_COOKIE['username'];
if(isset($user))
{

}
else 
{
header("location: /users/login.php");
}
?>

isn't working. The code works on other pages, though.

Link to comment
https://forums.phpfreaks.com/topic/222106-cookies/#findComment-1149130
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.