Jump to content

cookies arent setting properly


PC Nerd

Recommended Posts

um, im setting 3 cookies but theyre all storing the current timestamp, and theres some other cookie that i used to use, but no longer do, its still there

 

this is my code

 

 

 

 



$User_Name = $_POST['User_Name'];
$User_ID = $Login['User_ID'];
$Login_ID = $Login['Login_ID'];
#$Logged_In = "YES";
#$Active = "Yes";

setcookie("User_Name", $User_Name, strtotime('+ 30 minutes'));
setcookie("Login_ID", $Login_ID, strtotime('+ 30 minutes'));
setcookie("User_ID", $User_ID, strtotime('+ 30 minutes'));

 

 

thats the contents of the create cookies inc

 

 

 

this is the login file

 

 

 


<?php

$now = date("U");
#echo $now;



$Login_SQL = "INSERT INTO Login_Records (User_ID, Logged_In)
				VALUES ('".$DB_Login['User_ID']."', '".$now."')";
$Login_Query = mysqli_query($DB_Server, $Login_SQL);
#	or die("Could not Login.  Please try again later");

unset($Login_SQL, $Login_Query);

$Login_SQL = "SELECT User_ID, Login_ID FROM Login_Records WHERE User_ID ='".$DB_Login['User_ID']."' AND Logged_In = '".$now."'";
$Login_Query = mysqli_query($DB_Server, $Login_SQL)
or die("Could not login. Please try again later");
$Login = mysqli_fetch_array($Login_Query);



?>

 

 

 

can anyone see whats happening

 

 

 

this is the output when i echo the contents of the cookies ( through a foreach )

 

 

 

 

User_Name => 1176012801

Logged_In => 1176012801

Login_ID => 1176012801

User_ID => 1176012801

 

 

 

thankx

 

 

 

Link to comment
Share on other sites

always remember:

you cannot set cookies and echo them in the same page load

 

you must refresh to use the data in the cookies

 

this means that you must not set the cookies everytime the page loads, you must make an if/else statement to ONLY set the cookie if it isn't already set

 

if(!isset($_COOKIE['whatever'])) {

//set the cookie

} else {

echo $_COOKIE['whatever'];

}

Link to comment
Share on other sites

ok, the output is in B_A-Base.php, yet another page.

 

all of these files are included in the Login4.php file

 

ill post the code below ( thats where $DB_Login comes in)

 

 

 

 


<?php

$username = $_POST['User_Name'];
$password = $_POST['Password'];
$valid = $_POST['Valid'];

#echo "Username: {$username}<br>Password: {$password}<br>Valid: {$valid}<br><br>"; //echo out the values to see if they are being sent.

$Error = "";
$Error1 = "";
$Error2 = "";
$Error3 = "";
$Error4 = "";

if($username != "" && $password != "" && $valid != "") {
require('inc_files/Login_Pics.inc');
$img = "B_A-Login_".$_POST['IMG_Valid'];

$Image_Validate = $IMAGES["$img"];

if($_POST['Valid'] == $Image_Validate) {
	require("inc_files/Database_link.inc");
	$SQL_Login = "SELECT User_Name, `Password`, User_ID FROM General_Stats WHERE User_Name = '".$_POST['User_Name']."'";
	$Login_Query = mysqli_query($DB_Server, $SQL_Login);

	if(!empty($Login_Query)) {
		$DB_Login = mysqli_fetch_array($Login_Query);

		if($DB_Login['User_Name'] == $_POST['User_Name'] && $DB_Login['Password'] == $_POST['Password']) {
			require("inc_files/B_A-Login.inc");
			header("Location: B_A-Base.php");

		}

		else {
		$Error = True;
		$Error4 = True;
		}
	}
	else {
	$Error = True;
	$Error3 = True;
	}
}
else {
$Error = True;
$Error2 = True;
}
}
else {
$Error = True;
$Error1 = True;
}

?>




HTML FORMATING HERE




<?php


#echo "<form name = 'Login_Relocation' action = 'B_A-Base.php' method = 'POST'>\n";
#echo "<input type = 'button' name = 'relocation' value = 'Play Battle-Ages'>\n";
#echo "</form>";

#echo "<a href = 'B_A-Base.php' alt = 'Base'>Player Battle-Ages</a>\n";

if($Error1 == True) {
die("ERROR 1 You have not filled in the log in fields.  Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");
}

if($Error2 == True) {
die("ERROR 2 You did not type in the correct validation image.  Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");
}

if($Error3 == True) {
die("ERROR 3 There was an error in the Database.  You have not been logged in.  Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");#.mysqli_error($Login_Query));
}

if($Error4 == True) {
die("ERROR 4 There was an error in the Database.  You have not been logged in.  Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");#.mysqli_error($DB_Login));
}

?>



 

 

thats the login file, or Master file that all the other stuff is included in

 

 

 

thankx for your help..........

 

PS i am getting the output from the cookies in the next page, where the login is redirected after its logged in, seting cookies etc.

 

thankyou

Link to comment
Share on other sites

ok, ive re read, and reread all the posts, and i cant seem to fix it

 

im not resetting the cookies each page, nor do i want them to refresh or update at all.  theyrs simply a login thing ,to ttell whether of not some one is logged in.  thats why theyre expire time is 30 minutes, so that someone cant be logged in all the time

 

also.  they store the basic information about the user such as username, id, and the login id.  that way i can send the queries that get the data. becauase the information is update almost every page refresh, and it is open to other user's so it needs to be updated to a database, and not just to the cookie

 

 

is there anything else i should do, or any suggestions i should follow, because i cant create and test much more of the site until this starts working, becauase all the pages check for the cooie and "die()" if there isnt one

 

 

thankx for all your help so far,

 

PC Nerd

Link to comment
Share on other sites

Doesn't matter to me really. I do know the answer and was getting ready to post it until I saw that "WARNING: A user has posted message" and noticed it was you..again. Hopefully someone else can help you bud.

Link to comment
Share on other sites

Ok. so i am going to take a stab in the dark here.

 

A complete stab in the dark, as i allways use sessions rather than cookies.

 

But if i do every use cookies, i use:

 

 setcookie("COOKIENAME", "COOKIEVALUE", time() + 3600);

 

(3600 = 1 hour)

 

Rather than using:

 

setcookie("User_Name", $User_Name, strtotime('+ 30 minutes'));[/code

I dunno, it might help you..

if not then sorry!

Base

Link to comment
Share on other sites

Did you try clearing your cache of all cookies, making sure all of them are gone, then running the script again?  Maybe it is picking up residual cookie...crumbs (lol, pun)

 

Also, if no one is helping, just let it go, or make a new topic, don't keep bumping (7 times in a row) a topic, its rather obnoxious.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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