i need to allow a user to post only if their logged in. i have login.htm form with session feedback processing the request. but i dont know how to restrict acess to the post.htm form. here my code.
<?php
session_start();
ini_set('arg_separator.output',';');
$con = mysql_connect("host","database","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
// process log in form
if (isset($_POST['login'])){
if (!empty($_POST['user'])){
$user = $_POST['user'];
}
if (!empty($_POST['password'])){
$password = $_POST['password'];
}
// query whether there is a user with $usr for username and $pwd for password in the users database
$result = mysql_query("SELECT * FROM users WHERE user = '$user'");
while($row = mysql_fetch_array($result))
{
$password = $row['password'];
$user = $row['user'];
}
if($user){
if($password != 'Password'){
if ( $_POST['password'] == "$password"){
$_SESSION['user'] = $_POST['user'];
setcookie("user", $user, time()+3600);
}
}
}
mysql_close($con);
}
// log out
if (isset($_GET['logout'])){
unset($_SESSION['user']);
session_destroy();
setcookie("user", "", time()-3600);
}
header( 'Location:
http://www.etc.com. ) ;header to post.htm
?>