Jump to content

Cookie Problems


Lexar

Recommended Posts

Howdy, I'm having some issues using cookies. I've identified the problematic line being in my login.php file, which is the action="POST" of my login form.

[code]
<?php
if(empty($_POST['name']) || empty($_POST['pass']))
{  ?>
    <b>Fill All Details </b>
              <?php exit;
}
else
{
    //Colllect the details and validate
    $time = time();
    $name = $_POST['name'];
    $pass =md5($_POST['pass']);
    $check = 'ON';
   
$db = mysql_connect("-----", "-----","-----") or die(mysql_error());
    mysql_select_db("-----",$db) or die(mysql_error());
    $query = "select * from Customer where Username='$name' and Password='$pass'"; 
    $sql = mysql_query($query) or die(mysql_error());
    $count = mysql_num_rows($sql);
   
    if ($count == 1)
    {
        $cookie_data = $name.'-'.$pass.'-'.$access; 
        if($check=='ON')
        {

            if(setcookie ("cookie_info",$cookie_data, $time+3600)==TRUE)
            {
    ?> if check is on <?PHP
                echo "Cookie SET".$cookie_data; ?>
                <a href='logout.php'>Logout</a>
               
            <? }
        }
    }
    else
    {
        echo "Authentication Failed";
        exit;
    }//
   
}
?> [/code]


That's the entire file. I've found that the "if check is on" line will display if it's before the following if statment, but not inside of it.

[code]if(setcookie ("cookie_info",$cookie_data, $time+3600)==TRUE)
[/code]
Link to comment
Share on other sites

[quote author=Lexar link=topic=116919.msg476755#msg476755 date=1164948673]
Looks like you're right. Know of any way to fix this?

I put an additional if at the top with no arguements, which failed. What do you suggest?
[/quote]
You can always throw in ob_start() at the top of your script.  It caches everything until you're ready to print out the data (or the file is finished running) so that you can edit headers at any point in your script.
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.