...

View Full Version : Run php code after page loads



The_Return
10-12-2009, 12:52 AM
I wanna load a snippet that tells the person if their online or not but it takes to long when loading the page, so I wanna make it run when the page is already rendered. How would I do this?

Heres the code



$url = "http://www.blockstatus.com/aim/status-checker/index.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"aimac={$row['aim']}");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$result2 = curl_exec ($ch);
curl_close ($ch);
$data = $result2;
$pattern = '/Status:<\/b>(.*?)<br.*?><\/td>/i';
preg_match($pattern, $data, $status);
$output = str_replace("Status: ", "", $status[1]);
$aimstatus = trim($output);

oesxyl
10-12-2009, 12:59 AM
I wanna load a snippet that tells the person if their online or not but it takes to long when loading the page, so I wanna make it run when the page is already rendered. How would I do this?

Heres the code



$url = "http://www.blockstatus.com/aim/status-checker/index.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"aimac={$row['aim']}");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$result2 = curl_exec ($ch);
curl_close ($ch);
$data = $result2;
$pattern = '/Status:<\/b>(.*?)<br.*?><\/td>/i';
preg_match($pattern, $data, $status);
$output = str_replace("Status: ", "", $status[1]);
$aimstatus = trim($output);

you can't do this only with php because is server side and that means that when the page is loaded all php activity is finished. The only way to do this is to use ajax and after the page is loaded to do a ajax request to the server for what you want do.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum