Results 1 to 3 of 3

Thread: Retrive value from cookie

  1. #1
    Join Date
    Sep 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Retrive value from cookie

    Hello,

    I am using <input type="password" name="txtPwd">

    How can I retrive value in txtPwd from cookie on page_load.

    Thanks

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You wouldn't because you wouldn't store a password in a cookie.

    If you are implementing a log in system, a user's password should be stored, hashed, on the server.

    Mike

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    Wrong method for handling a password, if you keep a password in a cookie any time it got erased or intercepted in some way, don't do that. MWinter is 100% correct.


    ASP

    In ASP The "Response.Cookies" command is used to create cookies

    The "Request.Cookies" command is used to retrieve a cookie value.

    Writing a cookie, cookie name is user and cookie value is codeexploiter
    Code:
    <%
    Response.Cookies("user")="codeexploiter"
    %>
    Reading a cookie

    Code:
    <%
    username=Request.Cookies("user")
    response.write("user name is " & username)
    %>
    Cookie with keys: creation

    CODE]Response.Cookies("user")("fname")="Code"
    Response.Cookies("user")("lname")="Exploiter"
    Response.Cookies("user")("country")="India"
    Response.Cookies("user")("age")="25"[/CODE]

    Cookie with keys: reading

    Code:
    Response.write Request.cookies("user")("firstname")
    Response.write Request.cookies("user")("lname")
    Response.write Request.cookies("user")("country")
    Response.write Request.cookies("user")("age")


    If you want to learn how to set cookie using PHP then check the following

    The setcookie() function is used to set a cookie.

    Note: The setcookie() function must appear BEFORE the <html> tag.

    Syntax
    setcookie(name, value, expire, path, domain);



    PHP Code:
    <?php 
    setcookie
    ("user""codeexploiter"time()+3600);
    ?>

    Retrieve a Cookie Value

    The PHP $_COOKIE variable is used to retrieve a cookie value.

    In the example below, we retrieve the value of the cookie named "user" and display it on a page:

    PHP Code:
    <?php// Print a cookieecho $_COOKIE["user"];// A way to view all cookies
    print_r($_COOKIE);
    ?>
    Here we check whether a cookies exist/has a value or not


    PHP Code:
    <?php
    if (isset($_COOKIE["user"]))
    echo 
    "Welcome " $_COOKIE["user"] . "!<br />";
    else
    echo 
    "Welcome guest!<br />";
    ?>
    If you want more details about this topic then refer PHP manual
    Last edited by codeexploiter; 09-19-2006 at 11:43 AM.

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
  •