If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    May 2003
    Member #
    Hey. I have a login form. The submitted values are checked a mysql table. If a match is found, I set the session variable name to the value of username using this code.

    PHP Code:
    $sql="SELECT * FROM users WHERE username='".$username."' AND password='".md5($passw)."'";
    $res=mysql_query($sql) or die("Error: ".mysql_error());
    $_SESSION['name'] = $username;
    header("Location: admin.php");
    This works fine. I am then able to view the admin pages and perform admin stuff.

    But a section of this particular site allows visitors to leave feedback. Everytime I leave a page and go to feedback.php and then leave to another page I lose my session variable $_SESSION['name'] but I am still logged in.

    I am not sure where lies the problem, if it is on feedback.php, or if it is on header.php (which is included on each page, its purpose is to determine if you are logged in.)

    header.php is smaller than feedback.php so I will post that code
    PHP Code:
    // check if logged in
    if (isset($_SESSION['name'])) {
    $author $_SESSION['name'];
    $query "SELECT * FROM users WHERE username='$author' ORDER BY id";
    $result mysql_query($query);
    $numrows mysql_num_rows($result);
        if (
    $numrows == "0") {
    "No codes to display.<br /><br />";} // i get this message becuase it is trying to select but author has no value
    else {
    $row mysql_fetch_array($result))
    $profilelink"<a href='viewprofile.php?id=" $row['id'] . "'>Your profile</a><br><br>";
    <a href="logout.php" title="Logout">Logout</a> - <a href="news.php" title="News">News</a> - <a href="admin.php" title="Admin">Admin</a> - <a href="index.php" title="Home">Home</a> - <a href="members.php" title="Member list">Members</a>
    <?php echo " - ";
    $profilelink; } else { ?>

    <a href="login.php" title="Login">Login</a> - <a href="news.php" title="News">News</a> - <a href="index.php" title="Home">Home</a> - <a href="register.php" title="Register">Register</a> - <a href="members.php" title="Member list">Members</a>
    <?php ?>
    One thing you may notice is that I have not included
    PHP Code:
    header("Cache-control: private");
    This is because I have this on the page that includes header.php

    I have attached feedback.php

    To recap, when I log on, and goto feedback.php then navigate to another page $_SESSION['name'] value is lost. And then on all the other pages I visit after that, I get the "No codes to display." error message which is defined in header.php

    The only way to fix this is to log out then log in again.

    Thanks a lot to anyone who helps me.


  3. #2
    Junior Member w84me's Avatar
    Join Date
    Jun 2005
    Member #
    I think its better this way...

    $username = $_POST['username'];
    $password = $_POST['password']; 
    $password = md5($password);
       $sql = mysql_query("SELECT * FROM users
                               WHERE username ='$username'
                               AND password = '$password'")
                                or die (mysql_error());
       if(mysql_num_rows($sql) == 1){
          while($row = mysql_fetch_assoc($sql)){
             $_SESSION['username'] = $row['username'];
    Check that i am doing a $row['username'] not just $username

  4. #3
    Senior Member
    Join Date
    Jun 2005
    Atlanta, GA
    Member #
    1 times
    I don't know whether this matters or not, but it doesn't look like you included header.php on feedback.php. Is this intentional?

    Also, do you have register_globals on in php.ini?

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 04:42 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: