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

  • SEARCH
  • Home
  • 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 8557209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:31:27+00:00 2026-06-11T15:31:27+00:00

<?php $userid = $_POST[userid]; $pword = $_POST[pword]; # session session_start(); # check that session

  • 0
<?php

    $userid = $_POST["userid"];
    $pword = $_POST["pword"];

    # session

    session_start();

    # check that session is valid and set

    if(!isset($_SESSION['login']))
    {
        header('Location: login.php');
    }

    # check that the required values have been entered
    $testin1 = ($userid);
    $testin2 = ($pword);

    if($testin1 == "") 
    {
        print "<hr><h1> No Username Entered, Please return to the Login page</h1></hr>";
    }
    elseif ($testin2 == "") 
    {
        print "<hr><h1> No Password Entered, Please return to the Login page</h1></hr>";
    }

    # Connect to database

    $connect = mysql_connect ("localhost","root") or die("Error Connecting to SQLServer"); 
    $db = mysql_select_db ("test");

    # query  

      $query = mysql_query ("select username from login where username = '$userid' and pword = '$pword';");

    if($query === FALSE) 
    {
        die(mysql_error());
    }

    $result = mysql_fetch_array($query);
    $record = $result['username'] ;

    if ($record != null) 
    # check if session is operational, if so redirect the user to the correct page    
    {
        $_SESSION['login'] = true;
        header( 'Location: index.php' ) ;
    }
    else if ($record == null) 
    {
        header( 'Location: login.php' );
    }
?>

Does anyone know where this is not functioning? It seems to be ‘error free’ however keeps redirecting me back to the login.php page as opposed to the index.php page. any help would be great as i am a relative novice in PHP.

Thanks

  • 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-11T15:31:28+00:00Added an answer on June 11, 2026 at 3:31 pm

    It looks like you might possible be outputting data to the user before the header() is output. You have <HR>s and output (I know that it is only if there is an error) but if you are using those, you could well have <HTML> and the like above the code.

    If that is the case, then no other header will function.

    (Posting as answer as too long for comment – and might be the issue.

    Try this code:

    <?php
    
        session_start();
        $userid = $_POST["userid"];
        $pword = $_POST["pword"];
    
        // check that the required values have been entered
        $testin1 = ($userid);
        $testin2 = ($pword);
    
        if($testin1 == "") 
        {
            print "<hr><h1> No Username Entered, Please return to the Login page</h1></hr>";
        }
    
        if ($testin2 == "") 
        {
            print "<hr><h1> No Password Entered, Please return to the Login page</h1></hr>";
        }
    
        // Connect to database
    
        $connect = mysql_connect ("localhost","root") or die("Error Connecting to SQLServer"); 
        $db = mysql_select_db ("test");
    
        // query  
    
          $query = mysql_query ("select username from login where username = '$userid' and pword = '$pword';");
    
        if($query === FALSE) 
        {
            die(mysql_error());
        }
    
        $result = mysql_fetch_array($query);
        $record = $result['username'] ;
    
        if ($record != null) 
        // check if session is operational, if so redirect the user to the correct page    
        {
            $_SESSION['login'] = true;
            header( 'Location: index.php' ) ;
        }
        else if ($record == null) 
        {
            header( 'Location: login.php' );
        }
    ?>
    

    I looked through and moved a few things around as well as modifying the logic ever so slightly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script validation.php <?php if(!isset($_SESSION['userId'])){ session_destroy(); header('Location: home.php'); exit; } ?>
my code - require 'database.php'; $uid = $_SESSION['UserId']; $title = $_POST['imgtitle']; $tag = $_POST['imgtag'];
<?php require 'db.php'; include_once(header.php); include_once(functions.php); if(isset($_POST['search_term'])){ $search_term = mysql_real_escape_string(htmlentities ($_POST['search_term'])); if(!empty($search_term)){ $search = mysql_query(SELECT
<?php require 'db.php'; include_once(header.php); include_once(functions.php); include_once(profile.php); if(isset($_POST['search_term'])){ $search_term = mysql_real_escape_string(htmlentities ($_POST['search_term'])); if(!empty($search_term)){ $search =
<?php if(isset($_POST[user_name])) { $user_name=$_POST[user_name]; include(include/conn.php); $sql_check = mysql_query(select userid from `vector`.`signup` where userid='.$user_name.') or
I have the following two php scripts remove_directory.php <?php start_session(); $userId = $_SESSION['userId']; exec(escapeshellcmd(rm
Index.php <?php session_start(); require_once('../inc/db/dbc.php'); include('login_helper.php'); ?> <!-- html form --> Login/Logout Links depending on
I want a PHP script that logs into facebook with userid and password. posts
Here's my code: <?php session_start(); $currentPage = $_POST[currentPage]; $passedCoupID = $_POST[passedCoupID]; /* if youre
I am creating a login module in php. I am using session variables for

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.