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
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.

Link to comment
Share on other sites

The major problem I see is that welcome.php does not have a <? session_start(); ?> at the very top....every page that will reference a session needs to have that as the first thing on the page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.