NickG21 Posted December 28, 2006 Share Posted December 28, 2006 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]<?phpfunction 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 Quote Link to comment Share on other sites More sharing options...
taith Posted December 28, 2006 Share Posted December 28, 2006 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] Quote Link to comment Share on other sites More sharing options...
NickG21 Posted December 28, 2006 Author Share Posted December 28, 2006 where in my code would i call that function? where i have the elseif of count and i call the header? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 28, 2006 Share Posted December 28, 2006 is that the full code for contactUs.php? It doesnt look like it. Also do you get any other errors/messages too? NickG21If it is add ob_start() at the start of the script (after <?php) and ob_end_flush() before (?>) Quote Link to comment Share on other sites More sharing options...
taith Posted December 28, 2006 Share Posted December 28, 2006 it really doesnt matter where you put functions... as long as they're there[code]<?phpfunction 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.