technokid88
Part of a System
- Joined
- 15 Feb 2006
- Messages
- 741
I'm trying to put a php script to block content on a page, unless you put in your registered user name and password. I have it where if a person comes to this page they get message that says you are not logged in, and a link to log in. This will happen to ever page i put this code in to. What i want is after they get this message and log in i want them to go to the page with the blocked page logged in and want it to be displayed. Any help would be much appreciated. Thanks
This is the login.php code below.
Code:
<?php
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href=login1.php>click here</a> to login.");
echo "You are logged in $username";
?>
Code:
<?php
ob_start();
include("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$match = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";
$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows <= 0) {
echo "Sorry, there is no username or password with: <strong>".$_POST['username']."</strong><br>";
echo "<a href=login1.php>Try again</a>";
exit;
} else {
setcookie("loggedin", "".$_POST['username']."", time()+(3600 * 24));
setcookie("username", "".$_POST['username']."", "TRUE");
echo "Welcome: <strong>".$_POST['username']."</strong><br>";
echo "Continue to the <a href=members.php>Listing you were looking at.</a> section.";
}
ob_end_flush();
?>
Last edited: