sicawebd Posted February 23, 2013 Share Posted February 23, 2013 Hi, Ive recently started up my own small business doing web design for personal wedding invites. Im still quite new at everything, however now that i’ve got my first website invite up and running the contact form doesnt seem to work, i got this form from a tutorial I did when i was first started learning dreamweaver so i cant pick up where i’ve gone wrong. When i click send it comes up with a white screen with the error "Parse error: syntax error, unexpected T_STRING in /home/content/43/10414143/html/form.php on line 22" html is as follows: <div id="rsvp-form-2"> <form class="required-form" action="form.php" method="post"><ol class="forms"> <li><label for="rsvp">Yes / No</label><input type="text" name="rsvp" id="name" /></li> <li><label for="name">Name</label><input type="text" name="name" id="name" /></li> <li><label for="name">Guest Name</label><input type="text" name="name" id="name" /></li> <li><label for="email">Email</label><input type="text" name="email" id="email" /></li> <li><label for="phone">Phone</label><input type="text" name="phone" id="phone" /></li> <li><label for="message">Message</label><textarea name="message" id="message"></textarea></li> <li class="buttons"><button type="submit" style="background: none; border: 0px;"><img src="Images/RSVP/send.gif" /></button></li> <li class="buttons submit"><input type="submit" value="submit" /></li> <li class="buttons reset"><input type="reset" value="reset" /></li> </ol> </form> </div> I also have a validate.js and css with the following script in my header: <script type="text/javascript"> $(document).ready(function() { $('form.required-form').simpleValidate({ errorElement: 'em' }); }); </script> and php is as follows: <?php // This work is licensed under the MIT License - http://www.opensource.org/licenses/mit-license.php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = "rsvp@claireanddane.com"; // $yourWebsite = "http://www.claireanddane.com"; // $thanksPage = 'thanks.html'; // $maxPoints = 4; // $error_msg = null; $result = null; function isBot() { $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot"); $isBot = false; foreach ($bots as $bot) if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) $isBot = true; if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") $isBot = true; exit("Bots not allowed.</p>"); } if ($_SERVER['REQUEST_METHOD'] == "POST") { function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } $points = (int)0; $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "fuck", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur"); $exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); foreach ($badwords as $word) if (strpos($_POST['comments'], $word) !== false) $points += 2; foreach ($exploits as $exploit) if (strpos($_POST['comments'], $exploit) !== false) $points += 2; if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false) $points += 2; if (isset($_POST['nojs'])) $points += 1; if (preg_match("/(<.*>)/i", $_POST['comments'])) $points += 2; if (strlen($_POST['name']) < 3) $points += 1; if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) $points += 2; foreach ($_POST as $key => $value) $_POST[$key] = trim($value); if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) { $error_msg .= "Name, e-mail and comments are required fields. \n"; } elseif (strlen($_POST['name']) > 15) { $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; } elseif (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) { $error_msg .= "That is not a valid e-mail address. \n"; } elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(\d+))?\/?/i', $_POST['url'])) $error_msg .= "Invalid website url."; if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Automatic Form Email"; $message = "You received this e-mail message through your website: \n\n"; foreach ($_POST as $key => $val) { $message .= ucwords($key) . ": " . clean($val) . "\r\n"; } $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n"; $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n"; $message .= 'Points: '.$points; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: $yourEmail \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } else { $headers = "From: $yourWebsite <$yourEmail> \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } if (mail($yourEmail,$subject,$message,$headers)) { if (!empty($thanksPage)) { header("Location: $thanksPage"); exit; } else { $result = 'Your mail was successfully sent.'; } } else { $error_msg = 'Your mail could not be sent this time.'; } } else { if (empty($error_msg)) $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']'; } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } ?> website for reference is http://www.claireanddane.com Any advice would be appreciated as i’ve tried everything! Jessica Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 (edited) What line of code corresponds to line 22? And is there a reason you're not using curly braces? Edited February 23, 2013 by denno020 Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 23, 2013 Author Share Posted February 23, 2013 The error refers to: if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) also where should be curly braces be used? Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 (edited) Personally, I would always use curlry braces for if, foreach, switch etc statements.. So in your case: foreach ($bots as $bot){ if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false){ $isBot = true; } } This way there is no guessing as to what code belongs in which block etc.. Give that a try and see if the error message moves to another line lower down. Denno Edited February 23, 2013 by denno020 Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 23, 2013 Author Share Posted February 23, 2013 Ok thanks for the quick reply. I’ve updated this region but its still coming up an error. Any idea as to where from here? Jessica Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 (edited) Is the error still in the exact same place? Also, do a var_dump of $_SERVER to ensure that the array key is actually there Edited February 23, 2013 by denno020 Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 23, 2013 Author Share Posted February 23, 2013 Yes still at line 22. Ah sorry i’m a complete beginner with php so not sure what you mean by var_dump. could you please put in steps what i need to do? Thanks Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 (edited) var_dump($_SERVER); Oh hold on.. perhaps you can do this instead: foreach ($bots as $bot){ if (in_array($_SERVER['HTTP_USER_AGENT'], $bot)) { $isBot = true } } That will search the array $bots with the value of HTTP_USER_AGENT Edited February 23, 2013 by denno020 Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 23, 2013 Author Share Posted February 23, 2013 It still came up error at line 22. If i do the var_dump where do i put this code? Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 Put it on the line directly before the foreach, which would correspond to around line 19.. I hope this isn't rude, but why did you start up a business doing web design if you don't actually know how to do it? Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 var_dump($_SERVER); Oh hold on.. perhaps you can do this instead: foreach ($bots as $bot){ if (in_array($_SERVER['HTTP_USER_AGENT'], $bot)) { $isBot = true } } That will search the array $bots with the value of HTTP_USER_AGENT Apologies, I have steered you wrong with this code, it should have been if (in_array($_SERVER['HTTP_USER_AGENT'], $bots)) { $isBot = true } Quote Link to comment Share on other sites More sharing options...
DavidAM Posted February 23, 2013 Share Posted February 23, 2013 "Parse error: syntax error, unexpected T_STRING in /home/content/43/10414143/html/form.php on line 22" Is the PHP you showed above the file named in that error message? I did not get a Parse error when I tried that code. Note: The in_array code will NOT produce the same results as the strpos code. The original code is searching the entire UA for the existence of any of the bot strings anywhere in the UA. The in_array() code is only checking to see if the UA is exactly equal to one of the bot strings. It's a mute point, because 1) that function is not called in the code provided; and 2) that function will always execute the exit("Bots not allowed.</p>"); line whether it finds a bot string or not! Show us the form.php file, or check line 22 of that file yourself. That is where the problem lies. Oh, and use tags, it makes the code easier to read. Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 23, 2013 Share Posted February 23, 2013 Note: The in_array code will NOT produce the same results as the strpos code. The original code is searching the entire UA for the existence of any of the bot strings anywhere in the UA. The in_array() code is only checking to see if the UA is exactly equal to one of the bot strings. You are very right. My apologies Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 24, 2013 Author Share Posted February 24, 2013 (edited) Yes it is that file. i’ve tried it again this morning with the original form.php file i used (which is same as below) and its now coming up just a blank screen with no errors. <?php // This work is licensed under the MIT License - http://www.opensourc...mit-license.php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = "rsvp@claireanddane.com"; //$yourWebsite = "http://www.claireanddane.com"; //$thanksPage = 'thanks.html'; //$maxPoints = 4; // $error_msg = null;$result = null; function isBot() {$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot"); $isBot = false;foreach ($bots as $bot)if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)$isBot = true; if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")$isBot = true; exit("Bots not allowed.</p>");} if ($_SERVER['REQUEST_METHOD'] == "POST") {function clean($data) {$data = trim(stripslashes(strip_tags($data)));return $data;} $points = (int)0; $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "fuck", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur");$exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); foreach ($badwords as $word)if (strpos($_POST['comments'], $word) !== false)$points += 2; foreach ($exploits as $exploit)if (strpos($_POST['comments'], $exploit) !== false)$points += 2; if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)$points += 2;if (isset($_POST['nojs']))$points += 1;if (preg_match("/(<.*>)/i", $_POST['comments']))$points += 2;if (strlen($_POST['name']) < 3)$points += 1;if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))$points += 2; foreach ($_POST as $key => $value)$_POST[$key] = trim($value); if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) {$error_msg .= "Name, e-mail and comments are required fields. \n";} elseif (strlen($_POST['name']) > 15) {$error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n";} elseif (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) {$error_msg .= "The name field must not contain special characters. \n";} elseif (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) {$error_msg .= "That is not a valid e-mail address. \n";} elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(\d+))?\/?/i', $_POST['url']))$error_msg .= "Invalid website url."; if ($error_msg == NULL && $points <= $maxPoints) {$subject = "Automatic Form Email"; $message = "You received this e-mail message through your website: \n\n";foreach ($_POST as $key => $val) {$message .= ucwords($key) . ": " . clean($val) . "\r\n";}$message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";$message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";$message .= 'Points: '.$points; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {$headers = "From: $yourEmail \r\n";$headers .= "Reply-To: {$_POST['email']}";} else {$headers = "From: $yourWebsite <$yourEmail> \r\n";$headers .= "Reply-To: {$_POST['email']}";} if (mail($yourEmail,$subject,$message,$headers)) {if (!empty($thanksPage)) {header("Location: $thanksPage");exit;} else {$result = 'Your mail was successfully sent.';}} else {$error_msg = 'Your mail could not be sent this time.';}} else {if (empty($error_msg))$error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';}}function get_data($var) {if (isset($_POST[$var]))echo htmlspecialchars($_POST[$var]);}?> Edited February 24, 2013 by sicawebd Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 24, 2013 Author Share Posted February 24, 2013 (edited) Edited February 24, 2013 by sicawebd Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 24, 2013 Share Posted February 24, 2013 You could probably ask the person who wrote the script, they'd have a better understanding of what's trying to be achieved here. It's most likely something simple like a missing curly brace or a misspelt variable or something, but I can't really see it.. Quote Link to comment Share on other sites More sharing options...
sicawebd Posted February 24, 2013 Author Share Posted February 24, 2013 yeah that thought crossed my mind this morning. will ask him if i can. thanks for your help though Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 24, 2013 Share Posted February 24, 2013 Make sure that error_reporting is set to E_ALL or -1 and display_errors is set to ON 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.