Web Site Adresine Erişim Kontrol Sınıfı

PHP
38 lines
<?php
class adresTest{
var $vektor = array();
function __construct($time){
set_time_limit($time);
}
function ekle($adres){
$this->vektor[] = $adres;
}
function listele(){
$list = $this->vektor;
for($i = 0; $i < count($list);$i++){
$this->test($list[$i]);
}
}
function test($adres) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $adres);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(parse_url($adres, PHP_URL_SCHEME) == "https"){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
$cikti = curl_exec($ch);
$bilgi = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$hatalar = array("0","400", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "411", "412", "413", "414", "415", "500", "501", "502", "503", "504", "505");
if(in_array($bilgi, $hatalar)) {
echo "<a href=\"".$adres."\" target=\"_blank\">".$adres."</a> <b>($bilgi) Sayfaya Erişilemiyor!</b><br />";
}else{
echo "<a href=\"".$adres."\" target=\"_blank\">".$adres."</a> <b>($bilgi) Geçerli Sayfa.</b><br />";
}
curl_close($ch);
}
}
$test = new adresTest(0);
$test->ekle('http://www.google.com.tr');
$test->ekle('https://www.ulusanyazilim.com/feed');
$test->listele();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
2 lines
http://www.google.com.tr (200) Geçerli Sayfa.
https://www.ulusanyazilim.com/feed (301) Geçerli Sayfa.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Özel Adres Sınıfı

PHP
47 lines
<?php
error_reporting(63);
class ozelAdres {
var $anahtarlar= array();
var $taban = '';
function ozelAdres($taban='') {
$this->taban = $taban;
}
function anahtarAyarla($isim='',$deger='') {
if ($isim) {
$this->anahtarlar[$isim] = $deger;
}
}
function anahtarBirak($isim='') {
if ($isim) {
unset($this->anahtarlar[$isim]);
}
}
function tabanAyarla($deger) {
$this->taban = $deger;
}
function anahtarAl($isim) {
return $this->anahtarlar[$isim];
}
function dize() {
$r = $this->taban;
if (count($this->anahtarlar)>0) $r .= '?';
$tarr = array();
foreach ($this->anahtarlar as $anahtar=>$deger) {
$u[] = $anahtar.'='.(urlencode($deger));
}
$r .= implode('&',$u);
return $r;
}
function kodla($isim='') {
return "<a href=\"".$this->dize()."\">$isim</a>";
}
}
$url = new ozelAdres($_SERVER['PHP_SELF']);
$url->anahtarAyarla('par1','Test');
$url->anahtarAyarla('par2',2);
echo $url->dize()."<br>";
echo $url->kodla('test')."<br>";
$url->anahtarBirak('par1');
echo $url->dize()."<br>";
echo "'par2' degeri ".$url->anahtarAl('par2')."<br>";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
4 lines
/index.php?par1=Test&par2=2
<a href="/index.php?par1=Test&par2=2">test</a>
/index.php?par2=2
'par2' degeri 2
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Adresten Alan Adı Almak

PHP
13 lines
<?php
function urltemizle($url){
$domain=strtolower($url);
$domain= preg_replace(array('~^https?://~si' ,'~[/:#?;%&].*~','~.$~',),'',$domain);
if(preg_match('#^www.(.*)#i',$domain)){$domain=preg_replace('#www.#i','',$domain);}
$domain="http://".$domain;
return $domain;
}
echo urltemizle("http://phpstate.ulusanyazilim.com/index.php");
//Çıktısı phpstate.ulusanyazilim.com
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX