SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: Cookies?

  1. #1
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookies?

    How can I set cookies with Kevin's mysql user tutorial?

    I wish to use cookies that will never expire, so when they come back the next day, they are still logged in!

    I'm not good with cookies, hwo could I do this?

    Thanks,
    ~someonewhois

    P.S. How do I delete cookies aswell?
    thanks

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    setcookie ("uid"$username); 
    Would that work?

    Put that instead of the sessions_register?

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or

    PHP Code:
    setcookie ("user"$uid); 
    $uid is the field in teh form...

  4. #4
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setcookie("uid","$username", time()+3600*24*365);

    thats 1 year.

    Delete..

    setcookie("uid","", time()-3600*24*365);

    ps. anyone got the code archive that they could mail me? i wiped my machine and forgot to save it . Kevin's email aint responding at the mo.
    Last edited by redgoals; Apr 7, 2002 at 13:55.
    http://redgoals.com ... my site ... nuff said

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!

    does it matter what $username is?

    $uid is the field in teh form, like I said... so is it supposed to be teh cookie itself?

    Thanks,
    ~someonewhois

  6. #6
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $uid as ive set it would be the name of the cookie. However if you want to pass the $uid then alter $username.
    http://redgoals.com ... my site ... nuff said

  7. #7
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I uesd exactly what you have above, and it didn't work...

    It makes me log in the next page I go to, so that's basicly worse than sessions...

    This is the basic accesscontrol.php file, so you can see the it:

    PHP Code:
    <?php // accesscontrol.php

    include("common.php");
    include(
    "db.php");

    session_start();

    if(!isset(
    $uid)) {
      
    ?>
      <html>
      <head>
      <title> Please Log In for Access </title>
      </head>
      <body>
      <h1> Login Required </h1>
      <p>You must log in to access this area of the site. If you are
         not a registered user, <a href="signup.php">click here</a>
         to sign up for instant access!</p>
      <p><form method="post" action="<?=$PHP_SELF?>">
        User ID: <input type="text" name="uid" size="8"><br>
        Password: <input type="password" name="pwd" SIZE="8"><br>
        <input type="submit" value="Log in">
      </form></p>
      </body>
      </html>
      <?php
      
    exit;
    }

    session_register("uid");
    session_register("pwd");

    dbConnect("sessions");
    $sql "SELECT * FROM user WHERE
            userid = '
    $uid' AND password = PASSWORD('$pwd')";
    $result mysql_query($sql);
    if (!
    $result) {
      
    error("A database error occurred while checking your ".
            
    "login details.\\nIf this error persists, please ".
            
    "contact [email]sowibb@hotmail.com[/email].");
    }

    if (
    mysql_num_rows($result) == 0) {
      
    session_unregister("uid");
      
    session_unregister("pwd");
      
    ?>
      <html>
      <head>
      <title> Access Denied </title>
      </head>
      <body>
      <h1> Access Denied </h1>
      <p>Your user ID or password is incorrect, or you are not a
         registered user on this site. To try logging in again, click
         <a href="<?=$PHP_SELF?>">here</a>. To register for instant
         access, click <a href="signup.php">here</a>.</p>
      </body>
      </html>
      <?php
      
    exit;
    }

    $username mysql_result($result,0,"fullname");
    ?>
    And I put thsi:

    PHP Code:
    <?php // accesscontrol.php

    include("common.php");
    include(
    "db.php");

    session_start();

    if(!isset(
    $uid)) {
      
    ?>
      <html>
      <head>
      <title> Please Log In for Access </title>
      </head>
      <body>
      <h1> Login Required </h1>
      <p>You must log in to access this area of the site. If you are
         not a registered user, <a href="signup.php">click here</a>
         to sign up for instant access!</p>
      <p><form method="post" action="<?=$PHP_SELF?>">
        User ID: <input type="text" name="uid" size="8"><br>
        Password: <input type="password" name="pwd" SIZE="8"><br>
        <input type="submit" value="Log in">
      </form></p>
      </body>
      </html>
      <?php
      
    exit;
    }


    setcookie("uid","$username"time()+3600*24*365); 
    setcookie("pwd","$passwd"time()+3600*24*365); 


    /*
    session_register("uid");
    session_register("pwd");
    */


    dbConnect("sessions");
    $sql "SELECT * FROM user WHERE
            userid = '
    $uid' AND password = PASSWORD('$pwd')";
    $result mysql_query($sql);
    if (!
    $result) {
      
    error("A database error occurred while checking your ".
            
    "login details.\\nIf this error persists, please ".
            
    "contact [email]sowibb@hotmail.com[/email].");
    }

    if (
    mysql_num_rows($result) == 0) {

    setcookie("uid",""time()+3600*24*365); 
    setcookie("pwd",""time()+3600*24*365); 

    /*
      session_unregister("uid");
      session_unregister("pwd");
    */

      
    ?>
      <html>
      <head>
      <title> Access Denied </title>
      </head>
      <body>
      <h1> Access Denied </h1>
      <p>Your user ID or password is incorrect, or you are not a
         registered user on this site. To try logging in again, click
         <a href="<?=$PHP_SELF?>">here</a>. To register for instant
         access, click <a href="signup.php">here</a>.</p>
      </body>
      </html>
      <?php
      
    exit;
    }

    $username mysql_result($result,0,"fullname");
    ?>

    I commeted teh old stuff just in case...

  8. #8
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php // accesscontrol.php

    include("common.php");
    include(
    "db.php");

    if(!isset(
    $uid)) {
      
    ?>
      <html>
      <head>
      <title> Please Log In for Access </title>
      </head>
      <body>
      <h1> Login Required </h1>
      <p>You must log in to access this area of the site. If you are
         not a registered user, <a href="signup.php">click here</a>
         to sign up for instant access!</p>
      <p><form method="post" action="<?=$PHP_SELF?>">
        User ID: <input type="text" name="uid" size="8"><br>
        Password: <input type="password" name="pwd" SIZE="8"><br>
        <input type="submit" value="Log in">
      </form></p>
      </body>
      </html>
      <?php
    }
    else
    {
    setcookie("uid","$uid"time()+3600*24*365); 
    setcookie("pwd","$pwd"time()+3600*24*365); 
    }

    dbConnect("sessions");
    $sql "SELECT * FROM user WHERE
            userid = '
    $uid' AND password = PASSWORD('$pwd')";
    $result mysql_query($sql);
    if (!
    $result) {
      
    error("A database error occurred while checking your ".
            
    "login details.\nIf this error persists, please ".
            
    "contact [email]sowibb@hotmail.com[/email].");
    }

    if (
    mysql_num_rows($result) == 0) {

    setcookie("uid",""time()-3600*24*365); 
    setcookie("pwd",""time()-3600*24*365); 

      
    ?>
      <html>
      <head>
      <title> Access Denied </title>
      </head>
      <body>
      <h1> Access Denied </h1>
      <p>Your user ID or password is incorrect, or you are not a
         registered user on this site. To try logging in again, click
         <a href="<?=$PHP_SELF?>">here</a>. To register for instant
         access, click <a href="signup.php">here</a>.</p>
      </body>
      </html>
      <?php
    }

    $username mysql_result($result,0,"fullname");
    ?>
    http://redgoals.com ... my site ... nuff said

  9. #9
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'll try htat!

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, that worked enough to be able to go into other files!

    it works a lot like sessions...
    everything done with it is the same!

    Including the problem that when you close the windo wna dcome back, you have to login again!

    Any ideas?

  11. #11
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OH, LOL!

    I was editing the same file in a different script, adn then uploaded teh un-changed one! :P

    Oops...

  12. #12
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Small problem

    I get 1 problem:

    The setcookie() is after a header, so I get errors about header already sent..

    can this be fixed?

  13. #13
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try..

    PHP Code:
    <?php // accesscontrol.php

    setcookie("uid","$uid"time()+3600*24*365);
    setcookie("pwd","$pwd"time()+3600*24*365);

    include(
    "common.php");
    include(
    "db.php");



    if(!isset(
    $uid)) {
      
    ?>
      <html>
      <head>
      <title> Please Log In for Access </title>
      </head>
      <body>
      <h1> Login Required </h1>
      <p>You must log in to access this area of the site. If you are
         not a registered user, <a href="signup.php">click here</a>
         to sign up for instant access!</p>
      <p><form method="post" action="<?=$PHP_SELF?>">
        User ID: <input type="text" name="uid" size="8"><br>
        Password: <input type="password" name="pwd" SIZE="8"><br>
        <input type="submit" value="Log in">
      </form></p>
      </body>
      </html>
      <?php
    }


    dbConnect("sessions");
    $sql "SELECT * FROM user WHERE
            userid = '
    $uid' AND password = PASSWORD('$pwd')";
    $result mysql_query($sql);
    if (!
    $result) {
      
    error("A database error occurred while checking your ".
            
    "login details.\nIf this error persists, please ".
            
    "contact [email]sowibb@hotmail.com[/email].");
    }

    if (
    mysql_num_rows($result) == 0) {

      
    ?>
      <html>
      <head>
      <title> Access Denied </title>
      </head>
      <body>
      <h1> Access Denied </h1>
      <p>Your user ID or password is incorrect, or you are not a
         registered user on this site. To try logging in again, click
         <a href="<?=$PHP_SELF?>">here</a>. To register for instant
         access, click <a href="signup.php">here</a>.</p>
      </body>
      </html>
      <?php
    }

    $username mysql_result($result,0,"fullname");
    ?>
    http://redgoals.com ... my site ... nuff said

  14. #14
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I doubt that will work, becuase it doesn't know what to use as teh uid etc.

    I'll try it!

    Thanks,
    ~someonewhois

  15. #15
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed it!

    I tried it without that else part, adn with teh exit things still there, and it wroekd!

    Thanks for your help,
    ~someonewhois


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
  •