cookies and login

Discussion in 'PHP' started by legend19892008, Jul 4, 2008.

  1. #1
    plz i have a login system , i want to make cookies inside it ,when the person login
    this is my code
    login.php
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="login2.php">
      <label>username
      <input name="username" type="text" id="username" />
      </label>
      <p>
        <label>password
        <input name="password" type="password" id="password" />
        </label>
      </p>
      <p>
        <label>
        <input type="submit" name="Submit" value="Submit" />
        </label>
      </p>
    </form>
    <p>&nbsp;</p>
    </body>
    </html>
    
    PHP:
    and login2.php
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?
    $conn=mysql_connect("localhost","root","root");
    mysql_select_db('project3');
    include("include.php");
    $username=$_POST['username'];
    $password=$_POST['password'];
    $password=md5($password);
    if ($username&&$password)
    {
    if (checklogin($username,$password))
    {
    echo "success";
    }
    else
    {
    echo "failed";
    }
    }
    
    
    ?>
    </body>
    </html>
    
    PHP:

     
    legend19892008, Jul 4, 2008 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    In the login2.php you have code before <?, which will not let the cookie headers be sent to browser. It is a standard that when you send anything as header to browser, there bust not be even a single byte already sent. PHP distribution for win32 might allow sometimes but not always.

    And please explain " i want to make cookies inside it ".

    regards
     
    Vooler, Jul 4, 2008 IP
  3. websinch

    websinch Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?
    $conn=mysql_connect("localhost","root","root");
    mysql_select_db('project3');
    include("include.php");
    $username=$_POST['username'];
    $password=$_POST['password'];
    $password=md5($password);
    if ($username&&$password)
    {
    if (checklogin($username,$password))
    {
    setcookie("username", $username, time()+3600, "", ".domain.com");
    setcookie("password", $password, time()+3600, "", ".domain.com");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    echo "success";}
    else
    {
    echo "failed";
    }
    }
    
    
    ?>
    </body>
    </html>
    PHP:
    hope that helps but this is just of the top of my head and personally i would prefer to use sessions or use a customisable validation library
     
    websinch, Jul 4, 2008 IP
  4. legend19892008

    legend19892008 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it gave error
    [​IMG]
     

    Attached Files:

    legend19892008, Jul 4, 2008 IP
  5. jmf000

    jmf000 Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    See the file include.php
     
    jmf000, Jul 4, 2008 IP