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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:59:11+00:00 2026-05-16T03:59:11+00:00

I am using a PHP login script that challenges user for username & password.

  • 0

I am using a PHP login script that challenges user for username & password.

Once authenticated program stores a session value. On logout, session value is set to blanks.

Once logged out I want to avoid allowing user hitting the back button a few times and and betting allowed to see screen of data or accidentaly logging himself back in.

I am using sessions, a re-direct to send validated user to a new page. I am also using ob_start, ob_flush and ob_end_clean to prevent error or re-direct.

Questions:
Is this really secure?
Is this a common approach?
Is there alterternative to buffering?

below is a small proof-of-concept.

<?php
header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");  
header("Pragma: public"); 
session_cache_limiter('nocache');
// I'm not sure how effective any of the above seem to be.

session_start();

// start buffering because if we use header later we want to avoid error
ob_start();

echo "Type <b>in</b> or <b>out</b> to login/logout<br>";
?>

 <form action='' method='POST'>
 <input type='text' name='status' size='10' value=""><br/><br/>

 <p>&nbsp;</p>
 <input type='submit' name='Login' value='Login' /></form></p>

<?php 
 if ($_POST['status'] == 'in')
 {
  $_SESSION['logged_in'] = 'in';  
  ob_end_clean();  // clean and erase buffer so far
        header('location:test2.php');        
        exit;
 }

 if ($_POST['status'] == 'out')
 {
  $_SESSION['logged_in'] = 'no';
  echo "you are logged out <br>";

 }
 ob_flush();   // push output
 echo "login status = " . $_SESSION['logged_in']  ;

?>



file test2.php
<?php
echo "You have logged in"; 
?>
  • 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-05-16T03:59:12+00:00Added an answer on May 16, 2026 at 3:59 am

    What you need is a proper logout method rather than testing session data. You want the session to be wiped competely. Here is an example that logs the user in and logs the user out and also checks if the user is logged in. When you click the logout page you’re automatically logged out and redirected. Clicking back won’t change anything you still won’t be logged in.

    login.php

    session_start();
    $valid = someLoginFunctionHere();
    if($valid) {
         $_SESSION['isLoggedIn'] = true;
         header("Location: homepage.php");
    }
    

    homepage.php

    session_start();
    // If they are not logged in, send them to login page
    if(!isset($_SESSION['isLoggedIn'])) {
        header("Location: login.php");
    }
    
    // Normal homepage stuff
    ...
    

    logout.php

    session_start();
    session_destroy();
    header("Location: login.php");
    

    Hope this helps demystify sessions a bit for you.

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

Sidebar

Related Questions

So I have this login php script that I am using and it works
I am using my admin panel login script where i have created a global.php
Assume that I have login to system using PHP + MySQL, then, after I
I am building a website using php and mysql.I have a login that is
I'm trying to set up a login script for PHP using the tutorial on
I have a php script that shows all the picasa public albums by using
I'm creating a login script for a website i'm developing, and am using PHP
I've got a really simple login script using PHP's sessions to limit access, but
I would like to make a simple user login/registration system using PHP and mysql.
I've been dabbling abit with a login script (PHP and MySQL), using various online

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.