PHP Help Please
Posted: Thu May 07, 2015 2:05 pm
Im having a problem once I login to my account its ment to redirect to the index page once logged in and when I redirect to the index page the links for login and register are ment to not display and its ment to show logged in. Can anyone help me please?
login page code.
login page code.
Code: Select all
functions.php code<?php include('styles/top.php'); ?>
<?php
include 'connect.php';
include 'functions.php';
?>
<div id="left">
<form method="post">
<?php
if(isset($_POST['login_button'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) or empty($password)){
echo "The username or Password field was empty please try again!.";
} else {
$query = mysql_query("SELECT id FROM users WHERE username='$username' AND password='$password'");
$run = mysql_fetch_array($query);
$id = $run['id'];
if (!empty($id)){
$_SESSION['user_id'] = $id;
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
} else {
echo "Wrong Username or Password was entered.";
}
}
}
?>
<table cellspacing="20">
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td><input type="submit" name="login_button" value="Login" /></td>
</tr>
</table>
</form>
</div>
<div id="right">
</div>
<?php include('styles/bottom.php'); ?>
Code: Select all
index.php code<?php
session_start();
function loggedin(){
if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])){
return true;
} else {
return false;
}
}
?>
Code: Select all
<?php include('styles/top.php'); ?>
<?php
include 'connect.php';
include 'functions.php';
?>
<div id="left">
</div>
<div id="right">
<?php
if(loggedin()){
echo "Logged in ! <a href=logout.php>Logout</a>";
} else {
?>
<a href="login.php">Login</a> | <a href="register.php">Register</a>
<?php
}
?>
</div>
<?php include('styles/bottom.php'); ?>