Nice tut.
With aloha,
Ben Hughes.

Nice tut.
With aloha,
Ben Hughes.
Ben Hughes
Currently Researching ...
My posts: 5 ... 10 ... 15 ... 20 ... 25 ... 30 ... 35 ... 40 ... 45 ... 50
As pointed out, if you use cookies they can easily be forged. I would use PHP sessions because they are server side so no one can edid/forge them. So the code for login.php would be;
Then for any pages you want to be protected add this to the top;PHP Code:<?php
session_start()
if ($_SERVER['REQUEST_METHOD']=="POST"){
// Get UserNames and Passwords.
$Logi = file("users/log.txt");
// Work out how many there are
$size = sizeof($Logi);
// Break appart passwords and usernames
foreach($Logi as $Key => $Val)
{ $Data[$Key] = explode("||", $Val); }
// run threw list and see if any match
for($K = 0; $K<$size; $K++)
{
$user = $Data[$K][0];
$pass = $Data[$K][1];
// If match set cookie and redirect.
if ($user == trim(addslashes($_POST["user"])) && $pass == trim(addslashes($_POST["pass"])) )
{
$_SESSION['username'] = addslashes ( $user );
$_SESSION['password'] = addslashes ( md5 ( $pass ) );
// Start hidden page
header("Location: http://website.com/hidden.php");
}
}
echo "Login Failed.";
// If you didnt log in show login form
} else { ?>
<div style="width:250px">
<div><strong>Simple Login</strong></div>
<div><form name="Login" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
Username:
<input name="user" type="text" >
<br>
Password:
<input name="pass" type="password" >
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</div></div>
<?php
}
?>
PHP Code:<?php
session_start();
if ( !isset ( $_SESSION['username'] ) || !isset ( $_SESSION['username'] ) ) {
die ( "You need to login to view this page" );
}
?>
Signature Removed by Jamesy (Forum Super Moderator): Referal
For pages that only users can view once logged in why not just do.
PHP Code:<?php
session_start();
include 'config.php';
if($logged[id] {
echo 'blah blah blah';
} else {
echo 'You need to log in to view that sir!';
}
}
?>
Excellent, where is $logged defined? As its not in any part of the tutorial..? Do you know what that code actually does? lol.
But they'd know how to set up MySQL queries, get the results of the query, etc? :S (Which is what I assumed $logged would be - the result of a mysql query).
For multi user login it would be much easier if they just zapped it from a query as you said.
Then all they have to do is grab it from a config file and use $logged[id] and can pretty much use that for everything.PHP Code:$logged = mysql_query("SELECT * FROM `members` WHERE `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");
$fetchA = mysql_fetch_array($logged);
But this tutorial is all about flat-files and the code you posted would use $fetchA not $logged for the if statement in your previous post -.-
Want to hide these adverts? Register an account for free!