logo

PHP Link Kontrol Etme

logo

Aşağıdaki fonksiyon ile php ile bir linkin gerçek bir link olup olmadığını kontrol edebilirsiniz, fonksiyon, link geçerli bir link ise true, değilse false değeri döndürecektir.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
 
function is_valid_url ( $url )
{
		$url = @parse_url($url);
 
		if ( ! $url) {
			return false;
		}
 
		$url = array_map('trim', $url);
		$url['port'] = (!isset($url['port'])) ? 80 : (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 >= 5 )
			{
				$headers = get_headers("$url[scheme]://$url[host]:$url[port]$path");
			}
			else
			{
				$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
 
				if ( ! $fp )
				{
					return false;
				}
				fputs($fp, "HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n");
				$headers = fread ( $fp, 128 );
				fclose ( $fp );
			}
			$headers = ( is_array ( $headers ) ) ? implode ( "\n", $headers ) : $headers;
			return ( bool ) preg_match ( '#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers );
		}
		return false;
}
 
$linkler=array ("http://www.site.com","http://www.site.com/","www.site.com","site.com","https://www.site.com","https://www.site.com/","ftp://site.com","ftp://site.com/"); //kontrol için linkleri arka arkaya dizdik
 
	foreach ($linkler as $kontrol) { // teker teker tüm linkleri kontrol edelim şimdi
	echo is_valid_url($kontrol)?strip_tags($kontrol)." geçerli bir linktir":strip_tags($kontrol)." geçerli bir link değildir";
	echo "<br />";
	}
 
?>

kaynak: roscripts

VN:F [1.9.3_1094]
Rating: 4.0/10 (2 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
PHP Link Kontrol Etme, 4.0 out of 10 based on 2 ratings
  • teşekkürler paylaşım için
  • SoulSmasher
    We're excited to let you know that Arda Kilicdagi has invited you to Dropbox!

    Arda Kilicdagi has been using Dropbox to sync and share files online and across computers, and thought you might want it too.

    Visit http://www.dropbox.com/link/20.veR7tUP3HF/NjIxO... to get started.

    - The Dropbox Team

    ____________________________________________________
    To stop receiving invites from Dropbox, please go to http://www.dropbox.com/bl/86eb7e173af7/notifica...
  • Kardeş çalışmıyor ; kodda urller dışında değişiklik yapmadım lütfen cevabı maille atar mısınız ?
  • SoulSmasher
    Hostinginizde yabancı sitelerden URL çekme açık olmalıdır (allow_url_fopen)
  • işime yaradı; izninizle fonksiyon kütüphaneme alıyorum. teşekkürler
  • SoulSmasher
    We're excited to let you know that Arda Kilicdagi has invited you to Dropbox!

    Arda Kilicdagi has been using Dropbox to sync and share files online and across computers, and thought you might want it too.

    Visit http://www.dropbox.com/link/20.sn8CuNTIz4/NjIxO... to get started.

    - The Dropbox Team

    ____________________________________________________
    To stop receiving invites from Dropbox, please go to http://www.dropbox.com/bl/8a21ad980f0a/notifica...
  • admin
    @kadir - rica ederim :)
  • Bu kodların çok işime yaradı.tşk.ler abi. :)
  • teşekkürler soul :)
  • admin
    rica ederim ;)
blog comments powered by Disqus
logo
logo
Powered by Wordpress | Designed by Elegant Themes