Sorry guys if this a long winded post but I need to ask this the way it is. Well, I've tried this code on a couple of servers and it doesn't work properly!
I've been trying to change my PHP script from mysql to mysqli with more fails than success so far.
the registration form works fine, it will add the record to mysql database and it will send an email to the user as well without any errors. i got this on all my pages to make sure I am not getting any error:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
The login form also works just fine and it will logs in the user to their account.
But here is the issue, well a couple of issues that I have been facing.
1- there is simple toplink at the top of the page which will show login and Register if the users are not logged in and it will show their username and logout links once they are logged in. this seems to have mind of its own as it works on one server and it doesn't work on another. by working i mean is that on one server it will stay on login and Register links even if the user is logged in.
2- there is a logout.php file which should log the users out and end the session. but this again has mind of its own. on the older PHP server it will work fine but if I refresh the page on the users account URL again, it will automatically logs the user back in. it doesn't matter which browser i try this in and how many times i clear the cache and cookies. it will still logs the user back in the account on page refresh.
also, the logout.php file doesn't work on a server with php version 5.3.21 and it will not log he user out of their account!!
This is the member.php code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
session_start(); // Must start session first thing
// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '<a href="member.php?id=' . $userid . '">' . $username . '</a> •
<a href="member.php">Account</a> •
<a href="logout.php">Log Out</a>';
} else {
$toplinks = '<a href="join_form.php">Register</a> • <a href="login.php">Login</a>';
}
?>
<?php
// Use the URL 'id' variable to set who we want to query info about
$id = preg_replace("[^0-9]", "", $_GET['id']); // filter everything but numbers for security
if ($id == "") {
echo "Missing Data to Run";
exit();
}
//Connect to the database through our include
include_once "config/connect.php";
// Query member data from the database and ready it for display
$sql = "SELECT * FROM members WHERE id='$id' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$count = mysqli_num_rows($query);
if ($count > 1) {
echo "There is no user with that id here.";
exit();
}
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$username = $row["username"];
$_SESSION['username'] = $username;
$userid = $row["id"];
$_SESSION['id'] = $userid;
// Convert the sign up date to be more readable by humans
$signupdate = strftime("%b %d, %Y", strtotime($row['signupdate']));
}
?>
and this is the logout.php file:
<?php
session_start();
session_destroy();
if( isset($_SESSION['id'])){
header("location: index.php");
} else {
exit('<h2>Could not log you out, sorry the system encountered an error.</h2>');
}
?>
<html>
<body>
<?php echo "$msg"; ?><br>
<p><a href="index.php">Click here</a> to return to our home page </p>
</body>
</html>
any help would be appreciated.