PDA

View Full Version : Setting cookies problems?


FethrdWlf
05-06-2011, 03:03 AM
I'm trying to make a cookie be set for one someone logs into my website. I know that this method isn't the safest, but it's just to make progress on the project. I plan on "securitizing" it all later.

Anyways, I've done a test before with cookies where as soon as you load the page, one is set named "test". Then, I had a separate page that would check to see if it existed. That worked.

Now, I have it set up so that when a user enters in his/her username and password, and hits enter, it loads this script:

<?php
include("mysql.php");

$entereduser = $_POST['user'];
$pass = $_POST['pass'];

session_start();

$query = "SELECT * FROM users WHERE username='$entereduser' AND password='$pass'";
$results = mysqli_query($cxn,$query);
$logrow = mysqli_num_rows($results);
$inforow = mysqli_fetch_array($results);
$oneyear = time()+(86400*365);
if($logrow == 1){
setcookie("loggedin","true",$oneyear);
}else{
echo "<link rel='stylesheet' href='../css/login.css' />\n";
echo "<span style='font-family:Arial, Helvetica, sans-serif; text-align:center;'>No such username and password combo exists. <a href='http://fethrdwlf.zxq.net'>Go Back</a></span>\n";
}
?>
...
That doesn't exactly work for me. On my index/home page, there is a small script in the body of it that should check whether or not the cookie exists:
<?php
if(isset($_COOKIE['loggedin'])){
echo "Yes.";
}else{
echo "No.";
}
?>
...
What am I doing wrong?