Jump to content

PHP Cookies - getting frustrated


fohanlon

Recommended Posts

Hi Guys

I am spending hours on php cookies and looking at the code in IE and FF.

But neither broswer is setting the cookies.  I have seen the setcookie on php manuals and tried all the various suggested functions.  I have looked at the various ways to setcookie.  I am using the warning in firefox to test that a cookie has been set. 

Sometimes I get the cookie set but I need them to be set each time the website is visited.

Register globals is on for the ISP (I checked this).

Here is an example of what I was using:

setcookie("ifxun", $_POST['username'], time()+3600, "/", "mydomain.com");

Any useful comments/experences would be vey much appreciated or code I could try.  I am at a loss and have read the same comments over and over again on the web forums but the suggestions do not work.

Many Thanks,

Fergal.
Link to comment
Share on other sites

Hi Guys,

Thanks for the responses.  Still no luck.  Here's the scenario, I have a members login page with a username and password form, this is passed to a login check page code as below:

<?php
require('config.php');

$username = $_POST['username'];
$password = $_POST['password'];
$user_exists = mysql_query("SELECT * FROM members WHERE username = BINARY '$username' AND user_password = BINARY '$password'");
$num_users = mysql_num_rows($user_exists);

if($num_users == 0)
{
    include 'index.php';
    exit();  // exit the script
}
else
{
setcookie("ifxun", $_POST['username'], time()+3600, "/");
setcookie("ifxpw", $_POST['password'], time()+3600, "/");
header("location: test.php");
}

?>

I am using Mozilla FF warning procedure - that cookies are being set.  the above code does not call the FF warning and cookie are not being set.

Can you help me out further.

many thanks,

Fergal.
Link to comment
Share on other sites

change it to..

[code]
<?php
ob_start();
require('config.php');

$username = $_POST['username'];
$password = $_POST['password'];
$user_exists = mysql_query("SELECT * FROM members WHERE username = BINARY '$username' AND user_password = BINARY '$password'");
$num_users = mysql_num_rows($user_exists);

if($num_users == 0)
{
    include 'index.php';
    exit();              // exit the script
}
else
{
  setcookie("ifxun", $_POST['username'], time()+3600, "/");
  setcookie("ifxpw", $_POST['password'], time()+3600, "/");
  header("location: test.php");
}
ob_flush();
?>
[/code]
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.