Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8757581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:20:18+00:00 2026-06-13T14:20:18+00:00

I am having trouble with my code.It is supposed to redirect to a page

  • 0

I am having trouble with my code.It is supposed to redirect to a page if the login is okay.I am getting a successfully login but I am getting a error with the header forward.Here is the line which the problem is occurring:

header("Location: members.php");

Here is the error message:
Warning: Cannot modify header information – headers already sent

Here is my full code for the page if it helps:

<?php 
    // Connects to your Database 
    include("dbconnect.php");
    mysql_select_db("maxgee_close2");
    //Checks if there is a login cookie

    if(isset($_COOKIE['ID_my_site']))
     //if there is, it logs you in and directes you to the members page
    { 
        $username = $_COOKIE['ID_my_site']; 
        $password = $_COOKIE['Key_my_site'];
        $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
        while($info = mysql_fetch_array( $check )) 
        {
            if ($pass != $info['password'])
            {
            }
            else
            {
                header("Location: members.php");
            }
        }
    }
    //if the login form is submitted 
    if (isset($_POST['submit'])) { // if form has been submitted
     // makes sure they filled it in
        if(!$_POST['username'] | !$_POST['password']) {
            die('You did not fill in a required field.');
        }
        // checks it against the database

        if (!get_magic_quotes_gpc()) {
            $_POST['email'] = addslashes($_POST['email']);
        }
        $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

        //Gives error if user dosen't exist
        $check2 = mysql_num_rows($check);
        if ($check2 == 0) {
            die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
        }
        while($info = mysql_fetch_array( $check ))  
        {
            $_POST['password'] = stripslashes($_POST['password']);

            $info['password'] = stripslashes($info['password']);

            $_POST['password'] = md5($_POST['password']);

            //gives error if the password is wrong

            if ($_POST['password'] != $info['password']) {
                die('Incorrect password, please try again.');
            }
            else 
            { 
                // if login is ok then we add a cookie 
                $_POST['username'] = stripslashes($_POST['username']); 
                $hour = time() + 3600; 

              //then redirect them to the members area and the line with the error
              header("Location: members.php");
            }
        } 
      }
      else
      { 
        // if they are not logged in
         ?>
         <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
         <h1>Login</h1>
         Username:
        <input type="text" name="username" maxlength="40"> 
        Password:
        <input type="password" name="password" maxlength="50"> 
        <input type="submit" name="submit" value="Login">
        </form> 
    <?php 
     } 
     include("topsite.php");
    ?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:20:19+00:00Added an answer on June 13, 2026 at 2:20 pm

    You have written

    $password = $_COOKIE['Key_my_site'];
    

    But you are comparing $pass with $info[‘password’] and it should be

        if ($password != $info['password']){
    
        } else {
    
            header("Location: members.php");
        }
    

    You can modify your query in a better way by writing

    $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'")or die(mysql_error());
    
    if(mysql_num_rows($check) == 0) header("Location: members.php");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble with my code that is supposed to redo the
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I've successfully implemented passport-local into my Express/Mongoose web-app but I'm having trouble figuring out
I'm having trouble getting Google's load feed to work. Example is supposed to be
I am having trouble using the MapMaker from google-guava. Here is the code: package
I'm having trouble figuring out how to run the Android Marketplace Crawler here: http://code.google.com/p/android-marketplace-crawler/
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
I'm having trouble with the code below that refers to StoredPathName . As Indy
I seem to be having trouble with my code. I need to say: if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.