Codeiginiter HTML kodlaması

3 Cevap php

Ben Codeigniter de Girdi kütüphanede html kodlama ile bir sorunu var.

I have a form used to edit the News in the admin side of my project. Here is the HTML code of the title of the news:
echo form_input('title',($title) ? $title : $this->input->post('title'));

Düzenleme sayfa yüklendiğinde, herhangi bir doğrulama hata oluşursa, biçim başlık dosyasında yayınlanan değeri ile tekrar gösterilir, haber başlığını alarak ve $ title.After düzenleme bunu atıyorum. Yukarıdaki kod ile akılda yazılmıştır.

Şimdi konuya geliyor, diyelim ki yönetici XYZ's survey report gibi başlık girer ve gönderir. Bir doğrulama hatası başka bir alan için oluşursa Form yüklendiğinde Ardından, başlık alan />

XYZ's survey report

Ben yolladı değerli html kodlanmış, Girdi sınıfta düşünüyorum. Yani benim gereksinimi bir doğrulama hatası oluşursa, ben form.I onu göstermeden önce deşifresi değerini html zorunda olduğu />

echo form_input('title',($title) ? $title : html_entity_decode($this->input->post('title'),ENT_QUOTES));

ve çalışır. Ama proje büyük ve pek çok form alanları vardır. Ben bu başarmak için tek yol olduğunu bilmek hayal kırıklığı olacaktır.

3 Cevap

XSS Filtreleme görüntülenen giriş alanı değerini etkilemez.

Ben iki seçenek göreceksiniz:

1) You can manually create the INPUT element:
<input type="text" name="title" value="<?php echo ($title) ? $title : $this->input->post('title'); ?>" />

Sonradan tahribat yaratmak olasıdır) - 2) (önerilmez CodeIgniter kaynak kodunu değiştirebilirsiniz.

PS: Burada form_input değerini (form_helper.php) gösterilirken CodeIgniter kullanarak işlevi:

function form_prep($str = '')
{
	// if the field name is an array we do this recursively
	if (is_array($str))
	{
		foreach ($str as $key => $val)
		{
			$str[$key] = form_prep($val);
		}

		return $str;
	}

	if ($str === '')
	{
		return '';
	}

	$temp = '__TEMP_AMPERSANDS__';

	// Replace entities to temporary markers so that 
	// htmlspecialchars won't mess them up
	$str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
	$str = preg_replace("/&(\w+);/",  "$temp\\1;", $str);

	$str = htmlspecialchars($str);

	// In case htmlspecialchars misses these.
	$str = str_replace(array("'", '"'), array("&#39;", "&quot;"), $str);

	// Decode the temp markers back to entities
	$str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
	$str = preg_replace("/$temp(\w+);/","&\\1;",$str);

	return $str;
}

Gördüğünüz gibi, fonksiyon htmlspecialchars ve diğer hileler kullanıyor.

UPDATE- CodeIgniter exqample:

// config.php: $config['global_xss_filtering'] = FALSE;
echo form_open("test");
echo form_input('title', ($this->input->post('title')) ? $this->input->post('title') : $title);
echo form_input('title', ($this->input->post('title')) ? $this->input->post('title') : $title, FALSE);
echo form_input('title', ($_POST['title']) ? $_POST['title'] : $title, FALSE);
echo "<input type=\"text\" name=\"title\" value=\"" . (($title) ? $title : $this->input->post('title')) . "\" />";
echo form_submit("btn", "Submit");
echo form_close();

// output:
<form action="/test/" method="post">
<input type="text" name="title" value="XYZ&#39;s survey report"  />
<input type="text" name="title" value="XYZ&#39;s survey report"  />
<input type="text" name="title" value="XYZ&#39;s survey report"  />
<input type="text" name="title" value="XYZ's survey report" />
<input type="submit" name="btn" value="Submit"  />
</form>

XSS filtreleme küresel etkin varsa, giriş sınıfı otomatik olarak kodlar. Bu kapalı olduğundan emin olmak için application / config / config.php dosyasını kontrol edin:

$config['global_xss_filtering'] = FALSE;

http://codeigniter.com/user_guide/libraries/input.html

(Veritabanına veri eklerken bunu kullanıyorsanız) Ben çünkü set_value() fonksiyonu olduğunu düşünüyorum