Jump to content

ob_start() clears all my $_POST vars


Yesideez

Recommended Posts

ob_start has nothing to do with the receipt of external data. It's more likely you have invalid HTML that is preventing the form from working.

 

In any case, you would need to post your form and your form processing code for anyone to be able to tell you anything about what your code is doing or not doing.

 

Why are you using ob_start anyway, it's likely masking errors in your logic that are preventing it from working correctly in the first place.

It's strange that when ob_start() is removed it works perfectly fine and when I add it, it fails.

 

This is the page with the submit button (in this case a login script)

<?php
/* File   : admin/index.php
** Created: 17-Apr-2009 (Ivan Rood)
** Edited : N/A
********************************************************************/
require('config.php');
$strMsg='Please login';
$strUsername=(isset($_POST['username']) ? $_POST['username'] : '');
$strPassword=(isset($_POST['password']) ? $_POST['password'] : '');
$strCaptcha=(isset($_POST['captcha']) ? $_POST['captcha'] : '');
if (isset($_POST['sublogin'])) {
  if (isset($_SESSION['vercode']) && $_SESSION['vercode']==sha1($strCaptcha)) {
    if ($strUsername==$prefs->username && sha1($strPassword)==$prefs->password) {
      $prefs->saveSession();
      $_SESSION['loggedin']=true;
      header('Location: home.php');
      exit;
    } else {
      $strMsg='Invalid username/password';
    }
  } else {
    $strMsg='Invalid security code';
  }
}
?>
<html>
<?php include('html_head.php'); ?>
<body>
<?php include('html_header.php'); ?>
<p class="spacer"> </p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" cellspacing="0" class="boxinfo">
  <tr><td colspan="2" align="center"><strong><?php echo $strMsg; ?></strong></td></tr>
  <tr><td>Username</td><td><input type="text" name="username" maxlength="20" class="gadstr"></td></tr>
  <tr><td>Password</td><td><input type="password" name="password" class="gadstr"></td></tr>
  <tr><td colspan="2" align="center"><img src="../makeimg.php?i=<?php echo mt_rand(1000,9999); ?>" alt="" width="130" height="34" style="margin-bottom: 2px"><br><input type="text" name="captcha" size="6" maxlength="6" class="gadstr captcha"></td></tr>
  <tr><td colspan="2" align="center"><input type="submit" name="sublogin" value="Login" class="gadbut"></td></tr>
</table>
</form>
<p class="spacer"> </p>
<?php include('html_footer.php'); ?>
</body>
</html>

 

Here is the content of config.php:

<?php
session_start();
//if (isset($_POST['sublogin'])) {echo 'Yes';} else {echo 'No';}
//ob_start();
$basedir=dirname(__FILE__);
require($basedir.'/../config.php');
require($basedir.'/../siteprep.php');
?>

 

If I uncomment the if() statement it works and it says "Yes". If I then uncomment the ob_start() it fails and says "Yes" still.

The symptoms you are getting are indicative of a page being requested twice or an include/require being included/required more than once. Either your browser is requesting the page more than once, you have a url rewrite that is causing the page to be requested more than once, you have an include/require that in being included/required more than once, or you have a redirect that is causing the page to be re-requested.

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.