目前我有页面说page1.php。现在在某些情况下,我只想运行另一个链接,例如http://example.com,而无需实际刷新此页面。链接是一种可更新我的数据库的脚本。我尝试使用shell_exec('php'。$ url); 其中$ url =' http://example.com ',但是它显示了无法打开文件的错误,因此我认为shell_exec仅适用于服务器上存在的内部文件。有没有一种方法可以直接执行此操作,或者我必须使用AJAX?提前致谢
尝试使用curl将请求发送到带有php的服务器。
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_exec($ch);
curl_close($ch);
或者,您可以尝试 file_get_contents
file_get_contents('http://example.com');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句