Jump to content

Archived

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

icon

problem with cookies

Recommended Posts

hi


i have this code:

<?

$user="username";
$pass="password";
$database="db";

$username=$_POST['username'];
$password=$_POST['password'];
$first=$_POST['first'];
$last=$_POST['last'];
$occupation=$_POST['occupation'];
$location=$_POST['location'];
$email=$_POST['email'];

$username = $_REQUEST['username'] ;
$password = $_REQUEST['password'] ;


if (empty($username) || empty($password)) {

include "validate_error.php";

} else {

mysql_connect(localhost,$user,$pass);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT id FROM user WHERE username='$username' AND password='$password'";

$result = mysql_query($query) or die ("Query failed at login verifcation.");

$worked = mysql_num_rows($result);


If ($worked == "") {
include "error_username.html";

} else {

setcookie("cookie", $username, ".domain.net", 0);

header('Location: [a href=\"http://www.domain.net/web/00,,111.111.html');\" target=\"_blank\"]http://www.domain.net/web/00,,111.111.html');[/a]

}

}
?>

but it say Warning: setcookie() expects parameter 3 to be long

why is this happening

thanks

Share this post


Link to post
Share on other sites
Here's the function declaration for setcookie():
[code]
bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )
[/code]


Setcookie() expects an integer for the third parameter, but I think you called it using a string value as the third parameter.

Share this post


Link to post
Share on other sites
[!--quoteo(post=364570:date=Apr 13 2006, 03:55 PM:name=hadoob024)--][div class=\'quotetop\']QUOTE(hadoob024 @ Apr 13 2006, 03:55 PM) [snapback]364570[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Here's the function declaration for setcookie():
[code]
bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )
[/code]
Setcookie() expects an integer for the third parameter, but I think you called it using a string value as the third parameter.
[/quote]

thanks it ok now but now it aint setting the cookie

this is what i enter to solve the other problem

setcookie("cookie", $username, time(), "/", ".domain.net", 0);

but i looked in the cookie folder of the broswer and there aint a cookie there for my domain but if i run the test.php with this bit of code it sets the cookie

------test.php----------
<?
setcookie("time_visited", date('m/D/Y'), time()+14400, "/", ".domain.net", 0);
?>

any ideas

thanks :@

Share this post


Link to post
Share on other sites
[!--quoteo(post=364599:date=Apr 13 2006, 05:16 PM:name=paulley12)--][div class=\'quotetop\']QUOTE(paulley12 @ Apr 13 2006, 05:16 PM) [snapback]364599[/snapback][/div][div class=\'quotemain\'][!--quotec--]
setcookie("cookie", $username, time(), "/", ".domain.net", 0);

but i looked in the cookie folder of the broswer and there aint a cookie there for my domain but if i run the test.php with this bit of code it sets the cookie

------test.php----------
<?
setcookie("time_visited", date('m/D/Y'), time()+14400, "/", ".domain.net", 0);
?>

any ideas

thanks :@
[/quote]

you are setting the expiration to the current time. your browser will delete it the moment it's set. try adding the +14400 after time() -- that should work.

Share this post


Link to post
Share on other sites
[!--quoteo(post=364603:date=Apr 13 2006, 05:22 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Apr 13 2006, 05:22 PM) [snapback]364603[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you are setting the expiration to the current time. your browser will delete it the moment it's set. try adding the +14400 after time() -- that should work.
[/quote]

thanks , but what i want to do is have the cookie deleted when the browser closes

thanks for all ya help

Share this post


Link to post
Share on other sites
[!--quoteo(post=364606:date=Apr 13 2006, 05:27 PM:name=paulley12)--][div class=\'quotetop\']QUOTE(paulley12 @ Apr 13 2006, 05:27 PM) [snapback]364606[/snapback][/div][div class=\'quotemain\'][!--quotec--]
thanks , but what i want to do is have the cookie deleted when the browser closes

thanks for all ya help
[/quote]

I can't remember exactly, so you'll have to experiment. I think it's two double quotes with nothing in the middle. If that doesn't work, try the word NULL -- but I don't think NULL works.

so:

setcookie("time_visited", date('m/D/Y'), "", "/", ".domain.net", 0);

or (not likely)

setcookie("time_visited", date('m/D/Y'), NULL, "/", ".domain.net", 0);

Share this post


Link to post
Share on other sites
[!--quoteo(post=364611:date=Apr 13 2006, 05:35 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Apr 13 2006, 05:35 PM) [snapback]364611[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I can't remember exactly, so you'll have to experiment. I think it's two double quotes with nothing in the middle. If that doesn't work, try the word NULL -- but I don't think NULL works.

so:

setcookie("time_visited", date('m/D/Y'), "", "/", ".domain.net", 0);

or (not likely)

setcookie("time_visited", date('m/D/Y'), NULL, "/", ".domain.net", 0);
[/quote]

now it come up with the other problem

Warning: setcookie() expects parameter 3 to be long :@

Share this post


Link to post
Share on other sites
[!--quoteo(post=364615:date=Apr 13 2006, 05:43 PM:name=paulley12)--][div class=\'quotetop\']QUOTE(paulley12 @ Apr 13 2006, 05:43 PM) [snapback]364615[/snapback][/div][div class=\'quotemain\'][!--quotec--]
now it come up with the other problem

Warning: setcookie() expects parameter 3 to be long :@
[/quote]

Just tested with NULL and it works... NULL is a value, so don't enclose it in quotes or anything. Just like this:

setcookie("time_visited", date('m/D/Y'), NULL, "/", ".domain.net", 0);

if it still gives you trouble, everything after name is optional. Worst case scenario, just put the name and the value -- leave the rest off.

setcookie("time_visited", date('m/D/Y'));

Share this post


Link to post
Share on other sites
could there be a problem with the if/else logic? could it just not be getting to that part of the code, which is why no cookie is being set? does the header redirection work?

so it seems that if you just run the test script, where the only command is the setcookie() command, it works, right? i wonder if that header right after the setcookie() command is causing the cookie not to be set. just to test it, i'd try commenting out the header() and putting an exit() in there. if the cookie gets set, then you know what the problem is.

Share this post


Link to post
Share on other sites
[!--quoteo(post=364619:date=Apr 13 2006, 05:56 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Apr 13 2006, 05:56 PM) [snapback]364619[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Just tested with NULL and it works... NULL is a value, so don't enclose it in quotes or anything. Just like this:

setcookie("time_visited", date('m/D/Y'), NULL, "/", ".domain.net", 0);

if it still gives you trouble, everything after name is optional. Worst case scenario, just put the name and the value -- leave the rest off.

setcookie("time_visited", date('m/D/Y'));
[/quote]


thanks mate it work great now, oh just one more thing how would i dispaly the username which i have logged in has

cheers

Share this post


Link to post
Share on other sites

×

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.