Geri git   Van.GEN.TR Forum | Yerel Van Forumu > Bilgisayar > Programlama > PHP

Cevapla
 
Konu Araçları Stil
Alt 25/06/07, 16:26   #1
LastDesiqner
Super Moderator
 
LastDesiqner - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Jan 2007
Bulunduğu yer: ναη
Mesajlar: 8.132
Tecrübe Puanı: 56 LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute LastDesiqner has a reputation beyond repute
Thumbs up Zararli HTML kodlarini temizleme sinifi

Zararli HTML kodlarini temizleme sinifi

--------------------------------------------------------------------------------

PHP- Kodu:
<?php 
 
/** @class: InputFilter; 
* @project: Filter User Input Source; 
* @date: 18-03-2005; 
* @version: 1.1.1_php5; 
* @author: Daniel Morris; 
* @copyright: Daniel Morris; 
* @email: dan@rootcube.com; 
* @license: GNU General Public License (GPL); 
*/ 
class InputFilter 
// class config vars 
private $tagsArray// required 
private $attrArray// default = empty array 
private $tagsMethod// default = 0 
private $attrMethod// default = 0 
 
/** 
* Constructor for inputFilter class. Only first parameter is required. 
* @access constructor 
* @param Array $tagsArray - list of user-defined tags 
* @param Array $attrArray - list of user-defined attributes 
* @param int $tagsMethod - 0= allow just user-defined, 1= allow all but user-defined 
* @param int $attrMethod - 0= allow just user-defined, 1= allow all but user-defined 
*/ 
public function __construct($tagsArray$attrArray = array(), $tagsMethod 0$attrMethod 0) { 
$this->tagsArray $tagsArray
$this->attrArray $attrArray
$this->tagsMethod $tagsMethod
$this->attrMethod $attrMethod

 
/** 
* Method to be called by another php script. 
* @access public 
* @param Mixed $source - input string/array-of-string to be 'cleaned' 
* @return String $source - 'cleaned' version of input parameter 
*/ 
public function process($source) { 
if (
is_array($source)) { // clean all elements in this array 
for ($i 0$i count($source); $i++) 
if (
is_string($source[$i])) $source[$i] = $this->remove($source[$i]); 
return 
$source
} else if (
is_string($source)) return $this->remove($source); // clean this string 
else return $source// return parameter as given 

 
/** 
* Internal method to iteratively remove all unwanted tags and attributes 
* @access private 
* @param String $source - input string to be 'cleaned' 
* @return String $source - 'cleaned' version of input parameter 
*/ 
private function remove($source) { 
$loopCounter=0
// provides nested-tag protection 
while($source != $this->filterTags($source)) { 
$source $this->filterTags($source); 
$loopCounter++; 

return 
$source

/** 
* Internal method to strip a string of certain tags 
* @access private 
* @param String $source - input string to be 'cleaned' 
* @return String $source - 'cleaned' version of input parameter 
*/ 
private function filterTags($source) { 
// filter pass setup 
$preTag NULL
$postTag $source
// find initial tag's position 
$tagOpen_start strpos($source'<'); 
// interate through string until no tags left 
while($tagOpen_start !== FALSE) { 
// tag setup 
$fromTagOpen substr($postTag$tagOpen_start); 
$tagOpen_end strpos($fromTagOpen'>'); 
$tagOpen_nested = (strpos(substr($fromTagOpen1), '<')+1); 
$tagOpen_length $tagOpen_end 1
$currentTag substr($fromTagOpen1$tagOpen_length); 
// iterate through tag finding attribute pairs - setup 
$tagLeft $currentTag
$attrSet = array(); 
$currentSpace strpos($tagLeft' '); 
// is end tag 
if (substr($currentTag01) == "/") { 
$isCloseTag TRUE
list(
$tagName) = explode(' '$currentTag); 
$tagName substr($tagName1); 
// is start tag 
} else { 
$isCloseTag FALSE
list(
$tagName) = explode(' '$currentTag); 

 
// this while is needed to support attribute values with spaces in! 
while ($currentSpace !== FALSE) { 
$fromSpace substr($tagLeft, ($currentSpace+1)); 
$nextSpace strpos($fromSpace' '); 
$openQuotes strpos($fromSpace'"'); 
$closeQuotes strpos(substr($fromSpace, ($openQuotes+1)), '"') + $openQuotes 1
// another equals exists 
if (strpos($fromSpace'=') !== FALSE) { 
// opening and closing quotes exists 
if (($openQuotes !== FALSE) && (strpos(substr($fromSpace, ($openQuotes+1)), '"') !== FALSE)) 
$attr substr($fromSpace0, ($closeQuotes+1)); 
// one or neither exist 
else $attr substr($fromSpace0$nextSpace); 
// no more equals exist 
} else $attr substr($fromSpace0$nextSpace); 
// last attr pair 
if (!$attr$attr $fromSpace
// add to attribute pairs array 
$attrSet[] = $attr
// next inc 
$tagLeft substr($fromSpacestrlen($attr)); 
$currentSpace strpos($tagLeft' '); 

// deals with nexted tags 
if (($tagOpen_nested $tagOpen_end) && ($fromTagOpen[$tagOpen_nested] == '<')) { 
$preTag .= substr($postTag0, ($tagOpen_start + ($tagOpen_end $tagOpen_nested) - 1)); 
$postTag substr($fromTagOpen$tagOpen_nested); 
$tagOpen_start strpos($postTag'<'); 
continue; 
// doesn't contain nested tag 
} else $preTag .= substr($postTag0$tagOpen_start); 
// appears in array specified by user 
$tagFound in_array(strtolower($tagName), $this->tagsArray); 
// remove this tag on condition 
if ((!$tagFound && $this->tagsMethod) || ($tagFound && !$this->tagsMethod)) { 
// reconstruct tag with allowed attributes 
if (!$isCloseTag) { 
$attrSet $this->filterAttr($attrSet); 
$preTag .= '<' $tagName
for (
$i 0$i count($attrSet); $i++) 
$preTag .= ' ' $attrSet[$i]; 
// reformat single tags to XHTML 
if (strpos($fromTagOpen"</" $tagName)) $preTag .= '>'
else 
$preTag .= ' />'
// just the tagname 
} else $preTag .= '</' $tagName '>'

// find next tag's start 
$postTag substr($postTag, ($tagOpen_start $tagOpen_length 2)); 
$tagOpen_start strpos($postTag'<'); 

// append any code after end of tags 
$preTag .= $postTag
return 
$preTag

 
/** 
* Internal method to strip a tag of certain attributes 
* @access private 
* @param Array $attrSet 
* @return Array $newSet 
*/ 
private function filterAttr($attrSet) { 
$newSet = array(); 
// has attributes 
for ($i 0$i <count($attrSet); $i++) { 
$attrSubSet explode('='$attrSet[$i]); 
list(
$attrSubSet[0]) = explode(' '$attrSubSet[0]); 
$attrFound in_array(strtolower($attrSubSet[0]), $this->attrArray); 
// keep this attr on condition 
if ((!$attrFound && $this->attrMethod) || ($attrFound && !$this->attrMethod)) { 
// attr has value 
if ($attrSubSet[1]) $newSet[] = $attrSubSet[0] . '=' $attrSubSet[1]; 
// reformat single attributes to XHTML 
else $newSet[] = $attrSubSet[0] . '="' $attrSubSet[0] . '"'


return 
$newSet


 
?>
Alıntıdır
__________________
[Bu Adresi (link) Görme Yetkiniz Yok BEDAVA'ya Üye Ol Sitemizden Faydalan....]
[Bu Adresi (link) Görme Yetkiniz Yok BEDAVA'ya Üye Ol Sitemizden Faydalan....]


[Bu Adresi (link) Görme Yetkiniz Yok BEDAVA'ya Üye Ol Sitemizden Faydalan....]
LastDesiqner isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Konu Sayısı: 488
Takımınız:
Alt 25/06/07, 16:49   #2
Satan22
Mareşal
 
Satan22 - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Dec 2006
Bulunduğu yer: Sence Nerden..:))
Mesajlar: 14.110
Tecrübe Puanı: 0 Satan22 isimli üye Tecrübe puanını kapatmıştır.
Standart

teşekkürler sağol...
__________________
TabuTlara sığmayacak kadar inTihar var , şeyTanın siparişi..
dünyanın ninnisi olmuş sirenler , Ya RAB bizi özler...

şah damarım aTTıkça yaşını silerim çeşmin , solar hayaT resmin..
umuT nerdesin yine biTTin , nerelere giTTin , ben seni göremeden...



Satan22 isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Konu Sayısı: 1596
Takımınız:
Alt 29/10/07, 12:50   #3
gokhanaygun
Tuğgeneral
 
gokhanaygun - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Apr 2007
Bulunduğu yer: VAN
Yaş: 36
Mesajlar: 925
Tecrübe Puanı: 26 gokhanaygun is a splendid one to behold gokhanaygun is a splendid one to behold gokhanaygun is a splendid one to behold gokhanaygun is a splendid one to behold gokhanaygun is a splendid one to behold gokhanaygun is a splendid one to behold gokhanaygun is a splendid one to behold
Standart

ya kardeş kimse bundan bişi anlamas ki kodlar çok karışık ..

insanları php den soğutacaksın haa

paylaşım için sağolasın ...
gokhanaygun isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Konu Sayısı: 187
Alt 06/02/08, 13:43   #4
Bur2
Korgeneral
 
Bur2 - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Oct 2007
Bulunduğu yer: evde :)
Yaş: 45
Mesajlar: 2.545
Tecrübe Puanı: 50 Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute Bur2 has a reputation beyond repute
Standart

paylaşım için tşkler
__________________

[Bu Adresi (link) Görme Yetkiniz Yok BEDAVA'ya Üye Ol Sitemizden Faydalan....]

[Bu Adresi (link) Görme Yetkiniz Yok BEDAVA'ya Üye Ol Sitemizden Faydalan....]


Bur2 isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Konu Sayısı: 497
Takımınız:
Alt 01/08/08, 10:21   #5
Neutralizer
Yasaklı kullanıcı
 
Neutralizer - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Jan 2008
Bulunduğu yer: İstediğin yerden
Mesajlar: 1.890
Tecrübe Puanı: 0 Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute Neutralizer has a reputation beyond repute
Standart

emeğe sağlık
Neutralizer isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Konu Sayısı: 317
Takımınız:
Alt 11/10/09, 00:03   #6
mbyorgun
Acemi Er
 
mbyorgun - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Oct 2009
Mesajlar: 2
Tecrübe Puanı: 0 mbyorgun will become famous soon enough
Standart

Tsk ederiz ama bunlarin hic birine gerek yokki
zaten php nin ozel fonksiyonu var

strip_tags(' <a href="siteadresi.com">TIKLA</a> '); // ciktisi : TIKLA

PHP- Kodu:
<?php
   $metin 
'<a href="siteadresi.com">TIKLA</a>';
   
$temizle strip_tags($metin);

   echo 
'Bu temizlenmis hali: '.$temizle.'<br/> Buda sade hali :'.$metin;
?>
Bu arada strip_tags() fonksiyonu php 4,5 de aktif di ve bu function php kodlarinida temizler ...
mbyorgun isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Konu Sayısı: 0
Takımınız:
Cevapla


Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 
Konu Araçları
Stil

Yetkileriniz
Yeni Mesaj yazma yetkiniz Aktif değil dir.
Mesajlara Cevap verme yetkiniz aktif değil dir.
Eklenti ekleme yetkiniz Aktif değil dir.
Kendi Mesajınızı değiştirme yetkiniz Aktif değildir dir.

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-KodlarıKapalı
Gitmek istediğiniz klasörü seçiniz


Bütün Zaman Ayarları WEZ +3 olarak düzenlenmiştir. Şu Anki Saat: 02:47 .


Powered by vBulletin
Copyright © 2000-2007 Jelsoft Enterprises Limited.
Sitemap
6, 5, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 113, 16, 17, 18, 19, 81, 20, 27, 22, 23, 24, 25, 26, 48, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 136, 40, 58, 45, 42, 44, 46, 47, 53, 54, 55, 56, 57, 59, 60, 70, 61, 62, 63, 64, 65, 66, 68, 69, 71, 72, 74, 75, 76, 77, 78, 79, 80, 82, 83, 96, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 98, 97, 100, 101, 102, 103, 106, 104, 105, 112, 109, 108, 107, 110, 111, 114, 115, 118, 116, 117, 119, 148, 154, 124, 165, 122, 120, 123, 121, 150, 153, 125, 128, 129, 131, 132, 133, 134, 135, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 151, 149, 202, 175, 164, 152, 167, 155, 156, 157, 158, 159, 160, 161, 162, 163, 195, 169, 166, 168, 170, 171, 172, 199, 174, 173, 196, 200, 176, 177, 180, 178, 179, 182, 189, 187, 184, 186, 191, 192, 193, 194, 197, 198, 201, 203, 229, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 236, 231, 232, 233, 234, 235, 237, 240, 239, 241, 243, 242, 244,