• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[php] Password Help

technokid88

Part of a System
#1
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

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";
?>
This is the login.php code below.

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:

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies