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
    Feb 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie problems

    Code:
    <?php
    
    include "dbinfo.inc.php";
    
    
    // Find out the username and password stored in the db
    $sql = "SELECT `username`, `password`, `user_id` FROM `users` WHERE `username` = '$UnFromForm'";
    $result = mysql_query( $sql );
    
    while ($row = mysql_fetch_array( $result )) {
        $UnInDb = $row['username']; //UserName in the Database
        $PwInDb = $row['password']; //Password in the Database
    	$userid = $row['user_id'];
    }
    
    
    // Find out if this page is checking UN/PW or asking for UN/PW
    if (isset( $_POST['submit'] )) { // If it is checking UN/PW
        // See if the username entered on the form matches the one in the db
        if( ($PwFromForm==$PwInDb) && ($UnFromForm == $UnInDb)) {
            // Success
               setcookie( 'loggedon', 'true', time()+60*60*24*30, '/', '**.**.**.**', 0 );
    	   setcookie( 'username', $UnInDb, time()+60*60*24*30, '/', '**.**.**.**', 0 );
    	   setcookie( 'userid', $userid, time()+60*60*24*30, '/', '**.**.**.**', 0 );
               begining();
        }
    
        else {
            // Failure
            ?>
            Incorrect, Click <a href="logintest2.php">Here</a> To try again
            <?
        }
    }
    if (!isset( $_POST['submit'])) { // If there has not been a un/pw entered
        // Check to see if the cookie is already there:
        if(isset($_COOKIE['loggedon'])) {
          begining();
        }
    
        else {
        // Ask them for it
        
        ?>
        <TABLE>
        <FORM action="logintest2.php" method="POST">
            <TR>
                <TD>Username:</TD>
                <TD><INPUT name="UnFromForm" type="TEXT" /></TD>
            </TR>
            <TR>
                <TD>Password:</TD>
                <TD><INPUT name="PwFromForm" type="PASSWORD" /></TD>
            </TR>
            <TR>
                <TD><INPUT name="submit" type="submit" value="Log-On" /></TD>
            </TR>
        </FORM>
        </TABLE>
        <?
        }
    }
    function begining() {
        ?>
    	
    
    <a href="logout2.php">Click here to log out</a><br>
    <a href="space4.php">Click here to go to space</a><br>
    <a href="notes.php">Post or Read notes</a>
            
        <?
    }
    
    
    ?>


    For some reason the cookies arent being set and for the life of me i cant figure out why

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Did you read about the common pitfalls?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yea ive read the whole thing but still cant figure out why its not setting the cookies


  •  

    Posting Permissions

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