(I known that there is a thread on sessions right below thus, I've already read through it.)
Hello,
I've been working on a very basic PHP login script using a MySQL database to store the username and password. Everything works fine, except that the session won't ever start. Everything else works exactly as intended, except the session will never register.
The login script is for a very light mockup of an admin center that I am doing to teach myself more about PHP in general.
This is the main page for the admin center (index.php). It is supposed to check to see if $_SESSION['login'] has a value, and if it does, it prints the area where the admin center will be. $_SESSION['login'] does not have a value, it prints the login form.
This is the script that the form in .templates/login.php links to. It handles the login process. The file .templates/login.php is just HTML, and is a bit long, so I didn't bother posting it.
When I login wrong, it displays everything properly. When I login correctly, it redirects to index.php, but without setting the session. This causes it to show the login screen over and over again.
Any help would be greatly appreciated. Thanks!
Hello,
I've been working on a very basic PHP login script using a MySQL database to store the username and password. Everything works fine, except that the session won't ever start. Everything else works exactly as intended, except the session will never register.
The login script is for a very light mockup of an admin center that I am doing to teach myself more about PHP in general.
This is the main page for the admin center (index.php). It is supposed to check to see if $_SESSION['login'] has a value, and if it does, it prints the area where the admin center will be. $_SESSION['login'] does not have a value, it prints the login form.
Code:
<?php
if (!isset($_SESSION['login'])) {
include './templates/login.php';
}
else {
echo 'This is where the admin center would be if I bothered to make one';
}
?>
This is the script that the form in .templates/login.php links to. It handles the login process. The file .templates/login.php is just HTML, and is a bit long, so I didn't bother posting it.
Code:
<?php
include '../config/connect_info.php';
include '../config/mysql_connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM admin WHERE glogin='$username' AND gpassword = '$password'";
$result=mysql_fetch_array(mysql_query($query));
if ($result) {
session_start();
$_SESSION['login']=1;
echo 'Login success. You will now be redirected to the admin cp.<br><br>
Browser not redirecting? <a href="index.php">Click here.</a>';
echo " <script>
self.location='index.php';
</script>";
}
else {
echo 'Login unsuccessful. <br><br>
Username and password did not match. <br><br>
<a href="index.php">Click here to go back</a>';
}
include '../config/mysql_close.php';
?>
When I login wrong, it displays everything properly. When I login correctly, it redirects to index.php, but without setting the session. This causes it to show the login screen over and over again.
Any help would be greatly appreciated. Thanks!