Jump to content

Archived

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

brob

setcookie problem

Recommended Posts

hi here is my code

[code]import_request_variables("gP","");

$md5pass = md5($password);

include('db_stu_connect.php');

$getusername = mysql_query("select email1,passw_c from contacts_cstm,contacts where contacts.id = contacts_cstm.id_c and email1 = '$username' and contacts_cstm.passw_c = '$md5pass'");
$gotusername = mysql_fetch_row($getusername);

if ($gotusername[0] != "")
{
$username = $gotusername[0];

setcookie ("dbghstudent", "$username",0,"/");

?>
<script language="JavaScript">
parent.location='http://www.site.net/other_pages/test.php';
</script>
<?php
}
else
{[/code]

and for some reason it isn't setting the cookie can anyone see a reason for this?

Thanks

Share this post


Link to post
Share on other sites
0 as a timestamp is equil to January 1 1970 00:00:00 GMT

So setting a cookie that expired isnt going to have the result you want ;)

http://php.net/manual/en/function.time.php

Share this post


Link to post
Share on other sites
hi thanks for the reply,

It still doesn't seem to work even though I have set the time for an hour ahead i.e.

[code]setcookie ("dbghstudent", "$username",time()+36000,"/");[/code]

any ideas why this is?

For some reason its just not setting the cookie.

Share this post


Link to post
Share on other sites
are cookies enabled in your browser?

is the value of $username false?

Share this post


Link to post
Share on other sites
hi this is the code in full

[code]
<?php
import_request_variables("gP","");

$md5pass = md5($password);

include('db_stu_connect.php');

$getusername = mysql_query("select email1,passw_c from contacts_cstm,contacts where contacts.id = contacts_cstm.id_c and email1 = '$username' and contacts_cstm.passw_c = '$md5pass'");
$gotusername = mysql_fetch_row($getusername);

if ($gotusername[0] != "")
{
$username = $gotusername[0];

setcookie ("dbghstudent", "$username",time()+36000,"/");

?>
<script language="JavaScript">
parent.location='http://www.site.net/other_pages/test.php';
</script>
<?php
}
else
{
?>
sorry invalid login
<?
if ($gotusername[0] == "")
{
echo '<p><font color="#FF0000">Invalid username and/or password. Please try again.</font></p>';
}

?>
[/code]

I have used this system on another site and it worked but for this site it seems to fail

Share this post


Link to post
Share on other sites
Problem can be, if this code isnt in HEADER>...
Setting COOKIE has to be done BEFORE ANY HTML CODE..

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.