Small php Script`s

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
Redirect script webbrowser from wap to web and wapbrowser from web to wap.

PHP:
<?
$htmlredirect = "http://kralj.frih.net";
$wmlredirect = "http://kralj.r8.org";
if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0){
header("Location: ".$wmlredirect);}
else{
header("Location: ".$htmlredirect);
exit;}
?>
 

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
Here is countdown script:

PHP:
<?
$day = 1;
$month = 1;
$year = 2006;
$end = mktime(0,0,0,$month,$day,$year);
$today= mktime(date("G"),date("i"),
date("s"),date("m"),date("d"),date("Y"));
$days=($end-$today)/86400;
if ($days>0) {
$r1 = explode('.',$days);
$hours=24*($days-$r1[0]);
$r2 = explode('.',$hours);
$minutes=60*($hours-$r2[0]);
$r3 = explode('.',$minutes);
$seconds=60*($minutes-$r3[0]);
$r4 = explode('.',$seconds);
echo 'Days left: ' .$r1[0];
echo '<br>Time left: ' . $r2[0] . ':' . $r3[0] . ':' . $r4[0];
} else {
echo "Happy new year:)";}
?>
 

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
RANDOM IMAGE SCRIPT

RANDOM IMAGE SCRIPT


First create a folder called image.gif and upload your images to it.
When you have done that, make a file in that folder called index.php and add this code.

PHP:
<?php

    $folder = '.';

    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';
    
$img = null;

if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
}

if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
        $img = $folder.$imageInfo['basename'];
    }
} else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
        $file_info = pathinfo($file);
        if (
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
        ) {
            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
}

if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: image/png");
        $im = @imagecreate (100, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}

?>


Now by linking to yoursite.com/image.gif (image.gif being the folder) the index file will automatically run and random images will be displayed. That means you can display random images in forums like these.
 

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
TIME MESSAGES

TIME MESSAGES


PHP:
<?php

$TimeZone="8"; ////Change the TimeZone accordingly!
$New_Time = time() + ($TimeZone * 60 * 60);

$show_date=date("D dS F, Y",$New_Time); 
$show_time=date("H:i",$New_Time); 
$Hour=date("G",$New_Time);

echo $show_date;
echo"<br/>";
echo $show_time;
echo"<br/>";


////////////////Here you can change the messages, add lines with different hours etc. You could even display a different message every hour.////////////////

if ($Hour <= 4) { echo 'Hello night owl!'; } 

else if ($Hour <= 11) { echo 'Good morning!'; } 

else if ($Hour <= 12) { echo 'Enjoy your lunch!'; }

else if ($Hour <= 17) { echo 'Good afternoon!'; } 

else if ($Hour <= 23) { echo 'Good Evening!'; }

?>
 

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
ONLINE USERS

Display who is online. Create a file called besucher.txt and chmod to 777.
Now create a file called online.php or whatever and add this.

PHP:
<?

header("Content-Type: text/vnd.wap.wml");
echo '<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>

<card title="Online">

<do type="prev" label="Back"><prev/></do>';
  print "<p>";
  $xfile = @file("besucher.txt");
  $xfile = array_reverse($xfile);
  $p = 150;

  if ($npage == ""){$npage = "1";}
  $first = count($xfile) - ($p * ($npage - 1));
  $second = count($xfile) - ($p * $npage) + 1;
  if ($second < 1) {$second = 1;}
  $npages = (int)(count($xfile) / $p);
  if ($news_limiter>((int) ($npages*$p))) $npages = $npages+1;
  if ($npage <= $npages and $npage>1) $gline_rew = "<a href=\"guest.php?npage=".($npage-1)."\">Prev</a>";
  if ($npages > 1 and $npage<$npages) $gline_next = "<a href=\"guest.php?npage=".($npage+1)."\">Next</a>";
  $line = "";

  for ($p = 1; $p <= $npages; $p++) {
   if ($p != $npage) { $line .= "<a href=\"guest.php?npage=$p\"> $p </a>|";}
   if ($p == $npage) { $line .= "| $p |<br/>"; }
  }

  print $line;

  for ($i = $first-1; $i >= $second-1; $i--) {
   $ii = $i;
   $ii++;
   $udata = explode("&&",$xfile[$i]);
   print "$udata[1]<br/>";
   print "--------<br/>";
  }

  print $gline_rew."".$gline_next."
  
  <a href=\"/index.php\">LandOfwap.net</a></p>
  </card>
  </wml>";

?>
 

x-pert

Member
Jun 13, 2006
20,952
77
0
MaD-DoC said:
ya great site for web and wap coding help .......................
and really php coder`s there........................

Yeah seriously it's a good source :yes:

Why invent the wheel again ;) Code re-use hehe