Lethal.Liquid Posted March 26, 2007 Share Posted March 26, 2007 So I fixed up my code some more, and started helping some others, my topic has been answered for what I asked for. Here is my new code, and it just won't set these cookies. I tried to eat them, but that didn't work either... <?php $pass = "SOMEPWD"; if($_COOKIE['user'] == "admin" && $_COOKIE['pass'] == md5($pass)) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE> Upload a File! </TITLE> </HEAD> <BODY> <form method="POST" action="upload.php" enctype="multipart/form-data"> <input type="file" name="file" id="file"> <input type="submit" name="submit1" value="Upload!"> </form> <?php if(isset($_POST['submit1'])) { if($_COOKIE['user'] == "admin" && $_COOKIE['pass'] == md5($pass)) { if($_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/pjepg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/gif") { if($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } elseif(file_exists("upload/" . $_FILES["file"]["name"])) { echo "This file already exists!"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . $_FILES["file"]["size"] . "<br />"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored In: " . "upload/" . $_FILES["file"]["name"]; } } else { echo "Bad file type!"; } } else { echo "You went through the trouble of making your own form...and what did you get? Nothing!!!!"; } } ?> </BODY> </HEAD> </HTML> <?php } elseif($_COOKIE['user'] != "admin" || $_COOKIE['pass'] != md5($pass)) { ?> <form name="login" method="POST" action="upload.php"> <input type="text" name="user"><br /> <input type="password" name="pass"><br /> <input type="submit" name="submit2" value="submit"><br /> </form> <?php } elseif(isset($_POST['submit2'])) { $user = $_POST['user']; $pass = md5($_POST['pass']); setcookie("user", $user, time()+3600*24); setcookie("pass", $pass, time()+3600*24); } ?> Thanks in Advance, Lethal.Liquid Link to comment https://forums.phpfreaks.com/topic/44358-new-problem/ Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Are you sure it is entering the elseif? I would print out a statement to make sure. Looking this seems wrong: elseif($_COOKIE['user'] != "admin" || $_COOKIE['pass'] != md5($pass)) A better way would be: elseif((isset($_COOKIE['user']) && ($_COOKIE['user'] != "admin" || $_COOKIE['pass'] != md5($pass)))) If the user cookie isset than check the admin and password. But yea throw a print statement inside the submit2 isset if and see what happens. Link to comment https://forums.phpfreaks.com/topic/44358-new-problem/#findComment-215458 Share on other sites More sharing options...
Lethal.Liquid Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks, that new elseif worked! Link to comment https://forums.phpfreaks.com/topic/44358-new-problem/#findComment-215482 Share on other sites More sharing options...
Lethal.Liquid Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks, that new elseif worked! Or...did...it stopped working...here's my code: <?php $pass = "SOMEPWD"; if($_COOKIE['user'] == "admin" && $_COOKIE['pass'] == md5($pass)) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE> Upload a File! </TITLE> </HEAD> <BODY> <form method="POST" action="upload.php" enctype="multipart/form-data"> <input type="file" name="file" id="file"> <input type="submit" name="submit1" value="Upload!"> </form> <?php if(isset($_POST['submit1'])) { if($_COOKIE['user'] == "admin" && $_COOKIE['pass'] == md5($pass)) { if($_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/pjepg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/gif") { if($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } elseif(file_exists("upload/" . $_FILES["file"]["name"])) { echo "This file already exists!"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . $_FILES["file"]["size"] . "<br />"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored In: " . "upload/" . $_FILES["file"]["name"]; } } else { echo "Bad file type!"; } } else { echo "You went through the trouble of making your own form...and what did you get? Nothing!!!!"; } } ?> </BODY> </HEAD> </HTML> <?php } elseif((isset($_COOKIE['user']) && ($_COOKIE['user'] != "admin" || $_COOKIE['pass'] != md5($pass)))) { ?> <form name="login" method="POST" action="upload.php"> <input type="text" name="user"><br /> <input type="password" name="pass"><br /> <input type="submit" name="submit2" value="submit"><br /> </form> <?php } elseif(isset($_POST['submit2'])) { $user = $_POST['user']; $pass = md5($_POST['pass']); setcookie("user", $user, time()+3600*24); setcookie("pass", $pass, time()+3600*24); } ?> This is my first time doing a login...so yea... Thanks in Advance, Lethal.Liquid P.S. You were right, it doesnt go into that last elseif for some reason. Link to comment https://forums.phpfreaks.com/topic/44358-new-problem/#findComment-215492 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 I would put the login check in a separate function if it were me. IE: <?php function checkLogin($pass) { if (isset($_COOKIE['user']) && isset($_COOKIE['pass'])) { if ($_COOKIE['user'] == "admin") { if ($_COOKIE['pass'] == md5($pass)) { return true; } } } return false; } $pass = "SOMEPWD"; if(checkLogin($pass)) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE> Upload a File! </TITLE> </HEAD> <BODY> <form method="POST" action="upload.php" enctype="multipart/form-data"> <input type="file" name="file" id="file"> <input type="submit" name="submit1" value="Upload!"> </form> <?php if(isset($_POST['submit1'])) { if(checkLogin($pass)) { if($_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/pjepg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/gif") { if($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } elseif(file_exists("upload/" . $_FILES["file"]["name"])) { echo "This file already exists!"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . $_FILES["file"]["size"] . "<br />"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored In: " . "upload/" . $_FILES["file"]["name"]; } } else { echo "Bad file type!"; } } else { echo "You went through the trouble of making your own form...and what did you get? Nothing!!!!"; } } ?> </BODY> </HEAD> </HTML> <?php } elseif(checkLogin($pass)) { ?> <form name="login" method="POST" action="upload.php"> <input type="text" name="user"><br /> <input type="password" name="pass"><br /> <input type="submit" name="submit2" value="submit"><br /> </form> <?php } elseif(isset($_POST['submit2'])) { $user = $_POST['user']; $pass = md5($_POST['pass']); setcookie("user", $user, time()+3600*24); setcookie("pass", $pass, time()+3600*24); } ?> That will limit the chance of error. Link to comment https://forums.phpfreaks.com/topic/44358-new-problem/#findComment-215510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.