بررسی صحت وجود ایمیل؛لینک و تصویر در اینترنت - Ghoghnus - 02-03-2012
چند نمونه از بهترین کدهای PHP جهت بررسی وجود لینک ها؛عکس ها و آدرس های ایمیل را بصورت توابع آماده کرده ایم که مطمئنا برای دوستان مفید خواهد بود ...
۱-بررسی وجود یک تصویر در وب سایت دیگر:
کد پیاچپی: $external_link = 'www.example.com/example.jpg'; if (@GetImageSize($external_link) ) { echo "image exists"; } else { echo "image does not exist"; }
**
کد پیاچپی: function checkRemoteFile($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); // don't download content curl_setopt($ch, CURLOPT_NOBODY, ۱); curl_setopt($ch, CURLOPT_FAILONERROR, ۱); curl_setopt($ch, CURLOPT_RETURNTRANSFER, ۱); if(curl_exec($ch)!==FALSE) { return true; } else { return false; } }
کد پیاچپی: **
function url_exists($url) { if(@file_get_contents($url,۰,N ULL,۰,۱)) {return ۱;} else { return ۰;} }
[
۲-بررسی وجود یک URL
کد پیاچپی: function url_exists($url){ if(strstr($url, "")) $url = str_replace("", "", $url); $fp = @fsockopen($url, ۸۰); if($fp === false) return false; return true; }
**
کد پیاچپی: function url_exists($url){ if ((strpos($url, "http")) === false) $url = "" . $url; if (is_array(@get_headers($url))) return true; else return false; }
**
کد پیاچپی: function is_valid_url($url) { $url = @parse_url($url); if (!$url) { return false; } $url = array_map('trim', $url); $url['port'] = (!isset($url['port'])) ? ۸۰ : (int)$url['port']; $path = (isset($url['path'])) ? $url['path'] : ''; if ($path == '') { $path = '/'; } $path .= (isset($url['query'])) ? "?$url[query]" : ''; if (isset($url['host']) AND $url['host'] != gethostbyname($url['host'])) { if (PHP_VERSION >= ۵) { $headers = get_headers("$url[scheme]:// $url[host]:$url[port]$path"); } else { $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, ۳۰); if (!$fp) { return false; } fputs($fp, "HEAD $path HTTP/۱.۱\r\nHost: $url[host]\r\n\r\n"); $headers = fread($fp, ۴۰۹۶); fclose($fp); } $headers = (is_array($headers)) ? implode("\n", $headers) : $headers; return (bool)preg_match('#^HTTP/.*\ s+[(۲۰۰|۳۰۱|۳۰۲)]+\s#i', $headers); } return false; }
کد پیاچپی: **
function image_exist($url) { if (@fclose(@fopen( $url, "r"))) { // true; } else { // false; } }
۳-بررسی صحت وجود یک آدرس ایمیل
کد پیاچپی: function email_exist($email) { list($userid, $domain) = split("@", $email); if (checkdnsrr($domain, "MX")) { return true;} else { return false;} }
کد پیاچپی: if(! function_exists('checkdnsrr')) function checkdnsrr($hostName, $recType = '') { if(!empty($hostName)) { if( $recType == '' ) $recType = "MX"; exec("nslookup -type=$recType $hostName", $result); // check each line to find the one that starts with the host // name. If it exists then the function succeeded. foreach ($result as $line) { if(eregi("^$hostName",$line)) { return true; } } // otherwise there was no mail handler for the domain return false; } return false; }
**
کد پیاچپی: function check_email($email) { $email_error = false; $Email = htmlspecialchars(stripslashes( strip_tags(trim($email)))); //parse unnecessary characters to prevent exploits if ($Email == "") { email_error = true; } elseif (!eregi("^([a-zA-Z۰-۹._-]) +@([a-zA-Z۰-۹._-])+\.([a-zA-Z۰-۹._-])([a-zA-Z۰-۹._-])+", $Email)) { email_error = true; } else { list($Email, $domain) = split("@", $Email, ۲); if (! checkdnsrr($domain, "MX")) { email_error = true; } else { $array = array($Email, $domain); $Email = implode("@", $array); } } if (email_error) { return false; } else{return true;} }
**
کد پیاچپی: function check_email($email) { $email_error = false; $Email = htmlspecialchars(stripslashes( strip_tags(trim($email)))); //parse unnecessary characters to prevent exploits if ($Email == "") { email_error = true; } elseif (!eregi("^([a-zA-Z۰-۹._-]) +@([a-zA-Z۰-۹._-])+\.([a-zA-Z۰-۹._-])([a-zA-Z۰-۹._-])+", $Email)) { email_error = true; } else { list($Email, $domain) = split("@", $Email, ۲); if (! checkdnsrr($domain, "MX")) { email_error = true; } else { $array = array($Email, $domain); $Email = implode("@", $array); } } if (email_error) { return false; } else{return true;} } function EmailValidation($email) { if (check_email($email)) { $domain = explode( "@", $email ); if ( @fsockopen ($domain[۱] ,۸۰,$errno,$errstr,۳)) { $code = "here we place a secret key with the email address: $email"; mail($email, "Your Verification Code", "Please click the following URL to verify your email:\n\n ". $_SERVER['PHP_SELF']."/? v=$code&email=$email","From: \"example\" <example@example.com>"); echo "Your account needs to be verify. We have send you an email, click the link provided and you are verified."; return true; } else { return false; //if a connection cannot be established return false } } else { return false; //if email address is an invalid format return false } } function EmailForm(){ if(empty($_POST['email'])){ echo "<form action=".$_SERVER['PHP_SELF'] ." method='post'> <table border='۰'> <tr> <td>Email</td> <td><input name='email' type='text' id='email' /></td> </tr> <tr> <td> </td> <td><input type='submit' name='Submit' value='Validate' /></td> </tr> </table> </form>"; } elseif(isset($_POST['email'])) { if(EmailValidation($_POST['ema il'])) { echo "An email has been sent to you. Please follow the instructions to activate your account."; } else { echo "Your email address appears to be invalid. Please try again."; } }else elseif(isset($_GET['v']) && isset($_GET['email'])) { $clean['emai'] = $_GET['email']; //need to ....... these data to be clean $clean['v'] = $_GET['v']; //need to ....... these data to be clean $code = "here we place a secret key with the email address: $email"; $code = md۵($code); if ($clean['v'] != $code) { echo "The Verification Code is invalid. Please Try Again."; exit(۰); }else echo "The email ".$clean['emai']." has been verified"; }else { echo "An error has occured, please contact the administrator."; } } EmailForm();
|