191 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+4 more
themac says

@SplitV, for my example the var_dump doesn’t have the big advatage to echo

echo $sql = "bla";
is faster than
$sql = "bla";
var_dump($sql);
or
var_dump($sql = "bla");

my example only shows the possibilities of the = Operator – you could allocate values or variables to variables and the = returns values too, that’s the reason for the functioning of

$var1 = $var2 = "hello world";
and
echo $var1 = "hello world";

bye
mac

17 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
darawebdesign says

Anyone got tips on sanitizing inputs?

443 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
SplitV says

There is an article on Tut+ http://net.tutsplus.com/tutorials/php/getting-clean-with-php/

For earlier versions of php here are a few examples of things to use in validation and sanitation.

Validation….....

is_float

is_numeric

is_int

function is_bool($input)l{
return (in_array(strtolower($data), array(TRUE,FALSE,1,0)) ? 1 : 0;
}

function valid_email ($address) {
        return (preg_match('/^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$/', $address));
}
///Checks if the username contains any characters other then 0-9, letters, _,-,|,~,+,*
function valid_username($username) {
        return preg_match('/^[0-9a-zA-Z\s\_\-\|\~\+]+$/',$username);
}

Sanitation….......
////Sanitize int
function getInt($input){
        return intval($input); 
}
///Sanitize unsigned int
function getUInt($input){
        if(intval($input)<0){
            return 0;
        }
        else{
            return intval($input);
        }    
}

///Sanitize Number 
function getNumber($input){
        return strval($input)+0; 
}

///Sanitize Usigned Number 
function getUNumber($input){
        if((strval($input)+0)<0){
            return 0;
        }
        else{
            return strval($input)+0;
        }    
}

///Sanitize String
function getStr($input){
             return  trim(strval($input));
}
///Sanitize String NO TRIM
function getStrNoTrim($input){
             return  strval($input);
}
///Sanitize String NO HTML
function getNoHtml($input){
            return htmlspecialchars_uni(trim(strval($input)));
}
639 posts
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
Crakken says
Wow, I don’t know why this stopped but something in my mind told me that I shall continue this. Here’s a simple trick I’ve been using on all my projects:
Instead of using regex (regular expression) to make sure a string is an email, use filter_var, it’s much easier:
if (filter_var("insert email here", FILTER_VALIDATE_EMAIL)) {
    // Do something if it's an email   
        } else {
   // Do something else if it's not
}

Replace “insert email here” with the email address, it can be a variable too.
So, if you are like me, if you don’t like regex, this can be useful.
I will post a PHP tip/trick here everyweek or any day I get the time.

973 posts
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
aaranmcguire says

Wow, I don’t know why this stopped but something in my mind told me that I shall continue this. Here’s a simple trick I’ve been using on all my projects:
Instead of using regex (regular expression) to make sure a string is an email, use filter_var, it’s much easier:
if (filter_var("insert email here", FILTER_VALIDATE_EMAIL)) {
    // Do something if it's an email   
        } else {
   // Do something else if it's not
}
Replace “insert email here” with the email address, it can be a variable too.
So, if you are like me, if you don’t like regex, this can be useful.
I will post a PHP tip/trick here everyweek or any day I get the time.

I got one up…

function validEmail($email){
    if (filter_var($email, FILTER_VALIDATE_EMAIL)){
        list($user,$domain) = explode('@',$email);
        return checkdnsrr($domain, 'MX');
    } 
    return false;
}

This way if i type hfisjf@fnisdsi.com it will return false.

176 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in Australia
+2 more
michaeldale says


Wow, I don’t know why this stopped but something in my mind told me that I shall continue this. Here’s a simple trick I’ve been using on all my projects:
Instead of using regex (regular expression) to make sure a string is an email, use filter_var, it’s much easier:
if (filter_var("insert email here", FILTER_VALIDATE_EMAIL)) {
    // Do something if it's an email   
        } else {
   // Do something else if it's not
}
Replace “insert email here” with the email address, it can be a variable too.
So, if you are like me, if you don’t like regex, this can be useful.
I will post a PHP tip/trick here everyweek or any day I get the time.

I got one up…

function validEmail($email){
    if (filter_var($email, FILTER_VALIDATE_EMAIL)){
        list($user,$domain) = explode('@',$email);
        return checkdnsrr($domain, 'MX');
    } 
    return false;
}
This way if i type hfisjf@fnisdsi.com it will return false.

Nice idea. But email can still work without an MX record. Email servers will fall back to the root A record if there is no MX record. So this might cause issues

973 posts
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
aaranmcguire says

Nice idea. But email can still work without an MX record. Email servers will fall back to the root A record if there is no MX record. So this might cause issues

True, but I dont think thats done often… but still it would save the junk domains… because people are now smart enough to know how email addresses are formatted and people know you usually need to type a email for it to submit correctly.

639 posts
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
Crakken says


Nice idea. But email can still work without an MX record. Email servers will fall back to the root A record if there is no MX record. So this might cause issues
True, but I dont think thats done often… but still it would save the junk domains… because people are now smart enough to know how email addresses are formatted and people know you usually need to type a email for it to submit correctly.

Yeah, that was great. Thanks :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by