Source codes, small scripts...

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • arnage
    replied
    A useful little function to convert the symbols in the different inputs.

    PHP Code:
    function ConvertSimbols($var, $ConvertQuotes = 0) {
    if ($ConvertQuotes > 0) {
    $var = htmlentities($var, ENT_NOQUOTES, 'UTF-8');
    $var = str_replace(array('\"', "\'"), '', $var);
    } else {
    $var = htmlentities($var, ENT_QUOTES, 'UTF-8');
    }
    return $var;
    } 
    
    Usage with quotes for example message:
    PHP Code:
    $message = ConvertSimbols($message); 
    
    Usage without quotes for example link:
    PHP Code:
    $link = ConvertSimbols($link, 1); 
    
    Get user agent.

    PHP Code:
    function user_agent() {
    $Browser = isset($_SERVER['HTTP__AGENT']) ? $_SERVER['HTTP__AGENT'] : '';
    $Browser = isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) ? $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'] : $Browser;
    $Browser = isset($_SERVER['HTTP_X_ORIGINAL__AGENT']) ? $_SERVER['HTTP_X_ORIGINAL__AGENT'] : $Browser;
    $Browser = isset($_SERVER['HTTP_X_DEVICE__AGENT']) ? $_SERVER['HTTP_X_DEVICE__AGENT'] : $Browser;
    $Browser = isset($_SERVER['HTTP_X_MOBILE_UA']) ? $_SERVER['HTTP_X_MOBILE_UA'] : $Browser;
    $Browser = isset($_SERVER['HTTP_X_BOLT_PHONE_UA']) ? $_SERVER['HTTP_X_BOLT_PHONE_UA'] : $Browser;
    $Agent = htmlentities($Browser, ENT_QUOTES, 'UTF-8');
    if (empty($Agent)) {
    $Agent = 'ProxyUA';
    }
    return $Agent;
    } 
    
    Last edited by arnage; 17.04.11, 17:18.

    Leave a comment:


  • arnage
    replied
    Input link validation regardless is written http:// or not:

    PHP Code:
    if (!preg_match('/^(http:\/\/)?[a-z0-9-\.]+\.[a-z]{2,4}$/iD', $var)) {
    echo 'Invalid URL format!';
    } 
    
    Last edited by arnage; 18.03.12, 07:52.

    Leave a comment:


  • arnage
    replied
    I can't remember the topic where I put last time and date snippet but it is not quite exact in months and years, so this one is ok.
    Replacement language is Serbian.

    PHP Code:
    function TimeDate() {
    $dan = date('l', time() + (2 * 60 * 60));
    $dan = str_replace('Monday', 'Ponedeljak', $dan);
    $dan = str_replace('Tuesday', 'Utorak', $dan);
    $dan = str_replace('Wednesday', 'Sreda', $dan);
    $dan = str_replace('Thursday', 'Četvrtak', $dan);
    $dan = str_replace('Friday', 'Petak', $dan);
    $dan = str_replace('Saturday', 'Subota', $dan);
    $dan = str_replace('Sunday', 'Nedelja', $dan);
    
    $datum = date('d.F Y.', time() + (2 * 60 * 60));
    $datum = str_replace('January', 'Januar', $datum);
    $datum = str_replace('February', 'Februar', $datum);
    $datum = str_replace('March', 'Mart', $datum);
    $datum = str_replace('April', 'April', $datum);
    $datum = str_replace('May', 'Maj', $datum);
    $datum = str_replace('June', 'Jun', $datum);
    $datum = str_replace('July', 'Jul', $datum);
    $datum = str_replace('August', 'Avgust', $datum);
    $datum = str_replace('September', 'Septembar', $datum);
    $datum = str_replace('October', 'Oktobar', $datum);
    $datum = str_replace('November', 'Novembar', $datum);
    $datum = str_replace('December', 'Decembar', $datum);
    
    $sat = date('H:i', time() + (2 * 60 * 60));
    
    echo '
    <p>'.$dan.', '.$datum.' '.$sat.'</p>';
     } 
    
    To adjust change value 2 to your needs in (2 * 60 * 60) , rest don't change.

    Echo it:

    PHP Code:
    echo TimeDate(); 
    
    Looks like:

    Petak, 28.Januar 2011. 20:03
    Last edited by arnage; 28.01.11, 20:08.

    Leave a comment:


  • Anshul
    replied
    mcrypt based encrytpion/decrypt if it is instal on ur sver
    PHP Code:
    #########################################################
    function encrypt($input)
    {
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $textkey = 'ZTlhZGY';
        return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, hash('sha256',$textkey,TRUE), $input, MCRYPT_MODE_ECB, $iv));
    }
    #########################################################
    function decrypt($input)
    {
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $textkey = 'ZTlhZGY';
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, hash('sha256',$textkey,TRUE), base64_decode($input), MCRYPT_MODE_ECB, $iv));
    }
    ######################################################### 
    

    Leave a comment:


  • Guest
    Guest replied
    include very easy

    Special to reuse code in different folders
    Code function:
    PHP Code:
    function inc ($inc) {
    $result = count(explode ("/",$_SERVER['PHP_SELF']))-2;
    switch($result){
    case '0':$inc='';break;
    case '1':$inc='../';break;
    case '2':$inc='../../';break;
    case '3':$inc='../../../';break;
    case '4':$inc='../../../../';break;
    case '5':$inc='../../../../../';break;
                       }
    return "$inc";
    } 
    
    Example:
    PHP Code:
    $inc = inc(inc);
    include_once($inc."/config.php"); 
    

    Leave a comment:


  • Guest
    Guest replied
    Quick fix for validating images on ready.mobi

    "Specify the width and height of images in pixels as attributes of the IMG element. This allows devices to leave space for the images when they arrive, which means that pages don't have to be re-drawn several times"

    PHP Code:
    <?
    function img($file){
    list($width, $height) = getimagesize($file);
    $count = strrpos ($file, 'http://');
    if($count){
    $n=1;
    $alt  = str_replace('http://','', $file);
    $alt = explode('/',$alt);
    $alt  = $alt[0];
    $alt = explode('.',$alt);
    $alt  = $alt[0];
    }
    else{
    $n=2;
    $alt = explode('/',$file);
    $alt  = $alt[count($alt)-1];
    $alt = explode('.',$alt);
    $alt  = $alt[0];
    }
    echo "<img src='".$file."' width='".$width."' height='".$height."' alt ='".$alt."'/>";
    }
    ?>
    Example:
    PHP Code:
    <? 
    img('tools/logo.gif');//my pictures
    img('http://waperos.net/tools/logo.gif');//external url
    ?>
    Results:

    HTML Code:
    <img src='tools/logo.gif' width='120' height='20' alt ='logo'/>
    <img src='http://waperos.net/tools/logo.gif' width='131' height='24' alt ='logo'/>

    Leave a comment:


  • malaysiawap
    replied
    easy redirect

    PHP Code:
    /*
    Using
    
    if(getbrowsername($_SERVER["HTTP_USER_AGENT"])=="WML"){
    // redirect WML
    }else{
    // redirect HTML
    }
    
    */
    
    function getbrowsername($brow){
    $browser=substr(trim($brow),0,4);
    if(
    $browser=="noki" ||   // Nokia phones and emulators
    $browser=="eric" ||   // Ericsson WAP phones and emulators
    $browser=="sams" ||     // Samsung
    $browser=="sage" ||     // Sagem
    $browser=="mot-" ||     // Motorola
    $browser=="sony" ||     // SonyEricsson
    $browser=="winw" ||   // WinWAP browser
    $browser=="leno" ||   // Lenovo browser
    $browser=="lg-b" ||   // LG browser
    $browser=="mozi" ||   // Mozilla browser
    $browser=="oper")
    $br = "WML";
    return $br;
    } 
    

    Leave a comment:


  • malaysiawap
    replied
    Easy birthdate dropdown

    PHP Code:
    /*
    using
    echo Birthday("22", "09", "1989");
    */
    
    function Birthday($day="01", $month="01", $year="1980"){
    $rform = "<select name=\"day\">";
    $dayval = range('1','31');
    foreach ($dayval as $key){
    if($key<10){
    $keyadd = "0$key";
    }else{
    $keyadd = "$key";
    }
    if($day==$keyadd){
    $rform .= "<option value=\"$keyadd\" selected=\"true\">$keyadd</option>";
    }else{
    $rform .= "<option value=\"$keyadd\">$keyadd</option>";
    }
    }
    $rform .= "</select> ";
    $rform .= "<select name=\"month\">";
    $monthval = array('1'=>'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    foreach ($monthval as $val => $months){
    if($val<10){
    $keyadd = "0$val";
    }else{
    $keyadd = "$val";
    }
    if($month==$keyadd){
    $rform .= "<option value=\"$keyadd\" selected=\"true\">$months</option>";
    }else{
    $rform .= "<option value=\"$keyadd\">$months</option>";
    }
    }
    $rform .= "</select> ";
    $rform .= "<select name=\"year\">";
    $yearval = range('1950','2009');
    //you can define range year here from year -> to year
    
    foreach ($yearval as $key){
    if($year==$key){
    $rform .= "<option value=\"$key\" selected=\"true\">$key</option>";
    }else{
    $rform .= "<option value=\"$key\">$key</option>";
    }
    }
    $rform .= "</select>";
    return $rform;
    } 
    

    Leave a comment:


  • malaysiawap
    replied
    Easy Paginantion For Lavalair or Maybe For All script ...


    PHP Code:
    /*
    LEGEND
    ======
    
    $ipp = items_per_pages
    $p = $_GET["page"]
    $ni = num_items
    $np = num_pages
    $npc = num_pagesc
    
    $url = like "index.php?action=main&amp;ses=$ses
    Using:
    echo Paging("$url", $p, $np, $npc, $ipp, $ls, $ni);
    */
    
    
    if($p=="" || $p<=0)$p=1;
    $noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM tablename"));
    $ni = $noi[0]; //changable
    $ipp= 5;
    $np = ceil($ni/$ipp);
    $npc = ceil($ni/$ipp);
    if(($p>$np)&&$p!=1)$p= $np;
    $ls = ($p-1)*$ipp;
    
    $sql = "SELECT *  FROM tablename ORDER BY orderid DESC LIMIT $ls, $ipp";
    $items = mysql_query($sql);
    echo mysql_error();
    if(mysql_num_rows($items)>0){
    while ($item = mysql_fetch_array($items)){
    
    }
    }else{
    echo "dataEmpty";
    }
    
    
    
    echo "<div class=\"paging\">";
    echo Paging("?action=$action&amp;session=$session", $p, $np, $npc, $ipp, $ls, $ni);
    
    // Recall Jump Page
    if($np>2){
    $rets = "<form action=\"\" method=\"get\">";
    $rets .= "<input type=\"hidden\" name=\"a\" value=\"$a\">";
    $rets .= "<input type=\"hidden\" name=\"s\" value=\"$s\">";
    $rets .= "<div align=\"center\">Jump<br/><input name=\"p\" style=\"-wap-input-format: '*N'; text-align:center\" size=\"3\" maxlength=\"4\"/></div>";
    $rets .= "<input type=\"Submit\" value=\"[GO]\" class=\"submit\"/></form>";
    echo $rets;
    }
    echo "</div>"; 
    

    here is function script

    PHP Code:
    function Paging($pagename, $p, $np, $npc, $ipp, $ls, $ni){
    $nav=' ';
    if($p<=3){
    $px=1;
    $np=$p+3;
    }
    
    if($p>3){
    $px=$p-3;
    $np=$p+3;
    }
    if($p>=($npc-3)){
    $np=$npc;
    }
    for($jp=$px; $jp<=$np; $jp++){
    if($jp==$p){
    $nav .= "<span class=\"disable\">[$jp]</span> ";
    }else{
    $nav .= " <a href=\"$pagename&amp;p=$jp\">[$jp]</a> ";
    }
    }
    if($p>1){
    $pp = $p-1;
    $left = "<a href=\"$pagename&amp;p=$pp\">«Prev</a> ";
    }
    if($p<$np){
    $npg = $p+1;
    $right = "<a href=\"$pagename&amp;p=$npg\">Next»</a>";
    }
    if($p>4) {
    $jp=$p-1;
    $first="<a href=\"$pagename&amp;p=1\">«First</a>";
    }else{
    $first='';
    }
    if($p<($npc-3)){
    $jp=$p+1;
    $last="<a href=\"$pagename&amp;p=$npc\">Last»</a>";
    }else{
    $last='';
    }
    if($ni>$ipp) {
    $paging = "Page $p of $npc<br />";
    $paging .= "$left  $right <br/> $first  $nav  $last ";
    }
    
    if($ipp>$ni){
    $paging .= "Page $np of $np";
    }else if($ni==0){
    $paging .= "Page 0 of 0";
    }
    
    return $paging;
    
    } 
    


    here is CSS
    HTML Code:
    .paging{
    text-align:center;
    }
    
    .disable{
    background-color: black;
    color:#000;
    }

    Leave a comment:


  • malaysiawap
    replied
    here is random in one day..



    PHP Code:
    /*
    using
    
    echo $display;
    */
    
    $date = date("d");
    $myFile = "record.dat";
    $fh = fopen($myFile, 'r');
    $theData = fread($fh, 5);
    fclose($fh);
    if($theData==$date){
    $myFile = "imgrecord.dat";
    $fh = fopen($myFile, 'r');
    $theData = fgets($fh);
    fclose($fh);
    //display image
    $display = '<img src="'.$theData.'" alt="*" border=0 width="281"/>';
    }else{
    $imglist='';
    //$img_folder is the variable that holds the path to the banner images. Mine is images/tutorials/
    // see that you don't forget about the "/" at the end
    $img_folder = "imgrandom/";
    mt_srand((double)microtime()*1000);
    //use the directory class
    $imgs = dir($img_folder);
    //read all files from the directory, checks if are images and ads them to a list (see below how to display flash banners)
    while ($file = $imgs->read()) {
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    $imglist .= "$file ";
    } closedir($imgs->handle);
    //put all images into an array
    $imglist = explode(" ", $imglist);
    $no = sizeof($imglist)-2;
    //generate a random number between 0 and the number of images
    $random = mt_rand(0, $no);
    $image = $imglist[$random];
    $myFile = "record.dat";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = $date;
    fwrite($fh, $stringData);
    fclose($fh);
    $myFile = "imgrecord.dat";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = $img_folder.$image;
    fwrite($fh, $stringData);
    fclose($fh);
    } 
    
    dont forget to create this file
    record.dat [CHMOD 777]
    imgrecord.dat [CHMOD 777]
    imgrandom [FOLDER]
    Last edited by malaysiawap; 05.11.09, 03:20.

    Leave a comment:


  • GiLL
    replied
    How To Show Random Images From A Folder

    Here's the script. Call it something like images.php:

    Code:
    <?php
    
    Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    
    Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
    
    Header("Pragma: no-cache");
    
    Header("Content-Type: image/gif");
    
    
    
    $dir = "Images"; // This is the folder where the images are
    
    
    
    srand((double)microtime()*1000000);
    
    $i = 0;
    
    $dirHandle = opendir($dir); // Open the images folder
    
    while(($im = readdir($dirHandle)))
    
    {
    
    if($im != ".." && $im != ".") // Don't read in the 2 folders ".." and "."
    
    {
    
    $image[$i] = $im; // Select an image
    
    $i++;
    
    }
    
    }
    
    closedir($dirHandle); // Close the folder
    
    $n = rand(0,(count($image)-1));
    
    
    
    if(!readfile($dir."/".$image[$n])) // Read the image
    
    readfile($dir."error/error.gif"); // If the script can't find the directory, display this image
    
    ?>
    And now on your page, put this:
    Code:
    <img src="http://www.yourdomain.com/images.php" border="0">
    And there you have it! It will randomly display any image in the images folder!

    Enjoy!

    Leave a comment:


  • GiLL
    replied
    selects a random favicon from a specified directory. copy and paste it into the html head tag and change the dir variable to your icons directory.
    Code:
    <?php
    $dir = "images/icons/";
    $files = array();
    if ($handle = opendir($dir)) {
    	while (false !== ($file = readdir($handle))) {
    		$files[] = $file;
    	}
    }
    $icon = $files[rand(2,count($files)-1)];
    echo "<LINK REL=\"SHORTCUT ICON\" HREF=\"/images/icons/" . $icon . "\">";
    ?>

    Leave a comment:


  • Anshul
    replied
    PHP Code:
    
    <?php
    class chat {
    function a_header($title = 'chat-zone.mobi',$time_update = '0'){
    
    header("Cache-Control: no-store, no-cache");
    header("Content-type:text/html; charset=utf-8");
    
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head><link rel="stylesheet" type="text/css" href="'.rootlink.'css/css.css"/>
    <title>'.$title.'</title>';if (!empty($time_update)){echo '<meta http-equiv="refresh" content="'.$time_update.'" />';}echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>';
    }
    function a_footer($url = '',$name = 'Logout')
    {
    if (empty($url))  {$url= rootlink.'?action=logout';}
    echo '<div class="logout"><a href="'.$url.'&amp;'.SID.'">'.$name.'</a></div></body></html>';
    }
    function write($text)
    {
    echo $text;
    }
    function form($link = 'index.php',$method = 'post')
    {
    echo '<form action="'.$link.'" method="'.$method.'">';
    }
    function input($text,$name,$size='',$maxlength,$value = '')
    {
    if(!empty($text)){echo $text.'<br/>';}
    echo '<input type="text" name="'.$name.'" ';
    if($size > 0 && !empty($size)){echo 'size="'.$size.'" ';}
    if($maxlength > 0){echo 'maxlength="'.$maxlength.'" ';}
    echo 'value="'.$value.'" class="itext"/><br/>';
    }
    function hidden($name,$value)
    {
    echo '<input type="hidden" name="'.$name.'" value="'.$value.'"/>';
    }
    function checkbox($name,$value,$nme = '')
    {
    echo '<input type="checkbox" name="'.$name.'" value="'.$value.'"/>'.$nme.'<br/>';
    }
    function button($name,$value,$o = '',$c = '')
    {
    if(!empty($c)){echo '<input type="radio" name="'.$name.'" value="'.$value.'" checked="checked"/>'.$o.'<br/>';}
    else{echo '<input type="radio" name="'.$name.'" value="'.$value.'"/>'.$o.'<br/>';}
    }
    function end_form($value)
    {
    echo '<input type="submit" name="" value="'.$value.'" class="ibutton"/></form>';
    }
    function select($name, $value)
    {
    echo '<select name="'.$name.'" value="'.$value.'">';
    }
    function addselect($value, $label)
    {
    echo '<option value="'.$value.'">'.$label.'</option>';
    }
    function select_end()
    {
    echo '</select><br/>';
    }
    }
    ?>
    usage

    chat::a_header('chat-zone.mobi');
    chat::write('hi');
    chat::a_footer();
    or
    $chatcls = new chat;
    $chatcls->input('login',login,'15','15',$_SESSION['nicks']);
    Last edited by Anshul; 10.10.09, 22:36.

    Leave a comment:


  • opticalpigion
    replied
    PHP Code:
    <?  
      /*
      Multi Auto Redirection
      
          /\             / -------
         /     \   _   /    ----------
        / /     \[.. ]/    ---------
       ////// ' \/ `   ------
      ////  // :    : ------
     // /   /  /`    '----
    //          //..\\
              ==UU==UU==
                 '//||\\`
      
      By opticalpigion
      */
    //set the urls  
    $urls = array("http://google.com" ,"http://hotmail.com" ,"http://hawkee.com" );  
      
    //set the text links  
    $text = array("Google" ,"Hotmail" ,"Hawkee");  
            srand(time());  
      
    //set the number in (rand()%3); for however many links there are  
            $random = (rand()%3);  
    header( 'Location:'.$urls[$random]) ;
    ?>

    Leave a comment:


  • Anshul
    replied
    Deny access to static file data
    Code:
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
    RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]

    Leave a comment:

Working...
X