Jump to content

Please tell me why this code won't work!


ollie123

Recommended Posts

Im only a newb at PHP scripting, and I want to make a site for my friends. The first page requires you to enter a password (the password is 'havealaugh' ) which is sent to a PHP script which verifies the password, and redirects the user regarding the the password. The problem is that when I submit the password from the first page, it sends it to the verifier script, but the verifier does nothing! This is the contents of the script:

<?php 
session_start();
function gotoURL($url) {
header("Location: " + $url);
}
function verifyPass($pwd) {
$correct = "d86fc0e3acdaa15b9f760fd3e2fa10d9";
$current = md5($pwd);
if($current == $correct)
{
	$_SESSION["auth"] = true;
	gotoURL("welcome.php");
	exit();
}
}
verifyPass($_POST["password"]);
?>

 

This is the content of welcome.php (if you need it)

<?php 
if(!isset($_SESSION["auth"]) || $_SESSION["auth"] != true)
{
die("Auth error! Bog Off!");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>

<body>
Hello, This is a test!
</body>
</html>

 

Please help me!

 

Thanks

Ollie M

Link to comment
https://forums.phpfreaks.com/topic/96265-please-tell-me-why-this-code-wont-work/
Share on other sites

This is probably a simpler way to do this...but probably not as safe in fact nothing is truly safe.:

<?php
$code = $_POST['code']; // must have this so it will let u enter the page after you enter your password
$password = "havealaugh"; //this is were you enter the password you want to use for ppl to enter ur site


if($code!="$password"){     //checks for password...
echo "You must login first using the password.

<form action='".$_SERVER['PHP_SELF']."' method='post'>
Passowrd: <input type='password' name='code' size='30'> <input type='submit' value='Go'>
</form>";

} else {

//your site here

}
?>

 

I didn't test this so If something doesn't work please tell me so I can fix.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.