PHP and Web Technologies Freak
If you used Facebook on a regularly basis, you’ve probably come across their cool autocomplete method of adding multiple recipients to messages. For those that haven’t seen it, here’s a pic:

Guillermo Rauch set out to build something similar and he did a very good job of mimicking this behavior using MooTools v1.2:
The failing in using the value of $_SERVER['REMOTE_ADDR'] is that if the visitor is using a proxy then you will get the proxy IP address and not the visitors real IP address.
This function works by going through any variables in the $_SERVER array that might exist that would contain information to do with IP addresses. If they are all empty then the function finally looks at $_SERVER['REMOTE_ADDR'] value and returns this as a default.
function getRealIpAddr(){ if ( !empty($_SERVER['HTTP_CLIENT_IP']) ) { //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }
To run this function just call it.
echo getRealIpAddr();
This function was originally found here.
It is sometimes a good idea to find out where users can come from. When PHP is run the $_SERVER superglobal is always available and if the user has clicked on a link and landed on your page then the HTTP_REFERER value will be set. You can retrieve it like this.
if ( isset($_SERVER[ HTTP_REFERER ]) ) { echo $_SERVER['HTTP_REFERER']; }
Of course you might want to do something useful with this. For example, you might want to know what link a user clicked on when they broke your application.
This simple code example uses a combination of strrchr to find the last occurrence of a string and substr to return part of the string in order to find the file extension for a given filename. This is ideal if you want to quickly find a file extension.
$ext = substr(strrchr($fileName, '.'), 1);
This code can be used in the following way.
$fileName = '\path\to\file\afile.jpg'; $ext = substr(strrchr($fileName, '.'), 1); echo $ext;
The output here is ‘jpg’;
There are three available cryptographic functions in PHP, these are md5(), sha1() and crc32(). All of the functions take a string and output a value that is encrypted and can’t be reversed to the original string. In fact the only way to get the original string back is to run a brute force algorithm which tries to guess what the original string was.
To test these functions I will use the following string.
$string = 'wibble';
md5()
This function returns the hash as a 32-character hexadecimal number. The md5() function is used quite a bit and most PHP programmers will have come across it at some point.
md5($string); //returns 50eccc6e2b0d307d5e8a40fb296f6171
The md5() and sh1() functions have a second parameter which makes the function return binary data if set to true (the default is false). This returns binary data, which can be turned back into a hexadecimal number by using the bin2hex() function.
bin2hex(md5($string, true));
This function returns the same as in the previous example.
Read the rest of this entry »
1 2 3 4 5 6 7 8 9 10 11 | function ShortText($text) { // display char lenght $chars = 10; $text = $text." "; $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; // You can give a link here return $text; } //usage; echo ShortText("it's a very very very very very very very longggggggggggggg text"); |
1. Ajax Auto Suggest v.2
The AutoSuggest class adds a pulldown menu of suggested values to a text field. The user can either click directly on a suggestion to enter it into the field, or navigate the list using the up and down arrow keys, selecting a value using the enter key. The values for the suggestion list are to provided as XML, or as JSON (by a PHP script, or similar). This auto suggest class is very simple to customize and reuse in your web pages. Take a look here for the demo.
Hi!
i made this function at 2006 but still using it’s very usefull!
image.php;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php function createimg () { session_start(); ini_set("session.gc_maxlifetime","36000"); $fontnum=6; //count of fonts $numbers = strtoupper(substr(rand(0,999999999999),-3)); $_SESSION["guv"] = $numbers; $im = imagecreatetruecolor(125, 75); $white = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, 400, 200, $white); for ($i=0;$i<strlen($numbers);$i++) { $font = "fonts/".rand(1,$fontnum).".TTF"; if ((rand(2,6)%2)) { $angel=rand(0, 30); } else { $angel=rand(330, 360); } imagettfnumbers($im, 25, $angel, 10+$i*35, 49, imagecolorallocate($im, rand(1,250), rand(1,250), rand(1,250)), $font,$numbers[$i]); } $x=100; $y=100; $size=200; header("Content-type: image/png"); imagepng($im); imagedestroy($im); } createimg(); ?> |
You need 6 fonts in ./fonts directory like;
1.TTF
2.TTF
3.TTF
4.TFF
5.TFF
6.TFF
usage example;
1 2 3 | <img src="imgcode.php" alt="security" name="guv" id="guv"/> <!-- and also i made a relod image button here it is; --> <img src="images/reload.gif" width="16" height="16" border="0" alt="refresh" onclick="i=i+1; document.getElementById('guv').src='imgcode.php?id='+i"/> |
Here is the a screen shot;

1 2 3 4 5 6 7 8 9 10 | <?php foreach($_POST as $postkey =>; $postvalue){ $$postkey = $postvalue; } foreach($_GET as $getkey => $getvalue){ $$getkey = $getvalue; } ?> |
Hi,
Here i am again! I’ll start bloging again about web stuff. And share my hand made classes and codes