i need some help in cookie

Discussion in 'PHP' started by dr_fish, Aug 1, 2009.

  1. #1
    Hello Man! , listen .. i started to learn PHP 4 days ago..
    Now I am learn how to use in cookie.
    but I have a problem.

    After logging in I appears to me, "You are logged in" .. If I do "refresh" still appears to me .. But if I click on the "Home" is the login name .. So it disappeared for me

    <?php
     $user = $_POST["username"];
    setcookie("youlog" , $user , time()+3600);
    /*
    ===================================================================================
                                        START
    ================================================================================
    */
    ini_set('display_errors', 0);
    $link = mysql_connect("localhost","root","")or die(mysql_error());
    mysql_select_db('new')or die(mysql_error());
    if($_POST["submit"]) {
     $user = $_POST["username"];
    $pass = $_POST["password"];
    $query = mysql_query("SELECT * FROM `register` WHERE username='".$user."' AND password='".$pass."'");
    $res = mysql_num_rows($query);
    if ($res == 1) 
     { 
    echo '<div class="login">' . "." . $user . " " . 'התחברת בהצלחה</div>'; 
    $cookie = $_COOKIE["user"];
    echo '<div class=cookie>' . $_COOKIE["youlog"] . " " . 'אתה מחובר' . '</div>';
     }
     else
     {
    echo  "<div class=login>!שם המשתמש או הסיסמא אינם נכונים</div>";
     }
    }
    
    /*
    ===================================================================================
                                       END
    ================================================================================
    */
    ?>
     
    <HTML>
     
     <HEAD>
      <TITLE> TheWall - נסו לגלות מה מסתתר מאחורי החומה </TITLE>
    <style>
    input.user {
    position:absolute;
    top:120px;
    left:480px;
    border-width:0px;
    };
    input.pass {
    position:absolute;
    top:176px;
    left:480px;
    border-width:0px;
    };
    input.submit {
    position:absolute;
    top:210px;
    left:535px;
    };
    div.log {
    font-family:arial;
    position:absolute;
    left:400px;
    top:250px;
    };
    div.login {
    font-family:arial;
    position:absolute;
    left:420px;
    top:250px;
    font-size:12px;
    };
    div.cookie {
     font-family:arial;
    position:absolute;
    left:780px;
    top:44px;
    font-size:12px;
    };
    
    </style>
     </HEAD>
    <body>
     <img src="photos/test.jpg" width="1000" height="1000" border="0" alt="ראשי" usemap="#web_Map">
    <map name="web_Map">
    <area shape="rect" alt="קישורים" coords="85,362,118,400" href="links.php">
    <area shape="rect" alt="אלופים" coords="131,329,164,357" href="champ.php">
    <area shape="rect" alt="צור קשר" coords="176,300,216,329" href="conract.php">
    <area shape="rect" alt="הוראות" coords="238,287,274,309" href="howtoplay.php">
    <area shape="rect" alt="תקנון" coords="297,292,327,300" href="rules.php">
    <area shape="rect" alt="פרסים" coords="342,292,374,309" href="prrizes.php">
    <area shape="rect" alt="ראשי" coords="393,300,422,321" href="index.php">
    </map>
    <FORM METHOD=POST ACTION="index.php">
     <INPUT   class="user" TYPE="text" NAME="username">
      <INPUT   class="pass" TYPE="password" NAME="password">
     <input type="submit" class="submit" value="התחבר" style="width:50px; height:23px; border:#ffffff 0px solid;  font: bold 11px arial middle; background-color:c5df1e; color:white" name="submit" />
    </FORM>
      
     
    <?php
    ?>
     
     
     
     
     
     
     </BODY>
    </HTML
    PHP:

     
    dr_fish, Aug 1, 2009 IP
  2. CodeSpire

    CodeSpire Guest

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can we see the home page code? I'm guessing that there's no code for processing the cookie in there.
     
    CodeSpire, Aug 2, 2009 IP
  3. nishanair

    nishanair Active Member

    Messages:
    188
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    You are using html input not using the value. You have to add some more code in your home page, like

    if(!empty($cookie))
    {
    echo name
    }
    else
    {
    <FORM METHOD=POST ACTION="./">
     <INPUT   class="user" TYPE="text" NAME="username">
      <INPUT   class="pass" TYPE="password" NAME="password">
     <input type="submit" class="submit" value="התחבר" style="width:50px; height:23px; border:#ffffff 0px solid;  font: bold 11px arial middle; background-color:c5df1e; color:white" name="submit" />
    </FORM>
    }
    PHP:
    I think you understand what i mentioned above.
     
    nishanair, Aug 2, 2009 IP
  4. ptalent

    ptalent Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    edit: nevermind lol
     
    ptalent, Aug 2, 2009 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Don't use just cookies for logging people in, that's very insecure since cookies are stored clientside and can be easily edited. Instead, use sessions.
     
    premiumscripts, Aug 3, 2009 IP