I tested this code with Apache/Win32, PHP 5, worked fabulous, uploaded it to a server (helping a friend out with school) and it doesnt work there.
I am sure I did it right (especially since it worked for me).
It is written very basic (newbie to PHP wrote it) I am just helping figure out what is happening.
<?php
require "connect.inc.php"; // The SQL Connection works perfectly.. no need to show.
db_connect("database");
session_start(); // Start the session
$user = $_REQUEST['username']; // Get what they entered for user / pass
$pass = $_REQUEST['password'];
$query = "SELECT * from useraccess WHERE username = '$user' ";
$result = mysql_query($query);
if (mysql_num_rows($result) < 1) { // If the username does not exist;
echo "You have entered an invalid username and/or password. Please <a href=\"index.html\">Try Again</a>.";
} else {
while ($row = mysql_fetch_object($result)) {
$db_pass = $row->password;
$acslevel = $row->acslevel;
}
if ($pass == $db_pass) {
$validated = 1;
} else {
echo "You have entered an invalid username and/or password. Please <a href=\"index.html\">Try Again</a>."; }
}
if ($validated == 1) {
$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;
$_SESSION['acslevel'] = $acslevel;
echo "Thank you for logging in, <a href=\"custome_e.php\">Continue</a>";
}
?>
Then the file custome_e.php:
<?php
// Start Session; Get User / Password / Access Variables.
session_start();
$user = $_SESSION['username'];
$pass = $_SESSION['password'];
$acslevel = $_SESSION['acslevel'];
echo "Hello $user. Your Options are below. $acslevel $pass";
if ($acslevel >= 10) {
echo "You are an Administrator, you may delete or edit customer records.<br>";
} else {
echo " You must be an administrator in order to change/delete customers You may ADD, or VIEW customers.<br>";
}
?>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="show_records.php">Show Customers </a></div></td>
</tr>
<tr>
<td><div align="center"><a href="add_record.php">Add New Customer </a></div></td>
</tr>
<?php
if ($acslevel >= 10) {
?>
<tr>
<td><div align="center"><a href="delete_record.php">Delete Customer </a></div></td>
</tr>
<tr>
<td><div align="center"><a href="edit_records.php">Edit Customers </a></div></td>
</tr>
<?php
}
?>
The problem is, on my system it worked great, on the system it was uploaded to it wont accept the SESSION data on the 2nd file. If I (from the login.php file) echo $_SESSION['username']; after initializing it, it will echo perfectly.
As soon as it gets to the second file it can't seem to get the data.
I believe it to be a server problem, however it is a server that is setup for the school, where they instructed to use sessions.
I just want to make sure there is no coding errors... I know its basic, it sorta needs to stay that way.
thanks in advance...