+ -
当前位置:首页 → 问答吧 → 求php获取url

求php获取url

时间:2010-01-12

来源:互联网

网址形式www.xx.com/show.php?id=xx

如何编写php文件
使得访问这样的网址 自动跳转到
另一个域名,后面的show.php?id=xx仍旧不变
谢谢

作者: webcc   发布时间: 2010-01-12

复制代码
  1. <?php
  2. $comeurl=$_SERVER["HTTP_HOST"];//主域名
  3. $addurl=$_SERVER['PHP_SELF'];//地址除域名外后面的部分
  4. if($comeurl=="www.xx.com") $newurl="http://www.google.cn";//新的跳转网址,换成你自己的
  5. $fullurl=$newurl.$addurl;
  6. header("Location:$fullurl");
  7. ?>

作者: tafengnanhai   发布时间: 2010-01-12

在讲分页的时候 有个 SERVER_URL函数,对你有用

作者: memory   发布时间: 2010-01-12

谢谢!~~不过只能跳转到show.php 后面的参数就不行了

作者: webcc   发布时间: 2010-01-12

<?php
$id=$_GET["id"];//url参数接收过来拼接上就可以
$righturl="?id=".$id;
$comeurl=$_SERVER["HTTP_HOST"];//主域名
$addurl=$_SERVER['PHP_SELF'];//地址除域名外后面的部分
if($comeurl=="www.xx.com")
{
    $newurl="http://www.google.cn";//新的跳转网址
    $fullurl=$newurl.$addurl.$righturl;
    header("Location:$fullurl");
}
?>

作者: tafengnanhai   发布时间: 2010-01-12

学习了

作者: blueboyhi   发布时间: 2010-01-12

相关阅读 更多