Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/44349-solved-having-a-problem-with-my-code/
Share on other sites

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.

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

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

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);

}
?>

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.