Jump to content

php $_POST['varname'] does not work in any php page


mikehershey

Recommended Posts

Hi,

My php _POST variable is not working. I have Apache2 AND tomcat could that be causing interference . Here is an example script to make sure im not missing something stupid.

	<?
session_start();
require_once("db.php");
echo print_r($_POST);;
if(isset($_POST['username']) && isset($_POST['password']))
	{
	$con = mysql_connect("localhost",$username,$password);
	if(!(mysql_select_db($database))) die("Server Error");
	$result = mysql_query("SELECT * FROM logins WHERE user='".mysql_escape_string($_POST['username'])."' AND pass='".md5(mysql_escape_string($_POST['password']))."'");
	if(mysql_num_rows($result)==1)
		{
		$title= "logged in";
		$_SESSION['user']=$_POST['username'];		
		header ("Location: index.php");
		}
	else 
		{
		$title ="Username/Password combination is invalid";
		}
	mysql_close($con);
	}
else
	{
	$title="You need to log in to use this service";
	}
?>
<html>
<head>
	<title>Log in</title>
</head>
<body>
	<div style="margin-left:auto;margin-right:auto;width:350px;">
		<?=$title?>
		<form action="login.php" method="post">
			<p>Username:<input name="username" type="text" maxlength="15"></p>
			<p>Password:<input name="password" type="password" maxlength="15"></p>
			<input type="submit">
		</form>
	</div>
</body>
</html>

put this at the top of your script for a test:

 

if(isset($_POST['password'])){

  echo 'PW is set: '.$_POST['password'];

  }else{echo 'PW not set!';}

echo '<br />';

if(isset($_POST['username'])){

  echo 'USERNAME is set: '.$_POST['username'];

  }else{echo 'USERNAME not set!';}

I changed the tags and it made no difference the script executes fine and the output for the printr $_POST is always Array ( ) 1  even when I submit the form. I noticed the double ;; after the printr but that shouldnt matter in the code because it is just executing nothing after printing, and i fixed the typo now (problem still exists).

form is in the source code above

<form action="login.php" method="post">
            <p>Username:<input name="username" type="text" maxlength="15"></p>
            <p>Password:<input name="password" type="password" maxlength="15"></p>
            <input type="submit">
         </form>

I had the script working properly on two servers, so i'm pretty sure its a configuration problem. I had the script working properly on this server but then in php.ini i raised the max file upload size and the max post variable upload size. When i did this on other servers the script continued to work. On this on the script stopped working. The two differences between this server and the other 2 are this one has mod_jk and the Suhosin-Patch installed. I think that the Suhosin-Patch might be blocking the post variables. Is this possible?

Ok i think it was the patch i changed php.ini back down to a lower value and everything started working (except for large file transfer which is why i changed it to begin with) it worked on the other server so i'm concluding that it must be the stupid Suhosin-Patch. Thanks for replying everyone. If have any idea how to edit the Suhosin-Patch so i can upload large files that would be awesome.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.