SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    My problem is that the cookie will not set even with the correct username and password. Below is the code:

    config.php
    Code:
    <?php
    
    /*
    Script is copyright Peter McNulty of CodingClick.com
    This script must not be redistributed. You can edit this
    script for your own personal uses but you cannot
    redistribute or sell it.
    
    Change the below variables to youe servers configuration.
    
    Make sure to create the database before using the install script
    
    */
    
    // Database Host - If you do not know then leave the default
    $dbhost = "localhost";
    
    // Database username
    $dbuser = "user";
    
    // Database password
    $dbpass = "password";
    
    // Database name
    $dbname = "dbname";
    
    // Admin Username
    $adminuser = "admin_username";
    
    // Admin password
    $adminpass = "password";
    
    // Admin Email
    $adminemail = "webmaster@domain.com";
    
    // Admin Name
    $adminname = "Admin Name";
    
    // GuestBook Title
    $progtitle = "Guest Book";
    
    // Web Page URL
    $homepage_url = "http://www.domain.com/";
    
    // Web Page Name
    $homepage_name = "Domain.com";
    
    // Cookie Timeout - Default is two weeks
    $cookie = "1209600";
    
    ################################
    #CONNECT TO DATABASE
    #
    #DO NOT REMOVE THE BELOW UNLESS YOU DO
    #NOT WANT TO CONNECT TO THE DATABASE
    ################################
    
    $connect = mysql_connect($dbhost, $dbuser, $dbpass);
    if(!$connect) {
    print "Sorry, At this time we cannot connect to the database.";
    } else {
    mysql_select_db($dbname);
    }
    
    ?>
    cookie.php
    Code:
    <?php
    /*
    Check if the cookie is set in accordance with the varaible set it the config.php
    file. If the cookie is not set then display the login form. If it is, then continue.
    */
    
    function set_cookie() {
    
    $username_enc = md5($adminpass);
    
    setcookie ("username", $adminuser, time()+$cookie); 
    setcookie ("password", $username_enc, time()+$cookie); 
    
    
    }
    
    
    checkcookie();
    
    if ($loginuser) {
    if ($loginuser == $adminuser && $loginpassword == $adminpass) {
    set_cookie();
    
    
    } else {
    print "Your Password and/or your username is incorrect. Please try again.";
    $cookieset = 0;
    }
    }
    
    
    // Check to see if the cookie has been set and set as function
    function checkcookie() {
    
    if(isset($username)) {
    $got_user = $HTTP_COOKIE_VARS["username"];
    $got_password = $HTTP_COOKIE_VARS["password"];
    
    $adminpass_enc = md5($adminpass);
    $got_password_enc = md5($got_password);
    
    if ($adminpass_enc == $got_password_enc && $adminuser == $got_user) {
    $cookieset = 1;
    
    } else {
    $cookieset = 0;
    }
    } else {
    $cookieset = 0;
    }
    
    }
    
    
    
    // Display the login form
    
    if($cookieset==0) {
    
    ?>
    
    <html><head><title><?php echo $progtitle; ?></title></head>
    <body bgcolor="#FFFFFF">
    <blockquote>
    <p><font color="black" size="4" type="Verdana"><?php echo $progtitle; ?></font></p>
    <p>Cookie Retrieval was unsuccessful, please log in and enable cookies in your browser</p>
    <p><form name="login" action=<?php echo $PHP_SELF; ?> method="post">
    <table width="500" align="left" border="0">
    <tr><td><font type="Verdana" size="2">User Name: </font></td><td>
    <input type="text" name="loginuser" value"">
    </td></tr><tr><td><font type="Verdana" size="2">Password: </font></td><td>
    <input type="password" name="loginpassword" value=""></td></tr><tr><td>
    <input type="Submit" name="submit" value="Log In"></td><td>
    <input type="Reset" name="reset" value="Reset"></td></tr></form>
    </p><p> &nbsp; </p>
    
    </body></html>
    
    <?php 
    exit;
    }  ?>
    If I:

    PHP Code:
    print $username_enc
    I do get a long encrypted username, it just isn't setting the cookie. Also, cookie.php and config.php are included on a page and they work together.

    I get no error message.

    Any Help Appreciated...

    Lastly, How can I check using PHP if a setcookie() has been set directly after I set it?

    Thanx allot

    Peter

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got no idea myself, but last time I had trouble with cookie's I found the user comments in the online PHP manual extremely helpful - there's all sorts of info in there on why setcookie might not work...

    www.php.net/setcookie

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanx for that resource, however I already went before I posted this to try and find an answer.

    Thanx, any more suggestions?


Bookmarks

Posting Permissions

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