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 1 of 1
  1. #1
    Junior Member Lucian's Avatar
    Join Date
    Aug 2003
    Member #

    I'm trying to use sessions for my login script. The program will login to the members section, and display the member's area (member.php), however if you try to go to another page in the member's area and then come back to the member.php it just sends you back to the login page! AARGHHHH! lol

    Below are two code chunks: one is the login script that sets the user session and the second is the code placed on each page in the members section that you must be logged in to have access to.

    Anyone know what I am doing wrong? Probably something so simple it's stupid, anyway, here's the code!

    Login script:

    //check for required form fields
    if ((!$_POST[username]) || (!$_POST[password])) {
    $error = "Incorrect Username or Password, Please Try Again";
    header("Location: index.html");

    //connect to server and select database
    $conn = mysql_connect ($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($db);

    //create and issue query
    $sql = "select * from login_info where username = '$_POST[username]' AND pass_wd = '$_POST[password]'";
    $result = mysql_query($sql,$conn) or die(mysql_error());

    if (mysql_num_rows($result) == 1) {
    $user = mysql_result($result, 0, 'username');


    setcookie ("theuser",$user, 0, "/", $host, 0);
    header( "Location: member.php" );
    else {
    header("Location: index.html");

    This is the script used to check if the session is set (placed in each page that you must be logged in to view at the very very tip top):





    header( "Location: index.html" );

    Thanks for your help,

    Are your website promotion efforts yielding less than satisfactory results? Check out the Website Promotion Tips Blog for help!


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:22 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: