SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with user session

    I am trying to solve following problem. I display a link on my web page if user
    successfully sign-in. (To do this I take username and password entered by user and go to database). Link is successfully displayed but it disappear when I click signon button again.Here is how I am doing it.
    ==========================================================<php?
    session_start();
    ?>
    <HTML>
    <head>Testing</head>

    <body>
    <form METHOD="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table>
    <tr>
    <td><input type="text" name="login" size="10"></td>
    <td><input type="password" name="pwd" size="10"></td>
    <td ALIGN="right">&nbsp;<input type="image" border="0" value="login"
    name="login" src="/icons/signon.gif" align="absmiddle">
    </tr>
    </table>
    </form>

    <?php
    $_SESSION['loggedin'] = 'no' ;
    if (isset($_POST['login']) && isset($_POST['pwd']))
    {$var1 = $_POST['login'] ;
    $var2 = $_POST['pwd'] ;
    $link = mysql_connect('localhost', 'root', 'root') or die('Could not connect: ' . mysql_error());
    mysql_select_db("dbiocr",$link);
    $sql = "SELECT * FROM users WHERE username = '$var1' AND password = '$var2'" ;
    $result = mysql_query($sql , $link) or die(mysql_error().'<br> SQL:'.$sql);
    if (mysql_num_rows($result) > 0){
    $_SESSION['loggedin'] = 'yes' ;
    }
    }
    ?>

    <table border="0" width="100%" cellpadding="0">
    <tr>
    <td align="center">|<a href="/howto.html">How To Guide</a>|
    <?php
    if ($_SESSION['loggedin'] == 'yes'){
    echo "|<a href=\"/newcr.php\">Create New Request</a>|" ;
    }
    ?>
    </td>
    </tr>
    </table>


    </body>
    </HTML>
    ==========================================================
    I understand the reason for it and here it is. Second time $_SESSION['loggedin'] = 'no' is not changed to 'yes'. if ($_SESSION['loggedin'] == 'yes') test arround the link fails, so link is not displayed. If I remove $_SESSION['loggedin'] = 'no', then it complains about $_SESSION['loggedin'] not defined.
    Can someone help me how to solve this?

    Best Regards

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry mubashar...this is an asp forum not php...you'll have better luck in that forum


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
  •