Developers Archive for February, 2007

Calculating MD5 hash value of a file

Calculating MD5 hash value of a file Wednesday, February 28th, 2007

Syntax:

string md5_file ( string $filename [, bool $raw_output] )

md5_file funtion is used to calculates MD5 hash of the specified value.

Example:

<?php
$filename = “file1.txt”;
$md5val = md5_file($filename);
echo $md5val;
?>

fsockopen

fsockopen Tuesday, February 27th, 2007

fsockopen

fsockopen
- It open Internet or Unix domain socket connection

Syntax:

int fsockopen ( string hostname, int port [, int errno [, string errstr [, float timeout]]])

It initiates a stream connection in the Internet (AF_INET, using TCP or UDP) or Unix (AF_UNIX) domain. For the Internet domain, it will open a TCP socket connection to hostname on port port. hostname may in this case be either a fully qualified domain name or an IP address.

The optional timeout can be used to set a timeout in seconds for the connect system call.

fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fputs(), fclose(), and feof()).

If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call.

This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments will always be passed by reference.

Example:

$fp = fsockopen (”www.sample.com”, 80, $errno, $errstr, 30);
$input = “POST / HTTP/1.0
Host: www.sample.com\r\n\r\n”;
if (!$fp)
echo “$errstr ($errno)”;
else
{
fputs ($fp, $input);
while (!feof($fp))
echo fgets ($fp,128);
fclose ($fp);
}

Showing US Time

Showing US Time Tuesday, February 27th, 2007

Following script will print the time in US

setlocale(LC_ALL, “en_US”);
putenv(”TZ=EST”);
echo strftime(”%c\n”);

1.In the above script setlocale() function is used to set the local informations.

2. And putenv() function is used to set the current environment


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.