MyBB Depo Forum
Hazır Kodlar - Baskı Önizleme

+- MyBB Depo Forum (https://mybbdepo.com)
+-- Forum: Webmaster Deposu (https://mybbdepo.com/webmaster-deposu-forumu)
+--- Forum: Web Tabanlı Kodlama Dilleri (https://mybbdepo.com/web-tabanli-kodlama-dilleri-forumu)
+---- Forum: Php (https://mybbdepo.com/php-forumu)
+---- Konu Başlığı: Hazır Kodlar (/hazir-kodlar-konusu.html)



Hazır Kodlar - Smyrna35 - 21-08-2012

En son ne zaman scriptin güncellndiğini yazan fonksiyon

Kod:
<font   face="courier new, courier, mono">
<?php
echo date(’g:i a , j M y ’ , getlastmod());
?>

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

Sayfa Yuklenme Suresi


Kod:
<?php
function getmicrotime(){

   list($usec, $sec) = explode(" ",microtime());

   return ((float)$usec + (float)$sec);

}

//Sayfanın Başına Konulacak
$time_start = getmicrotime();


//Sayfadaki Veriler


//Sayfanın Sonuna Koyulacak
$time_end = getmicrotime();

//Yüklenme Süresi Yazdırılıyor
$time = $time_end - $time_start;
$time = number_format($time, 4, ".", "");
echo $time." saniye";
?>

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

Dosya boyutunu hesaplama


Kod:
<?
    function file_size($file){
    $size=filesize($file);
    if($size >= 1073741824){
    $size=round($size/1073741824)."Gb";
    }
    elseif($size >= 1048576){
    $size=round($size/1048576)."Mb";
    }
    elseif($size >= 1024){
    $size=round($size/1024)."Kb";
    }else{    
    $size=$size. "b";
    }
    echo "File size: <b>$size</b>" ;
    }
    
    file_size($file="index.php"); ?>

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

Son Giriş Tarihi ;

Kod:
<?
echo
"son giriş tarihiniz : " . date( "D m/d/Y h:i:[b]s[/b] a",fileatime( $PATH_TRANSLATED ) );
?>

---------------------------------------
IP ban


Kod:
<? $yetkililer=array("34.34.34.23", "23.23.23.23");
   if (!in_array(getenv("remote_addr"),$yetkililer)) die("Giris yasak !"); ?>

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

Şifreli Giriş Uygulaması

Kod:
<?
if (@$HTTP_GET_VARS["admin"] == "pass")
{
$kullanıcıadı = @$HTTP_POST_VARS["kullanıcıadı"];
$sifresi = @$HTTP_POST_VARS["sifresi"];
if($kullanıcıadı == "kurt" and $sifresi == "kurtbaba")
{
?>
<html>
Giriş Yaptınız
</html>
<?
}
else
{
echo "Yanlış Şifre";
}
}
else
{
?>
<html>

<head>
<title>Control Panel</title>
</head>

<bOdy>

<form method="POST" action="<? echo "$PHP_SELF?admin=pass"; ?>" ?>">
<p align="center">
Kullancı Adı
<br>
<input type="text" name="kullanıcıadı" size="30">
<br>
Şifresi
<br>
<input type="password" name="sifresi" size="30">
<br>
<input type="submit" value="GİR!>
</p>
</form>

</bOdy>

</html>
<?
}
?>

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

Kod renklendirme

forumlardaki gibi içine alınan kodların renklendirilmesi


Kod:
<?
    function bbencode_highlight_php($text) {
          
        $matches = array();
        $match_count = preg_match_all("#\\[php\\](.*?)\\[/php\\]#si", $text, $matches);
          
        for ($i = 0; $i < $match_count; $i++)
        {
              $before_replace = $matches[1][$i];
             $after_replace = trim($matches[1][$i]);
              $str_to_match = "[ph[b]p[/b]]" . $before_replace . "[/php]";
             $replacement = "";
             $after_replace = str_replace(’<’, ’<’, $after_replace);
             $after_replace = str_replace(’>’, ’>’, $after_replace);
             $after_replace = str_replace(’&’, ’&’, $after_replace);
             $added = FALSE;
             if (preg_match(’/^<\\?.*?\\?>$/si’, $after_replace) <= 0) {
                  $after_replace = "<?php $after_replace ?>";
                  $added = TRUE;
             }
             if(strcmp(’4.2.0’, phpversion()) > 0) {
                  ob_start();
                  highlight_string($after_replace);
                  $after_replace = ob_get_contents();
                  ob_end_clean();
            }
             else {
                  $after_replace = highlight_string($after_replace, TRUE);
             }
             if ($added == TRUE) {
                  $after_replace = str_replace(’<font color="#0000BB"><?php <br>’, ’<font color="#0000BB">’, $after_replace);
                  $after_replace = str_replace(’<font color="#0000BB"><br>?></font>’, ’’, $after_replace);
            }
             $after_replace = preg_replace(’/<font color="(.*?)">/si’, ’<span style="color: \\\\1;">’, $after_replace);
            $after_replace = str_replace(’</font>’, ’</span>’, $after_replace);
             $after_replace = str_replace("", ’’, $after_replace);
             $replacement .= $after_replace;
              
             $text = str_replace($str_to_match, $replacement, $text);
        }
      
       return $text;
}
?>

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

Resime metin ekle

Herhangibi resim üzerine yazı yazmanıza sağlar


Kod:
<?php

$dosya = ""; // png dosyası olmalı

header("Content-type: image/png");

$metin = "TRXgame.com";

$resim    = imagecreatefrompng("$dosya");

$turuncu = imagecolorallocate($resim, 220, 210, 60);

$px    = (imagesx($resim) - 7.5 * strlen($metin)) / 2;

imagestring($resim, 2, $px, 9, $metin, $turuncu);

imagejpeg($resim);

imagedestroy($resim);



?>

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

Tag Renklendirme
Sql Fonksiyonunun Bitiminden Bir Önceki yani Echodan Önceki Satıra Ekliyoruz


Kod:
$sayi = rand(0,4);
$r = rand(0,255);
$g = rand(0,255);
$b = rand(0,255);
$renk = dechex($r) . dechex($g) . dechex($b);
Kullanıma Bir Örnek :

echo "<a href=tag.php?tag=".$oku[’kelime’]."><font color=\\"#$renk\\" size=\\"$sayi\\">".$oku[’kelime’]."</font> ";
}

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

Sayfanın son güncellenme tarihi


Sayfanın fiziksel olarak en son ne zaman değiştirildiğini tarih ve saat olarak ekrana yazdırır.


Kod:
<?
$last_modified = filemtime("sayfa.php");
print("Son Güncelleme ");
print(date("j/m/y h:i", $last_modified));
?>

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

Bozmadan resim boyutla

Bir resimi profesyonel resim programları gibi boyutlandırıyor ve kaliteden taviz vermiyoruz hiç bir piksellik yok ve isterseniz kalitesini yüzde olrak değiştrip boyuttan kazanç sağlıyoruz ;




Kod:
codeDivStart()
<?php

// alt iki satırda dosyayı belirliyor be onu % kaç resize edicemiyi yazıoruz.


$filename = "dene.jpg";
$percent = 0.5;


header("Content-type: image/jpeg");


// ve seçilen yüzdelik(percent) ile yeni boyutlarımızı oluşturuyoz.


list($width, $height) = getimagesize($filename);
$newwidth = 180;

$newheight = 160;


// artık kaynağı yeni boyutları ile ayarladık.


$thumb = imagecreatetruecolor($newwidth, $newheight);

$source = imagecreatefromjpeg($filename);


// resim bu bölümde son halini yani yeni boyutlarını aldı


imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);



// ve dosyayı istenen % olarak kalite ile istenen adrese kaydettik


imagejpeg($thumb, "dene.jpg", 100);

?>

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

Verilen IP aralıklarını kontrol etme


Kod:
<?php
function checkIPorRange ($ip_address) {
     if (ereg("-",$ip_address)) {    
        // Range
        $ar = explode("-",$ip_address);
        $your_long_ip = ip2long($_SERVER["REMOTE_ADDR"]);
        if ( ($your_long_ip >= ip2long($ar[0])) && ($your_long_ip <= ip2long($ar[1])) ) {
             return TRUE;
        }
     } else {
        // Single IP
        if ($_SERVER["REMOTE_ADDR"] == $ip_address) {
             return TRUE;
        }
     }
     return FALSE;
}
?>

<?
// Örnek kullanım
$ip_range = "198.152.0.0-198.152.4.0";

if (checkIPorRange($ip_range)) {
     print "IP OK";
}
/*If your IP was 198.152.1.32
The above would return: IP OK */    
?>

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

Email kontrolü


Kod:
if (!eregi ("^([a-z0-9_]\\\\-\\\\.)+@(([a-z0-9_]\\\\-)+\\\\.)+[a-z]{2,4}$", $email))die ("E-Mail Adresiniz Geçersiz");
---------------------------------------

Rastgele kod üretici;

Kod:
function RandomCode($Length) {
    $Chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $Code  = "";
      for ($I = 0; $I < $Length; $I++)
        $Code .= $Chars[rand(0, strlen($Chars) -1)];
      return $Code;
}

echo RandomCode(6); //6 haneli bir kod üretir


[b]
Benzersiz code üretici; benzersiz ID ihtiyacınızı karşılayabilir[/b]

function UniqId() {
    $Q = str_replace(’ ’, ’-’, microtime()).’-’.rand(0,9).rand(0,9).rand(0,9);
    $Q = explode(’.’, $Q);
    return $Q[1];
}

echo UniqId(); //çıktısı 19117400-1192941538-766 şeklinde olur, .rand(0,9); eklenerek sonuna daha fazla rakam aldırılabilir.

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

Email Doğrulaması 2




Kod:
#Fonksiyon

function checkemail($email){
            return preg_match("/^[^\\s()<>@,;:\\"\\/\\[\\]?=]+@\\w[\\w-]*(\\.\\w[\\w-]*)*\\.[a-z]{2,}$/i",$email);
        }

#Hata Kontrolu

$email = $_POST[’email’];
if((!$email) OR (!checkemail($email))){ echo ’ - Dogru bir mail adresi girmediniz.’; }

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

Backlink Kontrolu

Kod:
<?php
function check_back_link($remote_url, $your_link) {
    $match_pattern = preg_quote(rtrim($your_link, "/"), "/");
    $found = false;
    if ($handle = @fopen($remote_url, "r")) {
        while (!feof($handle)) {
            $part = fread($handle, 1024);
            if (preg_match("/<a(.*)href=[\\"’]".$match_pattern."(\\/?)[\\"’](.*)>(.*)<\\/a>/", $part)) {
               $found = true;
               break;
            }
        }
        fclose($handle);
    }
    return $found;
}
// Örnek:
//if (check_back_link("http://www.hedefsite.com", "http://www.siteniz.com")) echo "Link bulundu.";
?>

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

Random Resim

Web Sayfanızda Random olarak fotoğraflarınızı gösterebilirsiniz. Resimler belirlediğiniz klasörden alınacaktır.

Kod:
<?php

/*
* Resimlerinizi 1.jpg, 2.jpg vs. şeklinde adlandırın
* Sayfanızda resimleri görmek istediğiniz kısımda şu satırları
* ekleyin: <?php include "randomimage.php"; ?>
*/

// Toplam resim sayınız ne kadarsa o şekilde değiştirin
$total = "11";

// Resim uzantısı, sizinki farklı ise değiştirin
$file_type = ".jpg";

// Resimlerin bulunduğu klasör
$image_folder = "images/random";

// Aşağıdakı satırları değiştirmeniz gerekmez
$start = "1";
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
echo "<img src=\\"$image_folder/$image_name\\" alt=\\"$image_name\\" />";
?>

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

Random olarak 10 karakterli sifre üretmektedir

Kod:
<?php
function sayiuret($sayi = 10)
{
global $f;
$dizim = "azwsedcrfvtgbxyhnujmIkolp"."AZWSEDCRFVTGBXYHNUJMIKOLP"."1234567890";
$boyut = strlen($dizim);
srand((double)microtime()*1000);
for($i = 0; $i <$sayi; $i++)
     {
$f .= $dizim[rand(0, $boyut)];

     }
return $f;
}


$sifrem= sayiuret(10);
echo ($sifrem);

?>

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

Dosyayi include edip logonun olmasini istediginiz yere $logo degiskenini çagirarak kullanabilirsiniz
Kod:
<?
$siteismi = "Site İsmi"; // Logonun üstüne geldiğinizde çıkmasını istediğiniz yazı
$format = "jpg"; // resim formatı olmalı (gif, jpg, png vs.)
$sayi = rand (1,11); // kaç tane logo varsa 11 yerine sayıyı yazın
$logo = "<img src=\\"logo".$sayi.".".$format."\\" alt=\\"".$siteismi."\\">";
?>

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

FONKSIYON OLUSTURMA:

Kod:
<?php

Function Renk(){

$sari = "sari renk";
$kirmizi = "kirmizi renk";
$mavi = "mavi renk";

echo "Fonsiyonun birinci degiskeni : <font color=’orange’>".$sari."</font><br>";
echo "Fonsiyonun ikinci degiskeni : <font color=’ff00’>".$kirmizi."</font><br>";
echo "Fonsiyonun ucuncu degiskeni : <font color=’blue’>".$mavi;

}

Renk();

?>

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

PHP ile Gün Hesapları



Kod:
<?php
echo strtotime("now"), "\\n";                
// bugün
echo strtotime("10 September 2000"), "\\n";  
// 10 eylül 2000
echo strtotime("+1 day"), "\\n";              
// bir gün sonrası
echo strtotime("+1 week"), "\\n";            
// bir hafta sonrası
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\\n";
// bir hafta 2 gün 4 saat 2 saniye sonrası
echo strtotime("next Thursday"), "\\n";
// en yakın perşembe
echo strtotime("last Monday"), "\\n";
// son pazartesi
?>

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

Dosya varmı yokmu kontrolü

Kod:
<?
      if (file_exists("deneme.txt"))
      {
           echo("Dosya var.");
      }
      else
      {
           echo("Dosya Yok");
      }
?>

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

Dosyamı değilmi kontrolü

Kod:
<?
        if (is_file("deneme.txt")
        {
             echo "Dosyadır.";
        }
        else
        {
             echo "Dosya değildir.";
        }
?>
---------------------------------------

PHP’de Güvenli Login işlemleri için şifreleme

Kod:
<?php
        $kul[0][’username’]="ali";
        $kul[0][’password’]="1234";

        $kul[1][’username’]="veli";
        $kul[1][’password’]="4321";

        function authenticate()
        {
            header( ’www-authenticate: basic realm="private"’ );
            header( ’http/1.0 401 unauthorized’ );
            echo("HATA");
            exit;
        }

        if (!isset($_server[’php_auth_user’]) || !isset($_server[’php_auth_pw’])) { authenticate(); } else
        {
              for($i=0;$i<count($kul);$i++)
              {
                     if($_server[’php_auth_user’]==$kul[$i][’username’] && $_server[’php_auth_pw’]==$kul[$i][’password’])
                     {
                           $auth = true;
                     }
              }
              if($auth !=true)
              {
                    authenticate();
              }
        }
?>
---------------------------------------

E-Mail Göndermek

Kod:
<?
$Kime      = ’gö[email protected]’;
$Konu      = ’E-Mail Fonksiyonu.’;
$mesaj     = ’Merhaba, email\\n denemesi’;
$basliklar = ’From: gö[email protected]’ . "\\n" .
             ’Reply-To: [email protected]’ . "\\n" .
             ’X-Mailer: PHP/’ . phpversion();
if (mail($Kime, $Konu, $mesaj, $basliklar)){
echo "email gönderildi.";}
else
{echo "email gönderilemedi.";}
?>

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

Veri Tabanından bilgileri cekme!!

Kod:
<?php

$baglanti=@mysql_connect("localhost","root","");

if(!$baglanti){

echo "MySQL’e baÄŸlantı kurulmadı!<br>Daha sonra tekrar deneyin!";

}

mysql_select_db("yayinevi",$baglanti);

$sql="select * from kitaplar ";

$sorgu=mysql_query($sql,$baglanti);

While($yazdir=mysql_fetch_array($sorgu))

{

echo "$yazdir[id]<br>";

echo "$yazdir[kitapadi]<br>";

echo "$yazdir[yazaradi]<br>";

echo "$yazdir[basimyili]<br>";

echo "$yazdir[sayfasayisi]<br>";

echo "$yazdir[yazaradresi]<br>";

echo "$yazdir[yazartel]<br>";

echo "<hr/>";

}

?>

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

Dizinin olup olmadığını kontrol etmek için:

Kod:
<?php
if(is_dir("dizinadi")
{
    echo "Dizin var";
}
else
{
    echo "Dizin yok";
}
?>
---------------------------------------

Girilen mesajı kaydeden php kodu


Kod:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form name="form1" method="post" action="sms.php">
<p> Mesajınızı Giriniz </p>
<p>
    <textarea name="T1" id="textarea" cols="45" rows="5"></textarea>
</p>
<p>
<label for="textarea"></label>
<input type="submit" name="button" id="button" value="Gönder">
</p>
</form>


    
<?php
    
    @$mesaj = $_POST[’T1’];
     $dosya = "mesajlar.txt";
     $conn = fopen($dosya , ’a’) or die ("Dosya açılamdı");
     fwrite($conn,$mesaj);
     fputs($conn," Bir sonraki mesaj ->");
     fclose($conn);
     echo "Mesajınız gönderilmiştir";
     header("Refresh :2 url:sms.php");
    
?>
---------------------------------------

Sayfa Girişini Engellemek

Kod:
if (preg_match("/config.php/i", $_SERVER[’PHP_SELF’])) { die("Bu dosyayi acmaniz izin verilmemis :)"); }
---------------------------------------
Kod:
Cyber-Warrior Tarafından Alıntıdır



Hazır Kodlar (TRXgame.com) - KaanN - 21-08-2012

1)
Kod:
[code]
[/code] tagları arasına alın.
2) Bu nedir ?



Hazır Kodlar (TRXgame.com) - Smyrna35 - 21-08-2012

konu güncellendi code taglarına alındı


Hazır Kodlar (TRXgame.com) - smt287 - 11-02-2013

Güzel Anlatım Gülümseme


Cvp: Hazır Kodlar - erinkral - 22-07-2014

Teşekkürler Gülümseme