Using seesion or cookie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    Using seesion or cookie

    i want to make the user to remind on my site.
    how can i do that with session or cookie like in this forum when i check the remember box ?
    and how can i secure cookie or session?
    what i will store in this cookie or session ex:(User ID or User name and his password)?
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    you will probably have to do it with cookies, since sessions are destroyed after a while.

    What you have to decide is how long the cookie should be valid, you probably want to store the IP-address and the user name, not a good idea to store the password.

    Google up some "best practice" for this kind of scenario.

    Hope this helps

    Comment

    • smartic
      New Member
      • May 2007
      • 150

      #3
      I need to enter username into the page when he login how can i do that?

      Comment

      • smartic
        New Member
        • May 2007
        • 150

        #4
        i want to enter the username into the page in this example i explain what i want[PHP]<?php
        // valid login credentials
        $username = 'admin';
        $password = 'admin_pass';
        // grab current time
        $time=time();

        // handle the logout event
        if ($_GET['logout'] == true) {
        setcookie ("user", md5($_POST[user]), $time-3200);
        setcookie ("pass", md5($_POST[pass]), $time-3200);
        header("Locatio n: index.php");
        }

        // handle validation event
        if ($_POST[user] && $_POST[pass]) {
        if ($_POST[user]==$username && $_POST[pass]==$password) {
        setcookie ("user", md5($_POST[user]), $time+3200);
        setcookie ("pass", md5($_POST[pass]), $time+3200);
        header("Locatio n: index.php");
        } else { $login_error= true; }
        }

        // handle login event, both successful and erroneous, or show login screen
        if ($login_error == true) { ?>
        <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
        <tr><td align=center bgcolor=#123dd4 >LOGIN ERROR</td></tr>
        <tr><td align=center><b >Invalid Username and/or Password</b><br><br><a href=index.php> Back</a></td></tr>
        </table>
        <?php
        } elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == md5($password)) { ?>
        <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
        <tr><td align=center bgcolor=#123dd4 >SECURE AREA</td></tr>
        <tr><td align=right><a href=index.php? logout=true>Log out</a></td></tr>
        <tr><td>You have successfully logged in.<br><br>
        Username: <b><?php echo "Her i want to right the username"; ?></b><br>
        Encrypted Username: <b><?php echo $_COOKIE['user']; ?></b><br>
        Encrypted Username: <b><?php echo $_COOKIE['user']; ?></b><br>
        </td></tr>
        </table>
        <?php
        } else {
        ?>
        <form action=index.ph p method=post>
        <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
        <tr><td colspan=2 align=center bgcolor=#123dd4 >LOGIN</td></tr>
        <tr><td align=right>Use rname: </td><td><input type=text name=user size=15></td></tr>
        <tr><td align=right>Pas sword: </td><td><input type=password name=pass size=15></td></tr>
        <tr><td align=center colspan=2><inpu t type=submit value=Login></td></tr>
        </table>
        </form>
        <?php
        }
        ?> [/PHP]

        Comment

        Working...