Lethal.Liquid Posted March 26, 2007 Share Posted March 26, 2007 <?php $pass = "SOMEPASSWORD"; 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.php" enctype="multipart/form-data"> <input type="file" name="file" id="file"> <input type="submit" name="submit" value="Upload!"> </form> </BODY> </HEAD> </HTML> <?php } elseif($_COOKIE['user'] != "admin" || $_COOKIE['pass'] != md5($pass)) { ?> <form name="login" method="POST" action="upload_login.php"> <input type="text" name="user"><br /> <input type="password" name="pass"><br /> <input type="submit" name="submit" value="submit"><br /> </form> <?php } elseif(isset($_POST['login'])) { $user = $_POST['user']; $pass = md5($_POST['pass']); setcookie("user", $user, 0); setcookie("pass", $pass, 0); header("Location: upload.php"); } ?> This all works fine until the last isset, I always have problems with this and have never bothered to ask 'til now. Anyone know how to fix it? Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/ Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 elseif(isset($_POST['submit'])) { $user = $_POST['user']; $pass = md5($_POST['pass']); setcookie("user", $user, 0); setcookie("pass", $pass, 0); header("Location: upload.php"); } The actual form does not get sent in post data, only members of that form. Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/#findComment-215382 Share on other sites More sharing options...
MadTechie Posted March 26, 2007 Share Posted March 26, 2007 whats the problem ? elseif(isset($_POST['login'])) { switch to elseif(isset($_POST['user'])) { <form method="POST" action="upload_php.php" enctype="multipart/form-data"> yet header("Location: upload.php"); Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/#findComment-215383 Share on other sites More sharing options...
Lethal.Liquid Posted March 26, 2007 Author Share Posted March 26, 2007 the header and the different thing i forgot to change, because one of my solutions was to just use another file, but that file didnt verify...thanks, that fixes my prob Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/#findComment-215388 Share on other sites More sharing options...
Lethal.Liquid Posted March 26, 2007 Author Share Posted March 26, 2007 Okay, with this I was able to combin all three codes and it looks like this: <?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("SOMEPWD")) { 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, 0); setcookie("pass", $pass, 0); } ?> It all works great until the last elseif, it just won't set the cookies. Some help again? Thanks, Lethal.Liquid Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/#findComment-215394 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Are you on localhost or a server. Also you are setting the time to 0, try doing this instead: setcookie("user", $user, time()+3600*24); setcookie("pass", $pass, time()+3600*24); http://us2.php.net/manual/en/function.setcookie.php Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/#findComment-215398 Share on other sites More sharing options...
Lethal.Liquid Posted March 26, 2007 Author Share Posted March 26, 2007 Same problem...I'm using cPanel to edit my stuff, so I guess a server. And 0 is supposed to be a browser session, so it doesn't end until the browser closes. This worked before I combined the three. My code now looks like this: <?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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/#findComment-215409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.