Jump to content
xisto Community
wappy

Wappy's Php Snippets I will place here usefull php snippets and functions that i learn/use

Recommended Posts

Here is a function you can use to generate a simple random password for whatever use ;-)

<?function rand_pass($numchar){$string = str_shuffle ("abcdefghijklmnopqrstuvwxyz1234567890");$password = substr ($string, 1, $numchar);return ($password);}//exampleecho rand_pass('8'); // will return an 8 character long random password of numbers and letters like c8k4ss42?>

Notice from serverph:
CODE tags added.


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 ;-)

<?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;}?>

Notice from serverph:
CODE tags added.


If you use (or have ever stopped using mobiliichat due to the stupid clone bug...) READ THIS!

<?//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//?>

Notice from serverph:
CODE tags added.


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://forums.xisto.com/no_longer_exists/ (please ignore the rude message at top its a test site i use for stuff ok)

<?//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";}?>

Notice from serverph:
CODE tags added.


Here are a few snippets i was given by PhoenixBytes ;-)

///////////////////////////////////////////////////////////////////////////////////////// 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 slashif (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


Notice from serverph:
CODE tags added. and finally merged FIVE successive posts in same thread. warning served as well. please review Xisto forum rules & TOS here.

Share this post


Link to post
Share on other sites

Oooh, nifty cool. Reminds me of a Firefox plugin for encrypting passwords. Very nice :)

Share this post


Link to post
Share on other sites

Yeah the random password thing can come in handy for email registration etc.

Share this post


Link to post
Share on other sites

But rememeber, even fixing the scripts wont help sometimes because you have just released your wappy_anti_clone and now hackers and other misfits can maybe get around it. Thats normally what happens - bugs are fixed just to have more bugs formed :)

Share this post


Link to post
Share on other sites

sigh.. maybe i should stop releasing stuff then juice? Eh look dude there are NOT many people like dj.dance who will stalk and try to ruin everything i do, there is something wrong with people like that. If you install that it WILL MAKE IT HARDER BY FAR TO DO IT. have you seen me get cloned yet? nO. I don't know why i bother sometimes. When your on top jealous spoilt brats just try to bring you down. To be honest i thought about banning both the popular sa networks from my site all together as all the trouble comes from this country. Well at least 90percent of it does anyway. It drives me CRAZY and here is my escape, i really don't want to talk about the dark side of wap here ok.

Share this post


Link to post
Share on other sites

yes by all means :-) you can use it :-)
what do you mean by credit like a link? If yes my wap site is http://forums.xisto.com/no_longer_exists/ or my web site is http://forums.xisto.com/no_longer_exists/ :-) im wappy from © wappyCULT
I hope you can make good use of these snippets :-)

Share this post


Link to post
Share on other sites

yes thanks i would rather you link to my site if possible. Wap or web i don't mind.Enjoy :-)

Share this post


Link to post
Share on other sites

Come on wappy I'm from sa and all I do is defend you aganst dj and his little kid followers.The only thing is that sa's got some of the best hackers in the world.

Share this post


Link to post
Share on other sites

yeah true but it would save me alot of hassle lol, i have been running wap sites for a couple of years now and have had more hassle of sa people than any other country dude. Yes i would lose about 10 friends, but would also lose almost all trouble on my site. I won't do it, but anyway as i stated above i don't want to talk about this wap war style stuff here. This is my escape from all that, this forum has nice helpfull people. Not like certain other forums i won't mention.

Share this post


Link to post
Share on other sites

Yes wappy but banning the SA networks will just make things worse, I'm in SA so please don't ban the SA networks :P FACT: The people from SA are some of the most addicted wappers around! :)

Share this post


Link to post
Share on other sites

i already said i won't ban the networks but as i said had been very tempted in the past. And yes there is alot of za people on wap bro.

Share this post


Link to post
Share on other sites

WAP forum

Wappy's Php Snippets

 

H0w can I make my own wap forum on my wapsite using php/mySQL?

Thank's... -=d(~_^)b=-

 

-question by Mark Anthony Gapoy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.