在域PHP之外导航后继续使用脚本


Continue with script after navigating outside of domain PHP

我使用的代码使用链接将数据添加到外部DB:

<?php
$url = 'https://secure.site.com/Import.aspx?name=test&phone=1234567890';
echo "<script>window.location = '". $url . "'</script>";
?>

只要将数据放置在外部数据库中,就可以了。

然而,由于我无法访问另一端的脚本,一旦数据馈送完成,我就无法控制它的结果。

在空白的一页上留下"成功"这个词简直是死路一条。

有没有一种方法可以让我的脚本在"外部"到另一个网站后导航回服务器上的页面?

我尝试过重定向、标头、include等,但这些似乎都不起作用,因为一旦我转到那个链接,我的下一行代码就不会被读取。

由于您只想调用该url,所以不要重定向,只需调用它,而是向它提供必要的查询字符串。不需要重定向,所以你只需要留在你的代码中。

$data = array('name' => 'test', 'phone' => '1234567890');
$query_string = http_build_query($data);
$url = 'https://secure.site.com/Import.aspx?' . $query_string;
$response = trim(file_get_contents($url));
if($response == 'Success') { // if this is indeed the return value of that page
    // do what you have to do next
}