Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to add security and sessions

    Hi,

    Iam new to PHP,how to add sesssions and secruity to the following code for the admin page.


    <?php
    function login()
    { global $err;
    include("head.php");
    ?>
    <tr><td> <table border="0" cellpadding="0" cellspacing="0" height="150" width="200" align="center">
    <tr>
    <td height="20" align="center" bgcolor="#ffffff">
    <font color="#000000">Admin Login</font>
    </td>
    </tr>
    <tr>
    <td valign="top">
    <form action="" method="post"><br>
    <table border="0" cellpadding="3" cellspacing="0" align="center">
    <tr>
    <td width="64">
    <b>Username:</b></td>
    <td width="134"><input type="text" name="aname" value="<?php echo $name;?>" /></td>
    </tr>
    <tr>
    <td>
    <b>Password:</b></td>
    <td>
    <input type="password" name="apass" value="<?php echo $pass;?>"></td>
    </tr>
    <tr>
    <td colspan="2">
    <center><input type="hidden" name="maa" value="do_login"><input type="submit" name="submit" value="Submit"></center>
    <input type="hidden" name="Refer" value="<? echo($refer) ?>"
    </td>
    </tr>
    </table>
    </form>

    </td></tr>
    </table> </td></tr>
    <tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td><?php echo $err; ?></td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr>
    <?php footer(); }

    function do_login()
    {

    global $err;
    $name="admin";
    $pass="admin";
    $adn=$_REQUEST['aname'];
    $adp=$_REQUEST['apass'];
    if(($name==$adn)&&($pass==$adp))
    {
    admin();
    }
    else
    {
    $err="<font color=\"#CC0033\"><div align=\"center\" class=\"style9\"><b>LOGIN_ERROR</b></div></font>";
    login();
    }

    }


    where i need to add sessions in the above code

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can add set a session object in a session like this:
    session_start();
    $_SESSION['admin'] = true;

    verify and protect the page ith this code:
    session_start();
    if($_SESSION['admin'] !== true) {
    die('access denied');
    }

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    1 topic per question please.

    This is the third one?

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I know, seems like he's wanting to fool us and have each thread add a little extra code onto his script to finish it off for him


  •  

    Posting Permissions

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