Archive for the 'PHP' Category

Php script set_time_limit timeout and socket operations

The PHP function set_time_limit is used to set a time limit on the maximum execution time of a script. But if the script has socket operations using fsockopen , fread and fwrite or even CURL then the set_time_limit may not appear to have any effect on the scripts timelimit or timeout.Again if safe mode is [...]

Get Real IP address and proxy of visitor in PHP

$_SERVER['REMOTE_ADDR'] or getenv(’REMOTE_ADDR’) is often used to find the remote users or visitors IP address on a website. But this value may not be the real ip address of the user who just visited the site. If the user is behind a proxy then the value of $_SERVER['REMOTE_ADDR'] will the IP address of the proxy [...]

Output buffering PHP Apache mod gzip mod deflate

Till recently most of my php scripts were working fine on the servers with instantaneous outputs as and when a echo statement came. One issue that popped a lot on localhost was that of chunky outputs; that is the outputs of big scripts came out in chunks rather than smoothly with every echo or print [...]

Remote Login with Curl PHP

The Curl Library of PHP can be used to open remote web pages and also logging in where a login is required.
Code

$login_url = ‘http://www.somesite.com/login.php’;
#These are the post data username and password
$post_data = ‘username=someusername&password=somepassword’;
#Create a curl object
$ch = curl_init();
#Set the useragent
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
#Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );
#This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 [...]

PHP Script to find visitor’s location

Hello All
Here is a simple php script that lets you track the location of the visitor’s on your site.
Lets get to the code straight away :

<?
$ip = ‘59.93.196.219′;
$url = "http://www.ipmango.com/api.php?ip=".$ip;
$xml = simplexml_load_file($url);
echo "IP address : {$xml->ipaddress}";
echo "City : {$xml->city}";
echo "Region : {$xml->region}";
echo "Country Name : {$xml->countryname}";
echo "Latitude : {$xml->latitude}";
echo "Longitude : {$xml->longitude}";
?>

Write Excel Files in PHP – Simple and Easy Way

Hi
So this time my simple task was to extract some data from some websites and write them into an excel file and submit. So I simply googled up and found a class calledMS-Excel Stream Handler. With it I went really happy as it was very easy and simple to use, with just a include file.

PHP 5.2.2 on Apache 2.2.4 on Windows XP

PHP 5.2.2 on Apache 2.2.4 on Windows XP
So this was another issue that was bugging me. session_start() was not resuming session. After logging in through the login page when an attempt was made to open another page the session was lost. Interestingly Internet Explorer and Mozilla were facing this problem but Opera was working happily [...]