snaketooth22 Posted June 9, 2013 Posted June 9, 2013 Im getting an error on this line in the checkem.php ,.. ive fixed the rest so that its compatible with the new versions of the PHP on the servers,. I just cant figure out what im doing wrong on this line,.. can anyone help please :) ,.. if (!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { (ERROR CODE): Warning: preg_match() [function.preg-match]: Unknown modifier '=' in /home4/jedigunz/public_html/checkem.php on line 13 Quote
Octarine Posted June 9, 2013 Posted June 9, 2013 Yet again, the error message makes it obvious: ` Unknown modifier '=' ` You cannot use the primary delimiters, in this case / within the expression itself. Anything after the second one is assumed to be a modifier.. in this case '=' if (!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { At a guess I'd say your expression needs simplifying - [!-~]{1,63} perhaps -- just make sure you escape it (mysql_real_escape_string etc) going into the database and escape it (htmlentities etc) going out to the screen. Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 could you re-write me the code im a bit confused,.. and ive been up all night getting the website together,.. would be much appreciated :) Quote
Guest Posted June 9, 2013 Posted June 9, 2013 Going by what Octarine said it should be if(!preg_match("/[!-~]{1,63}/")) Though I suck at regex so trust him :). Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 its worth a try :) ,.. octarine lost me on escaping it though Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 speaking to yuh in the IRC yuh now know its an email thing,. Octarine where abouts do yuh mean to put that small peice of code,.. do yuh mean to replace a specific part of the code that already exists ?? Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 and Ian i know what yuh mean i dont get this **** either,. regex yuh said,. never even heard off it before,.. never seen it in a piece of script like this in my life lool Quote
Guest Posted June 9, 2013 Posted June 9, 2013 speaking to yuh in the IRC yuh now know its an email thing,. Octarine where abouts do yuh mean to put that small peice of code,.. do yuh mean to replace a specific part of the code that already exists ?? I do now, so use what Nick said filter_var() Quote
Dominion Posted June 9, 2013 Posted June 9, 2013 its worth a try :) ,.. octarine lost me on escaping it though http://uk3.php.net/mysql_real_escape_string If you're checking an E-mail (as Ian said) FILTER_VALIDATE_EMAIL - http://uk3.php.net/filter_var Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 (edited) http://uk3.php.net/mysql_real_escape_string If you're checking an E-mail (as Ian said) FILTER_VALIDATE_EMAIL - http://uk3.php.net/filter_var i cant place what i need to change,.. all it is is one line of code,. which needs a minor edit,. let me show yuh the script and what ive done,.. Everything in bold italics is what ive changed / added ,.. i originally had 5 errors on the register page in the email to be classed as real section ,.. what i done eliminated 4 of the errors but there is still 1 error remaining on line 13,.. Originally there was ereg instead of preg_match and i added /// in places where i was supposedly meant to according to every website ive googled,. Warning: preg_match() [function.preg-match]: Unknown modifier '=' in /home4/jedigunz/public_html/checkem.php on line 13 <?php //thx to http://www.phpit.net/code/valid-email/ for valid_email function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { return false; } } if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) { return false; } } } return true; } include "config.php"; global $_CONFIG; define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; if(!$_GET['password']) { die("<font color='red'>Invalid - Blank</font>"); } if(!valid_email($_GET['password'])) { die("<font color='red'>Invalid - Bad Format</font>"); } $un=$_GET['password']; $q=$db->query("SELECT * FROM users WHERE email='$un'"); if($db->num_rows($q)) { die("<font color='red'>Invalid - Already In Use</font>"); } print "<font color='green'>Valid</font>"; ?> and the original is :: <?php //thx to http://www.phpit.net/code/valid-email/ for valid_email function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } include "config.php"; global $_CONFIG; define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; if(!$_GET['password']) { die("<font color='red'>Invalid - Blank</font>"); } if(!valid_email($_GET['password'])) { die("<font color='red'>Invalid - Bad Format</font>"); } $un=$_GET['password']; $q=$db->query("SELECT * FROM users WHERE email='$un'"); if($db->num_rows($q)) { die("<font color='red'>Invalid - Already In Use</font>"); } print "<font color='green'>Valid</font>"; ?> Edited June 9, 2013 by snaketooth22 Quote
Guest Posted June 9, 2013 Posted June 9, 2013 You don't need valid_email PHP already has one built in filter_var($var, FILTER_VALIDATE_EMAIL) Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 where does it have that mate ??,.. am i missing something ??, .. plus i want it to show in the register page so the user knows what they are entering is valid like it does or used to in every mccode V2 script Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 You don't need valid_email PHP already has one built in filter_var($var, FILTER_VALIDATE_EMAIL) where does it have that mate ??,.. am i missing something ??, .. plus i want it to show in the register page so the user knows what they are entering is valid like it does or used to in every mccode V2 script Quote
KyleMassacre Posted June 9, 2013 Posted June 9, 2013 Take all this //thx to http://www.phpit.net/code/valid-email/ for valid_email function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { return false; } } if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) { return false; } } } return true; } and do this: function valid_email($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return false; return true; } Quote
Nickson Posted June 9, 2013 Posted June 9, 2013 Why not simply this?: function valid_email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) } Will return if the email is not valid, and will return the email if it passes the validation. Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 function valid_email($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return false; return true; } Oh my god it was that simple,.. haaha ,. thanks alot for that,,.. ill remember that in future :) Quote
KyleMassacre Posted June 9, 2013 Posted June 9, 2013 Oh my god it was that simple,.. haaha ,. thanks alot for that,,.. ill remember that in future :) For a lot of things, just remember not everything filter_var() and filter_input() can be a really great friend of yours. It has quite a bit of nice features like defaults if the input returns false or even other settings like what you want to allow or not. Quote
snaketooth22 Posted June 9, 2013 Author Posted June 9, 2013 For a lot of things, just remember not everything filter_var() and filter_input() can be a really great friend of yours. It has quite a bit of nice features like defaults if the input returns false or even other settings like what you want to allow or not. yeah the updated version compared to the original is so much more easier to understand and know what its doing,. that original one was just madness Quote
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.