Jump to content

problem with cookies


icon

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
Link to comment
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.
Link to comment
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 :@
Link to comment
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.
Link to comment
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
Link to comment
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);
Link to comment
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 :@
Link to comment
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'));
Link to comment
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.
Link to comment
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
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.