ollie123 Posted March 15, 2008 Share Posted March 15, 2008 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 More sharing options...
derrick1123 Posted March 15, 2008 Share Posted March 15, 2008 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 https://forums.phpfreaks.com/topic/96265-please-tell-me-why-this-code-wont-work/#findComment-492772 Share on other sites More sharing options...
JD* Posted March 16, 2008 Share Posted March 16, 2008 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 https://forums.phpfreaks.com/topic/96265-please-tell-me-why-this-code-wont-work/#findComment-493199 Share on other sites More sharing options...
sasa Posted March 16, 2008 Share Posted March 16, 2008 2nd one in function gotoURL change + to .(header("Location: " . $url) Link to comment https://forums.phpfreaks.com/topic/96265-please-tell-me-why-this-code-wont-work/#findComment-493234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.