php微小的url链接不正确.我的网站url被附加到tinyurl.com,我得到了一个404错误


php tiny url not linking correctly. My website url gets appended to tinyurl.com and I get a 404 error

这是我的小url函数

private function getTinyUrl($url) {
    return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
}

输出类似于http://tinyurl.com/nj76pbs所以这很好。

但当我使用url时,它会将我带到

tinyurl.com/mywebsite.com/code?=fqhfkqhiurhg98y

我得到一个404没有找到。该怎么办?

我认为这是因为您的$url不包含"http://"或"https://"。因此,当tinyURL尝试重定向时,它会停留在tinyURL域中。你的$url变量有http还是https?如果总是这样,您可以将其添加到file_get_contents调用中。

此外,file_get_contents不会在所有服务器上都工作。有时会受到限制。如果你有机会的话,我建议你尝试用CURL来做这件事。

您缺少URL前面的http://、https://。如果需要的话,你可以在函数中添加一个复选框来自动添加前缀。