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 8747673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:23:44+00:00 2026-06-13T12:23:44+00:00

Following help from this site I have now got my log in script largely

  • 0

Following help from this site I have now got my log in script largely working, however there is an issue when I try to check for a session on a restricted page the full code as follows.

The log in script itself

    <?php

function validateUser()
{

    session_regenerate_id (); //this is a security measure
    $_SESSION['valid'] = 1;
    $_SESSION['userid'] = $userid;
}


?>

<?php

ob_start(); // Start output buffering

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

session_start(); //must call session_start before using any $_SESSION variables
$username = $_POST['username'];
$password = $_POST['password'];
//connect to the database here

$hostname_PropSuite = "localhost";
$database_PropSuite = "propsuite";
$username_PropSuite = "root";
$password_PropSuite = "root";
$PropSuite = mysql_pconnect($hostname_PropSuite, $username_PropSuite, $password_PropSuite) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db($database_PropSuite, $PropSuite);

$username = mysql_real_escape_string($username);

$query = "SELECT password, salt FROM admin_users WHERE username = '$username';";

$result = mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result) < 1) //no such user exists
{
    header('Location: http://localhost/PropSuite/index.php?login=fail');

    die();
}
$userData = mysql_fetch_array($result, MYSQL_ASSOC);
$hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
if($hash != $userData['password']) //incorrect password
{
    header('Location: http://localhost/PropSuite/index.php?login=fail');

    die();
}
else
{
   validateUser(); //sets the session data for this user
}
//redirect to another page or display "login success" message
header('Location: http://localhost/PropSuite/main');
die()




//redirect to another page or display "login success" message


?>

The page I am trying to restrict.

<?php

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);



function isLoggedIn()
{
    if(isset($_SESSION['valid']) && $_SESSION['valid'])
        return true;
    return false;
}

//if the user has not logged in
if(!isLoggedIn())
{
    header('Location: http://localhost/PropSuite/index.php');
    die();
}
//page content follows
?>

What happens when I press log in is that it is taking me back to the log in page so it seems to go through the log in script then when it hits the main page that throwing me back to the log in page. I’m confused.com 🙁

Thank you in advance for your help

  • 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-13T12:23:45+00:00Added an answer on June 13, 2026 at 12:23 pm

    In the page you trying to restrict i see no session_start

    <?php 
      session_start();
      error_reporting(E_ALL & ~E_NOTICE);
      ini_set('display_errors', TRUE);
      ini_set('display_startup_errors', TRUE);
      .....
    ?>
    

    By the way in your other script you should wrote this

     <?php
         .....
         $username = isset($_POST['username'])?$_POST['username']:'';
         $password = isset($_POST['password'])?$_POST['password']:'';
        ...
      ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help regarding the following issue. I have enabled the Block popup option in
Following from my last question which @Jon Skeet gave me a lot of help
Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
This may be a repeat of the following unanswered question: Help with bitmap lock
Please help me with following, I have a database which contain strings ( e.g.
Please help with the following: I have an input file that is quite heterogeneous
Please help me with following problem. In my android assets folder I have xml
I am using the following script on a site and it works perfectly -
Following this post which I posted some time ago, I now get the same
I have been using the following preload script to load all the images and

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.