If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.
Post a reply to the thread: Can someone help me with these PHP Scripts?
Click here to log in
What is the number after 87?
You may choose an icon for your message from this list
Will turn www.example.com into [URL]http://www.example.com[/URL].
You may rate this thread from 1-star (Terrible) to 5-stars (Excellent) if you wish to do so.
Can someone help me with these PHP Scripts? I am taking an intro PHP class, and for an assignment I have to create a form that will email what is input to me, and it has to be password protected, after they submit the comments I want a thank you page to appear. So far I have worked on the first two pages. The first page is the secure login, the second page is the email form. The secure login works but when I hit submit I get an error. Any help is GREATLY appreciated. Hopefully I will get the hang of this PHP stuff eventually. emailprotected.php (Secure Login) : <?php // this is false until a successful login $login_worked = false; // get user info if the form is submitted if ($_SERVER['REQUEST_METHOD']=="POST") { // "usernames" => "passwords", as many as you like... $userpass = array ( "photographer" => "focus", "designer" => "focus", "other" => "focus" ); $u = $_POST['username']; $p = $_POST['password']; } // checks if $userpass has been set as an array // login is true if there is a match between the associated key and value if (is_array($userpass) && $userpass[$u] == $p) { $login_worked = true; } if ($login_worked == true) { //set the login session variables, uname and logged session_start(); $_SESSION['uname'] = $u; $_SESSION['logged'] = true; // setcookies if (isset($_POST['saved']) && $_POST['saved'] == "yes") { setcookie("checked", “yes”, time()+86400*31); setcookie("name", $u, time()+86400*31); setcookie("pass", $p, time()+86400*31); } else { // remove cookies by setting expiration to time in the past setcookie("checked", "", time()-1000); setcookie("name", "", time()-1000); setcookie("pass", "", time()-1000); } // send the successfully logged on visitor on their way... header("Location:emailprotected.php"); exit; } else { // show form if $login_worked is false ?> <div id="loginForm" style="position:absolute; left:657px; top:434px; width:371px; height:162px; z-index:1"> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="login" id="login"> <table width="100%" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="24%" class="login">UserName</td> <td width="76%"><input name="username" type="text" id="username" value="<?php echo $_COOKIE['name'];?>"></td> </tr> <tr> <td>Password</td> <td><input name="password" type="password" id="password" value="<?php echo (isset($_COOKIE['pass'])) ? $_COOKIE['pass'] : "";?>"></td> </tr> <tr> <td>*</td> <td><input type="submit" name="Submit" value="Submit"><input type="reset" name="Reset" value="Clear"></td> </tr> <tr> <td align="right"> <input name="saved" type="checkbox" id="saved" value="yes" <?php echo (!(strcmp($_COOKIE['checked'],"yes"))) ? "checked" : ""; ?>> </td> <td> <p>Remember me!</p> </td> </tr> </table> </form> <p>*</p> </div> </body> </html> <?php } // close "else" conditional ?> emailArray.php (Email Form) <?php session_start(); $goodUser = $_SESSION['uname']; // if any of the following are true, visitor sent to login if (empty($goodUser) || !isset($_SESSION['logged']) || $_SESSION['logged'] != true) { // re-directs to login page header("emailprotected.php"); exit; } // page loads if login was successful! ?> <html> <head> <title>This is a Password-Protected PHP Page {P:P:P:P}</title> </head> <body> <div id="header" style="position:absolute; left:614px; top:299px; width:378px; height:56px; z-index:2"> <h1 class="welcome"> <form action="handle_form.php" method="post"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="name" size="20" /></p> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send My Feedback" /> </form> </div> </body> </html>
Can someone help me with these PHP Scripts?
Forum Rules