简体   繁体   中英

How to get a URL from a remote txt/php file and load that URL?

How to get a URL from a text/php file on another site and then open that URL link ?

And if there isn't one just default to default.php

I have access to both sites,

If I understand correctly you want site A to request an URL on site B. Site B will then respond with a URL and you want to load that. You could use the following

<?
$url = 'http://www.siteb.com/givemeaurl.php';
$content = implode('', file($url));//

//$content now contains the response from site B. If its only the URL you can use it directly, else you need to parse the results

if (strlen($content)>0) {
  //we have a value
  $newurl = $content;
} else {
  //no value
  $newurl = 'default.php';
}

//no open the new site
header('Location: ' . $newurl);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM