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