我希望脚本尽可能快地重定向用户,并在用户被重定向后继续处理数据。我在谷歌上找到了这个,但它不起作用。在重定向之前等待 10 秒。似乎用户需要等到脚本完成才能直接浏览器。
<?PHP
store data
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$user_ip=$_SERVER['REMOTE_ADDR'];
//Redirect to google
header("Location: http://www.google.com");
//Erase the output buffer
ob_end_clean();
//Tell the browser that the connection's closed
header("Connection: close");
//Ignore the user's abort (which we caused with the redirect).
ignore_user_abort(true);
//Extend time limit to 30 minutes
set_time_limit(1800);
//Extend memory limit to 10MB
ini_set("memory_limit","10M");
//Start output buffering again
ob_start();
//Tell the browser we're serious... there's really
//nothing else to receive from this page.
header("Content-Length: 0");
//Send the output buffer and turn output buffering off.
ob_end_flush();
//Yes... flush again.
flush();
//Close the session.
session_write_close();
//After redirection no need to send any data to user anymore.
//User would It's seem that user need to wait till script is finish before browser can be direct.
//Do some work
//sleep(10);
$matched = $wurflObj->getDeviceCapabilitiesFromAgent($userAgent);
$org = geoip_org_by_name($user_ip);
?>