CODE
<?
function rand_pass($numchar){
$string = str_shuffle ("abcdefghijklmnopqrstuvwxyz1234567890");
$password = substr ($string, 1, $numchar);
return ($password);
}
//example
echo rand_pass('8'); // will return an 8 character long random password of numbers and letters like c8k4ss42
?>
function rand_pass($numchar){
$string = str_shuffle ("abcdefghijklmnopqrstuvwxyz1234567890");
$password = substr ($string, 1, $numchar);
return ($password);
}
//example
echo rand_pass('8'); // will return an 8 character long random password of numbers and letters like c8k4ss42
?>
Here is an extremly usefull search function that will search a directory and its subdirectories for files including the given keyword and display a link to these files. I have made some great file search systems for wap sites using this ;-)
CODE
<?
function search($target, $directory){
if(is_dir($directory)){
$direc = opendir($directory);
while(false !== ($file = readdir($direc))){
if($file !="." && $file != ".."){
if(is_file($directory."/".$file)){
if(preg_match("/$target/i", $file)){
$size = round(filesize($directory."/".$file)/1024,1); echo "<a href=\"$directory/$file\">$file ($size KB)</a><br>";
}
}else if(is_dir($directory."/".$file)){
search($target,$directory."/".$file);
}
}
}
closedir($direc);
}
return;
}
?>
function search($target, $directory){
if(is_dir($directory)){
$direc = opendir($directory);
while(false !== ($file = readdir($direc))){
if($file !="." && $file != ".."){
if(is_file($directory."/".$file)){
if(preg_match("/$target/i", $file)){
$size = round(filesize($directory."/".$file)/1024,1); echo "<a href=\"$directory/$file\">$file ($size KB)</a><br>";
}
}else if(is_dir($directory."/".$file)){
search($target,$directory."/".$file);
}
}
}
closedir($direc);
}
return;
}
?>
If you use (or have ever stopped using mobiliichat due to the stupid clone bug...) READ THIS!
CODE
<?
//anti-CLONE v1.0 by wappy//
//this i mainly designed for the cloning problem thats bugged mobiliichat (a cool wap chat script i used as base code for my WAP CHAT) since its release. Hope you can make good use of it. I have lol!!!!//
//© wappyCULT 2006-2007//
//!!DO NOT REMOVE HEADER!!//
//if your using this on your site then sure remove this crap! But if you plan to give it out please keep the original contents intact!!!!!//
//!!PUT THE FUNCTION UP HIGH ON YOUR PAGE SO IT CAN BE USED ANYWHERE!!//
//build our function anti-CLONE!!!!! This is most of the important stuff out the way but we need to do a little more protection after he he he he he... Dumb clones..//
function anti_clone($string){
return ereg_replace ("[^[:space:]a-zA-Z0-9*_:-]", "", $string);
}
//ENTER THIS PART WHERE YOU NEED IT!//
//enter the value you want to protect from cloning, for mobilichat it is $nimi or you can see the general idea by now you can work it out and make your own layout... God im bored pmpl...//
$value_to_protect = YOUR_VALUE;
//use our anti-CLONE function!!!!!//
$value_to_protect = anti_clone($value_to_protect);
//add even more protection from enters an returns!!!!!//
$value_to_protect = ereg_replace("\n", "", $value_to_protect);
$value_to_protect = ereg_replace("\r", "", $value_to_protect);
//strip any unwanted tags//
$value_to_protect = striptags ($value_to_protect);
//make sure all letters are small!!!!!//
$value_to_protect = strtolower ($value_to_protect);
//enter your value again here... Last bit now pmpl//
YOUR_VALUE = $value_to_protect;
//THATS IT YOUR VALUE WILL NOW BE SAFE FROM spaces, symbols, funny A's, tags, enters, returns an all the other crap these idiots try ha... Im SURE ITS SAFE NOW! Someone should of done this along time ago!! If you find a gap mail me asap with details!!//
//if you try and claim you wrote this grrr at you, it because i spent hours on this cool mobiilichat BUG FIX!! lol!!!!//
//if you can't get this to work or need help etc... I couldn't give a ????... If however you wanna share/trade scripts etc mail me at wappyCULT@gmail.com//
//wappy from wappyCULT//
?>
//anti-CLONE v1.0 by wappy//
//this i mainly designed for the cloning problem thats bugged mobiliichat (a cool wap chat script i used as base code for my WAP CHAT) since its release. Hope you can make good use of it. I have lol!!!!//
//© wappyCULT 2006-2007//
//!!DO NOT REMOVE HEADER!!//
//if your using this on your site then sure remove this crap! But if you plan to give it out please keep the original contents intact!!!!!//
//!!PUT THE FUNCTION UP HIGH ON YOUR PAGE SO IT CAN BE USED ANYWHERE!!//
//build our function anti-CLONE!!!!! This is most of the important stuff out the way but we need to do a little more protection after he he he he he... Dumb clones..//
function anti_clone($string){
return ereg_replace ("[^[:space:]a-zA-Z0-9*_:-]", "", $string);
}
//ENTER THIS PART WHERE YOU NEED IT!//
//enter the value you want to protect from cloning, for mobilichat it is $nimi or you can see the general idea by now you can work it out and make your own layout... God im bored pmpl...//
$value_to_protect = YOUR_VALUE;
//use our anti-CLONE function!!!!!//
$value_to_protect = anti_clone($value_to_protect);
//add even more protection from enters an returns!!!!!//
$value_to_protect = ereg_replace("\n", "", $value_to_protect);
$value_to_protect = ereg_replace("\r", "", $value_to_protect);
//strip any unwanted tags//
$value_to_protect = striptags ($value_to_protect);
//make sure all letters are small!!!!!//
$value_to_protect = strtolower ($value_to_protect);
//enter your value again here... Last bit now pmpl//
YOUR_VALUE = $value_to_protect;
//THATS IT YOUR VALUE WILL NOW BE SAFE FROM spaces, symbols, funny A's, tags, enters, returns an all the other crap these idiots try ha... Im SURE ITS SAFE NOW! Someone should of done this along time ago!! If you find a gap mail me asap with details!!//
//if you try and claim you wrote this grrr at you, it because i spent hours on this cool mobiilichat BUG FIX!! lol!!!!//
//if you can't get this to work or need help etc... I couldn't give a ????... If however you wanna share/trade scripts etc mail me at wappyCULT@gmail.com//
//wappy from wappyCULT//
?>
This is a good example of the strrev() command////
I used this simple function to determine the file extension of files on my site so i can put a unique icon next to each file thats listed. If you would like the icons (they are very small as designed for mobile/wap sites) you can get them at my wap site http://cul.t34.biz (please ignore the rude message at top its a test site i use for stuff ok)
CODE
<?
//icon code
$icon = "unknown.gif";
$rev = strrev ($file_name);
$exp = explode (".", $rev);
$true = strrev ($exp[0]);
$trueext = strtolower ($true);
if ($trueext=="zip" OR $trueext=="rar" OR $trueext=="gz"){$icon = "zip.gif";}
if ($trueext=="amr"){$icon = "amr.gif";}
if ($trueext=="midi"){$icon = "midi.gif";}
if ($trueext=="mid"){$icon = "mid.gif";}
if ($trueext=="gif"){$icon = "gif.gif";}
if ($trueext=="jpeg"){$icon = "jpeg.gif";}
if ($trueext=="jpg"){$icon = "jpg.gif";}
if ($trueext=="jad"){$icon = "jad.gif";}
if ($trueext=="jar"){$icon = "jar.gif";}
if ($trueext=="sis"){$icon = "sis.gif";}
if ($trueext=="bmp"){$icon = "bmp.gif";}
if ($trueext=="wbmp"){$icon = "wbmp.gif";}
if ($trueext=="txt"){$icon = "txt.gif";}
if ($trueext=="avi"){$icon = "avi.gif";}
if ($trueext=="thm"){$icon = "thm.gif";}
if ($trueext=="nth"){$icon = "nth.gif";}
if ($trueext=="png"){$icon = "png.gif";}
if ($trueext=="mmf"){$icon = "mp4.gif";}
if ($trueext=="wav"){$icon = "wav.gif";}
?>
//icon code
$icon = "unknown.gif";
$rev = strrev ($file_name);
$exp = explode (".", $rev);
$true = strrev ($exp[0]);
$trueext = strtolower ($true);
if ($trueext=="zip" OR $trueext=="rar" OR $trueext=="gz"){$icon = "zip.gif";}
if ($trueext=="amr"){$icon = "amr.gif";}
if ($trueext=="midi"){$icon = "midi.gif";}
if ($trueext=="mid"){$icon = "mid.gif";}
if ($trueext=="gif"){$icon = "gif.gif";}
if ($trueext=="jpeg"){$icon = "jpeg.gif";}
if ($trueext=="jpg"){$icon = "jpg.gif";}
if ($trueext=="jad"){$icon = "jad.gif";}
if ($trueext=="jar"){$icon = "jar.gif";}
if ($trueext=="sis"){$icon = "sis.gif";}
if ($trueext=="bmp"){$icon = "bmp.gif";}
if ($trueext=="wbmp"){$icon = "wbmp.gif";}
if ($trueext=="txt"){$icon = "txt.gif";}
if ($trueext=="avi"){$icon = "avi.gif";}
if ($trueext=="thm"){$icon = "thm.gif";}
if ($trueext=="nth"){$icon = "nth.gif";}
if ($trueext=="png"){$icon = "png.gif";}
if ($trueext=="mmf"){$icon = "mp4.gif";}
if ($trueext=="wav"){$icon = "wav.gif";}
?>
Here are a few snippets i was given by PhoenixBytes ;-)
CODE
/////////////////////////////////////////////////////////////////////////////////////
//
// this is the code i use for my search engine,
// the first if statement checks to see if this process has been done before or not,
// $stringy is only passed from the previous page with the cearch box on it, not from any 'back' or next links.
// the back and next links pass the $trimm variable
//
// so, if $trimm is empty, we must run $stringy through this code.
// if trim is NOT empty, we put $trimm through instead
//
// both variables are imported with the $malteasers variable
//
/////////////////////////////////////////////////////////////////////////////////////
if ($stringy == "") $malteasers = "$trimm";
else $malteasers = "$stringy";
$trimmed = trim($malteasers);
// this determines what characters can be used as a splitter, i.e 'space (%20)'
// this is so you can search for "chicken soup", "chicken" and "soup" all in one single query!
$trimmed_array = explode(" .%20.%2C.%26.%3F.%40",$trimmed);
// this foreach call was cut from my code (my code is on a loop)
// so this may work straight away or may need some editing,
foreach ($trimmed_array as $trimm);
// look for a slash
if (preg_match ("/\"/i", "$trimm"))
{
// do something with a function i'm sure is wrong, i may have taken a long way round when i was less experienced.
// $trimm = eregi_replace("/\"","",$trimm); might have worked instead of all the minusers and nudgers being needed!
$minuser = "2";
$trimm = eregi_replace("\"","",$trimm);
$preparetoslice = strlen("$trimm");
$sliceoffset = ($preparetoslice - $minuser);
$nudger = "1";
$trimm = substr($trimm,$nudger,$sliceoffset);
}
$query = "select count(*) from my_links where keywords LIKE '%$trimm%' AND valid='yes'";
$result = mysql_query($query);
$count = number_format(mysql_result($result,0,"count(*)"));
//
// if you wan't an ACCURATE search, let your text box pass a variable
// called $stringy
//
// then replace the database code with your own, but, keep the "where keywords LIKE '%$trimm%'" part!
//
// and that should be it, good luck with search!
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
//
// Random link generation:
//
$query = "SELECT * from randylinks ORDER BY RAND(" . time() . " * " . time() . ") LIMIT 1";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
$rowrandy = mysql_fetch_array($result);
$linkname = $rowrandy["linkname"];
$linkurl = $rowrandy["linkurl"];
$randylink = "<a href=\"$linkurl\">$linkname</a>";
//
//
// just alter your database details to get this one working
// you need a db table that supplies a linkurl and a linktext
//
// optionally you can easilly add an image into it to create an image link
//
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// MAKE WML COMPAT
//
// this is my make_wml_compat function, it should work though i have had issues with the carriage returns!
//
function make_wml_compat($string)
{
$string = ltrim($string);
$string = ereg_replace(chr(13),"<br/>",$string);
$string = ereg_replace(chr(10),"<br/>",$string);
$string = ereg_replace("¶","<br/>",$string);
$string = ereg_replace("µ"," ",$string);
$string = ereg_replace("===","<br/>",$string);
$string = ereg_replace("\n","<br/>",$string);
$string = ereg_replace("\r","<br/>",$string);
$string = ereg_replace("&","&",$string);
$string = ereg_replace("\\$","$",$string);
$string = ereg_replace("\","£",$string);
$string = ereg_replace("<","<",$string);
$string = ereg_replace(">",">",$string);
$string = ereg_replace("","-1",$string);
$string = ereg_replace("","-2",$string);
$string = ereg_replace("","-3",$string);
$string = ereg_replace("","-euro",$string);
$string = ereg_replace("","©",$string);
$string = ereg_replace("","®",$string);
$string = ereg_replace("~club","♣",$string);
$string = ereg_replace("~spade","♠",$string);
$string = ereg_replace("~heart","♥",$string);
$string = ereg_replace("~diamond","♦",$string);
$string = ereg_replace("~1","¹",$string);
$string = ereg_replace("~2","²",$string);
$string = ereg_replace("~3","³",$string);
$string = ereg_replace("~half","½",$string);
$string = ereg_replace("~quart","¼",$string);
$string = ereg_replace("~euro","€",$string);
$string = ereg_replace("~dot","•",$string);
return $string;
}
//
//
// this SHOULD work, however, different servers run different versions of php etc, so if you get an error on
// say, line 3452345, then find the symbol on that line and google php escape %symbol%
// an escape is to stop php parsing it, look at the dollar sign up there,
// it's escaped with two back slashes.
//
// you can use the above function like this: make_wml_compat("$text");
// it will do nothing if you don't call it.
//
// enjoy!
///////////////////////////////////////////////////////////////////////////////////////////////////
©PhoenixBytes

