Diğer Konular - .htaccess Eğer Aranılan Dosya Sitede Yoksa Index.php Yönlendir (scripti, nasıl, nedir?)
Nisan 15, 2008
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
not: index.php yerine hazırlayacağınız bir sayfada olabilir
kaynak: ordan burdan
Php - Server Zaman Farkını Düzeltme (scripti, nasıl, nedir?)
Nisan 15, 2008
$saatfarki = "8"; // ne kadar saat geri
$farki = (date("H") + ($saatfarki));
$gerial = mktime( $farki , date("i"), date("s"), date("m"), date("d"), date("Y"));
$tarih = date("Y-m-d",$gerial);
$yenizaman = date("H:i:s",$gerial);
kaynak: ordan burdan
//CAPTCHA OLUŞTURMA
<?php
session_start();
$width = 140;
$height = 70;
$im = imagecreate($width, $height);
$bg = imagecolorallocate($im, 0, 0, 0);
// generate random string
$len = 5;
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$string = '';
for ($i = 0; $i < $len; $i++) {
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos};
}
$_SESSION['captcha_code'] = md5($string);
// grid
$grid_color = imagecolorallocate($im, 175, 0, 0);
$number_to_loop = ceil($width / 20);
for($i = 0; $i < $number_to_loop; $i++) {
$x = ($i + 1) * 20;
imageline($im, $x, 0, $x, $height, $grid_color);
}
$number_to_loop = ceil($height / 10);
for($i = 0; $i < $number_to_loop; $i++) {
$y = ($i + 1) * 10;
imageline($im, 0, $y, $width, $y, $grid_color);
}
// random lines
$line_color = imagecolorallocate($im, 130, 0, 0);
for($i = 0; $i < 30; $i++) {
$rand_x_1 = rand(0, $width - 1);
$rand_x_2 = rand(0, $width - 1);
$rand_y_1 = rand(0, $height - 1);
$rand_y_2 = rand(0, $height - 1);
imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line_color);
}
// write the text
$text_color = imagecolorallocate($im, 255, 0, 0);
$rand_x = rand(0, $width - 50);
$rand_y = rand(0, $height - 15);
imagestring($im, 10, $rand_x, $rand_y, $string, $text_color);
header ("Content-type: image/png");
imagepng($im);
?>
////////////////////////////////////////////////////
DOÐRULAMA SAYFASI
<?php
session_start();
if(isset($_POST['submit'])) {
if(isset($_POST['captcha_code']) && isset($_SESSION['captcha_code'])) {
if(md5($_POST['captcha_code']) == $_SESSION['captcha_code']) {
echo 'Result: CAPTCHA code correct.<br />';
}else{
echo 'Result: CAPTCHA code incorrect.<br />';
}
}else{
if(!isset($_POST['captcha_code'])) {
echo 'Result: No security code was entered.<br />';
}
if(!isset($_SESSION['captcha_code'])) {
echo 'Result: No CAPTCHA was viewed.<br />';
}
}
}
?>
<form method="POST">
<img src="captcha.php" />
<br />
Enter the above text EXACTALY as it appears. Note: It is case sensitive<br />
<input type="text" name="captcha_code" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
kaynak: ordan burdan
<?php
function js_redirect($url, $seconds=5) {
echo "<script language="JavaScript">
";
echo "<!- hide code from displaying on browsers with JS turned off
";
echo "function redirect() {
";
echo "window.location = "" . $url . "";
";
echo "}
";
echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');
";
echo "->
";
echo "</script>
";
return true;
}
örnek :
js_redirect(http://google.com,5);//5 saniye sonra google sayfasına gidecek
kaynak: ordan burdan
Php - Kodların Içindeki Cdata, Script, Style, Code Taglarını Ve Içeriklerini Silmek (scripti, nasıl, nedir?)
Nisan 15, 2008
bu kodla formlardan gelebilecek saldırıları bir nebze temizleyebilirsiniz
<?
function stripLargeTags($html){
$searches = array (
"/<![CDATA[(.*)]]>/si", // Remove CData
"/<script[^>]*>.*?</script>/si", // Strip out javascript
"/<style[^>]*>.*?</style>/si", // Strip out styles
"/<code[^>]*>.*?</code>/si", // Strip out code chunks
"/<!–.*?–>/s", // Strip comments
"/<!.*>/Us", // Strip !Tags
"/<?.*>/Us" // Strip !Tags
);
$replace = array();
foreach($searches as $search){
array_push($replace, ''); // Replace all with ''
} reset($searches);
$text = preg_replace($searches, $replace, $html);
return $text;
}
?>
kaynak: ordan burdan
Php - Sitenizden Download Edilen Dosyanın Indirilme Hızını Belirlemek (scripti, nasıl, nedir?)
Nisan 15, 2008
<?
$filename = 'file-to-download.zip';
// filename visible for client
$visible_name = 'client-file-name.zip';
// setting the download rate limit (=> 36,6 kb/s)
$download_rate = 36.6;
// checking if file exists
if(file_exists($filename) && is_file($filename)) {
// send headers
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($filename));
header('Content-Disposition: filename='.$visible_name);
// flush content
flush();
// open file stream
$file = fopen($filename, "r");
while(!feof($file)) {
// send the current file part to the browser
print fread($file, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
// close file stream
fclose($file);
}
else {
die('Error: The file '.$visible_name.' does not exist!');
}
?>
kaynak: ordan burdan
<html>
<head>
<title>JS ile Fare Pozisyonu ve Tuş Denetimi</title>
<style type="text/css">
.tasinan {
position: absolute;
border: dashed 1px #59f;
margin: 15px 15px 15px 10px;
padding: 15px;
}
</style>
<script type="text/javascript">
var FarePosUst = 0;
var FarePosSol = 0;
function FarePosAl(olay)
{
if(!olay) var olay = window.event;
FarePosSol = olay.clientX;
FarePosUst = olay.clientY;
document.getElementById("BilgiKutusu").style.top = FarePosUst;
document.getElementById("BilgiKutusu").style.left = FarePosSol;
document.getElementById("mousepos").innerHTML = FarePosSol + ", " + FarePosUst;
return true;
}
// Fare hareket olay kontrolünü kendi fonksiyonumuza bağlıyoruz.
window.document.onmousemove = FarePosAl;
</script>
</head>
<body>
<div class="tasinan" id="BilgiKutusu">
<span>Fare Pozisyonu: </span><span id="mousepos">
</span>
<br />
</div>
</body>
</html>
kaynak: ordan burdan
Html - Formatlı Gösterimler (scripti, nasıl, nedir?)
Nisan 15, 2008
Metod Açıklama
big <big> etiketi oluşturarak karakter dizisinin "büyük" gösterilmesini sağlar.
blink <blink> etiketi oluşturarak karakter dizisinin "yanıp-sönmesini" sağlar.
bold <b> etiketi oluşturarak karakter dizisinin "kalın" gösterilmesini sağlar.
italics <i> etiketi oluşturarak karakter dizisinin "italik" gösterilmesini sağlar.
small <small> etiketi oluşturarak karakter dizisinin "ufak" gösterilmesini sağlar.
strike <strike> etiketi oluşturarak karakter dizisinin "üstü çizgili" gösterilmesini sağlar.
sub <sub> etiketi oluşturarak karakter dizisinin "altta" gösterilmesini sağlar.
sup <sup> etiketi oluşturarak karakter dizisinin "üstte" gösterilmesini sağlar.
fixed <tt> etiketi oluşturarak karakter dizisi içindeki karakterlerin "sabit genişlikte" gösterilmesini sağlar.
fontcolor <font color="renk"> etiketi oluşturarak karakter dizisinin belirtilen renkte gösterilmesini sağlar.
fontsize <font size="boyu"> etiketi oluşturarak karakter dizisinin belirtilen boyda gösterilmesini sağlar.
kaynak: ordan burdan
$theText = "http://www.OtelReferans.com";
$fontSize = 15;
$angle = 25;
$font = "arial.ttf";
$size = imageTTFBBox($fontSize, $angle, $theFont, $theText);
$image = imageCreateTrueColor(abs($size[2]) + abs($size[0]), abs($size[7]) + abs($size[1]));
imageSaveAlpha($image, true);
ImageAlphaBlending($image, false);
$transparentColor = imagecolorallocatealpha($image, 200, 200, 200, 127);
imagefill($image, 0, 0, $transparentColor);
$textColor = imagecolorallocate($image, 200, 200, 200);
imagettftext($image, $fontSize, 0, 0, abs($size[5]), $textColor, $font, $theText);
imagepng($image, "textImage.png");
imagedestroy($image);
kaynak: ordan burdan
Php - Gelen Ziyaretçiyi Session Lara Atayarak Ve Log Dosyasına Kaydederek. Site Istatistiği Oluşturmak (scripti, nasıl, nedir?)
Nisan 15, 2008
session_start();
if($_SESSION["logged"] != "yes")
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$visitTime = date("r"); //Example: Thu, 21 Dec 2000 16:01:07 +0200
$logLine = "$visitTime - IP: $ip || User Agent: $agent || Page: $uri || Referrer: $ref
";
$fp = fopen("istatistik.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
$_SESSION["logged"] = "yes";
}
?>
kaynak: ordan burdan
