hej
jeg er igang med at lave en hjemmeside, hvor der skal være en login side.
Denne side skal sende brugeren videre til en bestem side fx billedbank.php.
Jeg har brugt noget kode jeg har fundet på nettet, men jeg kan ikke helt
finde ud af, hvoordan jeg undgår, at folk bare kan komme ind på
billedbank.php, bare ved at skrive det direkte i adresselinjen.
Her er koden til loginsiden, men der skal vel være et eller andet på
billedbank.php, som tjekker at man er kommet fra den side?
<?php
$goHere="album/index.php"; // Page to send successfull log-ins to
$logSuccess="1"; // Track / log successful log-ins (1 = yes
and 0 = no)
$namePassCombos = array ( // Add as many lines as you like below
"name1" => "flip", // Add username and password combo here
"name2" => "pass2", // Add username and password combo here
"name3" => "pass3" // Add username and password combo here
);
// Multiple user Log-In script by Dave Lauderdale - Originally published
at:
www.digi-dl.com
// The below code may or may not be necessary for you
$loginName = $_POST['loginName']; $passWord = $_POST['passWord'];
// Replace bad characters in user input
$passWord = preg_replace ("/</","[",$passWord); $loginName = preg_replace
("/>/","]",$loginName);
$loginName = str_replace(".."," ",$loginName); $passWord =
str_replace(".."," ",$passWord);
// Trim whitespace from user input
$loginName=trim($loginName); $passWord=trim($passWord);
// If log-in was successfull
$logInTracker="successLog.txt";
function success($logSuccess,$logInTracker,$loginName,$goHere)
{
$date=date ("l dS of F Y h:i:s A");
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $ip = getenv(REMOTE_ADDR);
else $ip = $_SERVER['REMOTE_ADDR'];
// If webmaster wants to log successful logins
if($logSuccess=="1"){
$log=fopen("files/$logInTracker", "a+");
fputs($log, "$loginName logged in on: $date - Logged IP address:
$ip\n");
fclose($log);
}
// If no log or after log then go here
Header("Location: $goHere");
}
// If there is an error
function error($notice)
{
// Display error notice (0)
if($notice=="0"){
echo"
<title>Login fejl: Manglende navn / password</title>
<body><br><p style=\"font:11pt arial\"><font color=red>NOTICE:</font>
Login fejl: Manglende navn / password.
<br><br><br>Klik <a href=\"javascript:history.back(1)\"
style=\"color:black\">her</a> for at prøve igen.
</body></html>
"; exit;
}
// Display error notice (1)
if($notice=="1"){
echo"
<title>Login fejl: Ugyldigt navn / password</title>
<body><br><p style=\"font:11pt arial\"><font color=red>NOTICE:</font>
Login fejl: Ugyldigt navn / password.
<br><br><br>Klik <a href=\"javascript:history.back(1)\"
style=\"color:black\">her</a> for at prøve igen.
</body></html>
"; exit;
}
}
// If the user doesnt enter a name or password then set error notice to 0
and display error
if (($loginName == "") || ($passWord == "")) { $notice=0; error($notice); }
// If the username and password entered don't match then set error notice
to 1 and display error
else if (strcmp($namePassCombos[$loginName],$passWord) != 0) { $notice=1;
error($notice); }
// If the log in was sucessful
else if (strcmp($namePassCombos[$loginName],$passWord) == 0) {
success($logSuccess,$logInTracker,$loginName,$goHere); }
?>