Jump to content

[SOLVED] header error


NickG21

Recommended Posts

good day to you all, below i have my php code for a form validation and i am getting an error even after all the information is accepted and i try to direct to a thanks.php page.  the code was working earlier today and i haven't made any modifications to the header area, only to other parts.  anyone have any idea what this might be caused by?

Error:
[code]Warning: Cannot modify header information - headers already sent by (output started at /home/web/www.netatlantic.com/test/nickgirard/ContactUs.php:2) in /.../ContactUs.php on line 69[/code]

Code:
[code]<?php
function checkEmail($email)
{
  if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
  {
      return FALSE;
  }
  list($Username, $Domain) = split("@",$email);
  if(getmxrr($Domain, $MXHost))
  {
      return TRUE;
  }
  else
  {
      if(@fsockopen($Domain, 25, $errno, $errstr, 15))
      {
        return TRUE;
      }
      else
      {
        return FALSE;
      }
  }
}
if (isset($_POST['submit'])) {
$company = $_POST['CompanyName'];
$name = $_POST['YourName'];
$email = $_POST['YourEmailAddress'];
$domainName = $_POST['ListOrDomainName'];
$username = $_POST['Username'];
$password = $_POST['Password'];
$error = array();

if (empty($company))
{
$error[] = "Comapny";
}
if (empty($name))
{
$error[] = "Your Name";
}
elseif (!preg_match("/^([a-zA-Z])+/",$name))
{
  $error[] = "Your Name";
  $name="";
}

if(checkEmail($email) == FALSE)
{
  $error[]="E-Mail Address";
  $email = "";
}
if(empty($username))
{
$error[] = "User Name";
}
if(empty($password))
{
$error[]="Password";
}
elseif (strlen($password) < 6)
{
$error[]= "Password Must Contain At Least Six Characters";
}
if (count($error)>0) {
    echo"<big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br />', $error). "</p>";
    } elseif (count($error) <=0) {
header('Location: ./Thanks.php');
    exit;
  }
}
?>
[/code]

thank you in advance for any and all help
Link to comment
https://forums.phpfreaks.com/topic/32070-solved-header-error/
Share on other sites

do yourself a major favor... dont use header(); use this...

[code]
<?
function redirect($filename=".?op=main",$delay="0",$die="0"){
if((!headers_sent())&&($delay=="0")) header('Location: '.$filename);
elseif($delay=="0"){
  echo '<script type="text/javascript">';
  echo 'window.location.href="'.$filename.'";';
  echo '</script>';
  echo '<noscript>';
  echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
  echo '<noscript>';
}else echo '<meta http-equiv="refresh" content="'.$delay.';url='.$filename.'" />';
if($die=="0") exit;
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32070-solved-header-error/#findComment-148850
Share on other sites

it really doesnt matter where you put functions... as long as they're there
[code]
<?php
function checkEmail($email){
if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) return FALSE;
list($Username, $Domain) = split("@",$email);
if(getmxrr($Domain, $MXHost)) return TRUE;
else{
  if(@fsockopen($Domain, 25, $errno, $errstr, 15)) return TRUE;
  else return FALSE;
}
}

function redirect($filename=".?op=main",$delay="0",$die="0"){
if((!headers_sent())&&($delay=="0")) header('Location: '.$filename);
elseif($delay=="0"){
  echo '<script type="text/javascript">';
  echo 'window.location.href="'.$filename.'";';
  echo '</script>';
  echo '<noscript>';
  echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
  echo '<noscript>';
}else echo '<meta http-equiv="refresh" content="'.$delay.';url='.$filename.'" />';
if($die=="0") exit;
}

if(isset($_POST['submit'])){
$company = $_POST['CompanyName'];
$name = $_POST['YourName'];
$email = $_POST['YourEmailAddress'];
$domainName = $_POST['ListOrDomainName'];
$username = $_POST['Username'];
$password = $_POST['Password'];
$error = array();
if(empty($company)) $error[] = "Comapny";
if(empty($name)) $error[] = "Your Name";
elseif(!preg_match("/^([a-zA-Z])+/",$name)){
  $error[] = "Your Name";
  $name="";
}
if(checkEmail($email) == FALSE){
  $error[]="E-Mail Address";
  $email = "";
}
if(empty($username)) $error[] = "User Name";
if(empty($password)) $error[]="Password";
elseif(strlen($password) < 6) $error[]= "Password Must Contain At Least Six Characters";
if(count($error)>0) echo"<big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br />', $error);
else redirect('./Thanks.php');
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32070-solved-header-error/#findComment-148885
Share on other sites

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.