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 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

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From a coding perspective, starting with version 3.0 of the… May 16, 2026 at 10:48 am
  • Editorial Team
    Editorial Team added an answer I gave up trying to get Stored Procedures to work… May 16, 2026 at 10:48 am
  • Editorial Team
    Editorial Team added an answer You can change you're site's url easily by adding in… May 16, 2026 at 10:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to set up a login script for PHP using the tutorial on
I need to cause a user's browser to post data using PHP to another
I have a login script that when successful, should check to see if the
I have a server-side php-script that fetches results from a MySQL table. I am
I am making a simple Dynamic Website using PHP, where i allow the user
I need to make a proxy script that can access a page hidden behind
I am having a problem using PHP's PDO object to prepare an update statement
I'm looking for a good PHP login class via MySQL, and I'm not yet
How can I use HTTP basic Authentication and have the user submit their Username
Using PHP, I'm trying to give each specific text its own variable. I believe

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.