Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Cookie Problems

  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie Problems

    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;
        }//
        
    }
    ?>

    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)

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I don't understand the problem you are having, can you be more clear?
    Sounds like this:
    PHP Code:
                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>
                    
                <? }
    is never evaluated to true, is that correct?
    As well, unless you have output buffering enabled in your php.ini, this code will never set a cookie correctly. This is because you have previous output to the browser, which you will need to capture either in a variable or by using output buffering in order to set the actual cookie.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Correct. The if statment is never evaluated to be true, and if I add an else statment to it, it will always run through the else. I've tried removing the output to the screen from above and still have the same issues.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •