PDA

View Full Version : آموزش: تکه کد های تقریبا کاربردی در php



djsaeedkhan
پنج شنبه 22 دی 1390, 17:40 عصر
ضبط آدرس های درخواست شده

$requestURI = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']';


پاک کردن متغیر های گلوبال

$_POST["name"] = strtolower(stripslashes(trim(htmlspecialchars($_PO ST["name"]))));
$_POST["message"] = strtolower(stripslashes(trim(htmlspecialchars($_PO ST["message"]))));


درست کردن یک لوک آپ (یا مشخصات یک آی پی)

// ip lookup from database
$ip = $row["address"];
$url = "http://api.hostip.info/get_html.php?ip=".$ip;
$contents = file_get_contents($url);
$values = split("[\n|\r]",$contents);

$count = count($values);
for($i = 0; $i < $count; $i++) {
if($i != $count-1) {
echo $values[$i] . "\n";
}
}


نمایش سورس های یک آدرس (مثل ویو سورس براوزر ها)

<?php // display source code
$lines = file('http://google.com/'); // pick teh url
foreach ($lines as $line_num => $line) {
// loop thru each line and prepend line numbers
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}