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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:07:09+00:00 2026-05-16T17:07:09+00:00

I have a PHP authentication system on my website using the $_SESSION variable. A

  • 0

I have a PHP authentication system on my website using the $_SESSION variable.

A form submits a username and password to the file “login.php”. It is handled like this:

<?php include '../includes/sessionstart.inc.php'; ?>
<?php ob_start(); ?>

if($_POST){
    $q = mysql_query("SELECT id, company FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."' AND password = '".md5($_POST['password'])."'");
    if(mysql_num_rows($q) >= 1){
        $f = mysql_fetch_Array($q);
        $_SESSION['company'] = $f['company'];
        $_SESSION['id'] = $f['id'];
        $_SESSION['logedin'] = true;
        session_write_close();

        ob_clean();
        header("Location: index.php");

}

Afterwards, index.php is loaded and checks whether ‘logedin’ is true.

<?php include '../includes/sessionstart.inc.php'; ?>
<?php if(!isset($_SESSION['logedin'])) header('Location: login.php'); ?>

On my production server, it continues, but on my Wampserver, it reverts back to login.php. I notice that Wampserver is very slow in page loading, this might have to do something with it. That’s why I included the session_write_close, to make sure session data is saved before the pages are switched, but it doesn’t help.

The contents of session_start.inc.php are simply:

<?php
    session_start();
?>

I used to have more code in there, but at the moment it’s just this. The problem also existed before I started using an include file.

Does anybody have an idea what I’m doing wrong? Why doesn’t Wampserver transmit my SESSION data to the next PHP file?

  • 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-16T17:07:10+00:00Added an answer on May 16, 2026 at 5:07 pm

    After a long time I have fixed this bug finally.

    On my localhost WAMP, the session data is not saved between page loads, because the session data is stored in a cookie, and there is no cookie domain to be set for localhost.

    The solution:

    ‘session.cookie_domain’ should be set to empty string for all local domain names, not only for ‘localhost’ (but should not be empty for local IP addresses):

    <?php
    ini_set('session.cookie_domain', (strpos($_SERVER['HTTP_HOST'],'.') !== false) ? $_SERVER['HTTP_HOST'] : '');
    ?>
    

    Thanks to Marcin Wiazowski who posted it here.

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

Sidebar

Related Questions

I'm developing a login and authentication system for a new PHP site and have
I have just succeeded in creating oAuth authentication for my twitter application using PHP.
I have been toying with http authentication using the .htaccess file in an attempt
I already have a simple registration system in place using php and mysql. It
I am editing someone else's PHP, and they have an 'authentication' system in which
I have an existing php website with a user system already set up (registration,
I'm trying to design a two factor authentication system (on PHP) using SMS as
I'm using Orbited to build a Comet chat system on a PHP-based website. However,
Have anyone reading the description of PHP user authentication system at Wikibooks? http://en.wikibooks.org/wiki/PHP_Programming/User_login_systems Is
I have a PHP site that uses a fairly common authentication scheme. The entire

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.