After years of developing websites and in this case, the same website I'm having a problem with, I'm at a complete loss with what's happening. I have a standard php login that consists of three pages:
login.php to input login information, checklogin.php to check the input credentials then home.php as the landing page
All of which have worked perfectly fine for years as they've barely been changed within that time. Now, recently I've moved hosting company and with that obviously meant the daunting task of re-installing all of my preferred web hosting software and configuring it to my websites needs. So anyway since the website coding hasn't changed, I've figured it must be a server problem, either the server configuration or a setting I must have missed out.
The configuration set up I have now worked for all of three days then 'poof' it just doesn't want to set sessions any more. I can set one and display it but if I try to carry it over to another page, it won't work.
Can anyone explain what may have just magically happened within three days that decided to just ruin everything?
A few notes:
- Yes, I am using
session_start();
on my landing page and any I intend to take the sessions to. - I've used the tags to give you an idea of what software my server is running for web pages (Since I'm still unsure what's causing it)
- The php session path is
/var/lib/php/sessions/
which has the correct permissions for Apache/nginx - MySQL is collecting the data and php is setting the sessions on page 2 but then page 3 seems to have lost the sessions.
Here's an example of a quick throw-together I did to test it:
Page 1: Setting the sessions:
<?php
session_start();
require_once'../connect.php'; // Database connection
$user_info = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id = '1'"));
$_SESSION['myid'] = $user_info['id'];
$_SESSION['myuser'] = $user_info['username'];
// Echo the set sessions just to make sure they set
echo 'ID: ' . $_SESSION['myid'] . ' - Username: ' . $_SESSION['myuser'] . '';
echo '<br /><a href="/page2.php">Click here to take your sessions to the next page</a>';
?>
Page 2: Moving on with the sessions:
<?php
session_start();
echo 'ID: ' . $_SESSION['myid'] . ' - Username: ' . $_SESSION['myuser'] . '';
?>
As you can see from the basic example above, page 2 should display my sessions but it just won't. Any help with this is much appreciated, it's driving me mad, mainly for the fact of not knowing what's causing it. Let me know if any further details are needed and I'll try to be as specific as possible.