Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2007
    Posts
    184
    Tokens
    0

    Default How to set a cookie

    U have this in an echo.

    PHP Code:
    <form action=\"bank.php\" method=\"post\" autocomplete=\"off\">
    <table><tbody><tr><td>Username:</td><td>
    <input type=\"text\" maxlength=\"12\" value=\"\" name=\"user\" size=\"20\"></td></tr><tr><td>
        Password:</td><td>
    <input type=\"password\" maxlength=\"20\" value=\"\" name=\"pass\" size=\"20\"></td></tr><tr><td>&nbsp;</td><td align=\"center\">
    <input style=\"background: rgb(77, 66, 46) url('images/brownback.jpg') 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: white\" type=\"submit\" class=\"b\" value=\"Login to Admininistration Panel\" size=\"20\"></td></tr></tbody></table>
    <div>
    </div>
    </form> 
    How to i set so that when they either click the submit button it sets a cookie with the user + pass in, or that on the next page it sets a cookie with the user + pass in it from post data, and how do i retrive the information from a cookie sort of thing so say if i typed Ryan in the username field and password in the pass field, then it sets the cookie with Ryan + password in, how do i make a page where it shows the username + pass from the cookie.

    thnx
    Edited by Catzsy Forum Super Moderator: Your signature has been removed because
    It is against the rules to insult/bully other members by targetting them with personal remarks about them in your signature.

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Say the set variable for the username is $username and the set variable for the password is $password then all you do is:

    PHP Code:
    setCookie("user"$passwordtime()+3600); // Lasts for an hour
    setCookie("pass"$passwordtime()+3600); // Lasts for an hour also 
    To check for the cookie you just do

    PHP Code:
    if(isset($_COOKIE['user']) && isset($_COOKIE['password'])) {

    Ofcourse you then have to check the cookie over information in a database to make sure the cookie isnt fake :]

  3. #3
    Join Date
    Mar 2007
    Posts
    184
    Tokens
    0

    Default

    that kinda explained it all dont know how to say thnx enough ^^

    one more thing though, how would i display the username+password from the cookie, would it be..

    PHP Code:
    echo("$_COOKIE['user'] is the username and $_COOKIE['pass'] is the password"); 
    Is that right?
    Edited by Catzsy Forum Super Moderator: Your signature has been removed because
    It is against the rules to insult/bully other members by targetting them with personal remarks about them in your signature.

  4. #4
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    PHP Code:
    echo(""$_COOKIE["user"] ." is the username and "$_COOKIE["pass"] ." is the password"); 
    Is the best way to do it

  5. #5
    Join Date
    Mar 2007
    Posts
    184
    Tokens
    0

    Default

    ok thankzzz
    Edited by Catzsy Forum Super Moderator: Your signature has been removed because
    It is against the rules to insult/bully other members by targetting them with personal remarks about them in your signature.

Posting Permissions

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