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>

Link to comment
Share on other sites

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!';}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.