Autologin using cookie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vashafnas
    New Member
    • Feb 2008
    • 8

    Autologin using cookie

    Hello all,
    I have an autologin feature in the login form.So if autologin selected once,it should work using cookies then.How to use it.Please help???
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    [php]<?php
    //file name: index.php
    if isset($_COOKIE['name_of_the_co okie']) //COOKIE YOU ALREADY SET
    {
    $p1 = $_COOKIE['saved_password _in_the_cookie']; //PASSWORD IN THE COOKIE
    /*
    FETCH FROM DATABASE, THE ROW (SAY $db_row)HAVING THAT ID
    $sql = _______________ ______________ ;
    */
    $p2 = $db_row['password']; //PASSWORD FETCHED FROM DB FOR THAT ID

    if ($p1 == $p2) //COMPARE PASSWORDS
    {
    header ("location:home .php"); //REDIRECT IF COOKIE VERIFIED
    }
    }
    else
    {
    header ("location:logi n.php"); //REDIRECT TO LOGIN PAGE
    }
    ?>[/PHP]
    Is this what you need?

    Comment

    • vashafnas
      New Member
      • Feb 2008
      • 8

      #3
      Thanks,but an error comes,cannot modify header..

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by vashafnas
        Thanks,but an error comes,cannot modify header..
        Are you using it as it is?....

        Remove any space or line break before <?php if there.

        Comment

        • vashafnas
          New Member
          • Feb 2008
          • 8

          #5
          Sorry for the late reply.
          I used[php]
          if(isset($_POST["autologin"]))
          {
          $inTwoMonths = 60 * 60 * 24 * 60 + time();
          setcookie('user name',$_POST["Password"], $inTwoMonths);
          setcookie('pass word',$_POST["Password"], $inTwoMonths);
          }
          in login page and
          if(isset($_COOK IE['username']) AND isset($_COOKIE['password']))
          {
          $_SESSION["ww_2"]=23;
          $redir=$_GET["redir"]?$_GET["redir"]:$_POST["redir"];
          $redir=($redir? $redir:"./?p=myaccount&s= dayplanner");
          header ("location:home .php");
          //echo "<script language='javas cript'>window.l ocation='$redir '</script>";
          exit();

          } [/php]
          in index page.
          Please tell wat is wrong??Again i have to login..
          Last edited by ronverdonk; Mar 4 '08, 10:42 AM. Reason: code within code tags

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

            moderator

            Comment

            Working...