2014-02-10 37 views
0

我们有本地PHP文件A-Z。重定向开关语句在哪里编码。其实我想用id请求并获得重定向url的真实地址。例如,domain1.com完整路径,domain2.com完整路径。如何在php switch语句中得到url的真实地址

请有人让我知道,如何获得这些网址的真正的域路径?

<?php 

$id = $_GET['id']; 

switch ($id) { 

    case 01: 
    header("Location: http://domain1.com"); 
    break; 

    case 02: 
    header("Location: http://domain2.com"); 
    break; 


    default: 
    header("Location: http://"); 
    break; 

} 

?> 

我该如何请求ID?

http://localhost/a.php?id=123 

和URL的这样其返回实地址:

http://www.domain.com/content/title.html // etc 
+0

'$ _ SERVER [ 'HTTP_HOST']。 $ _SERVER ['REQUEST_URI']',http://www.php.net/manual/en/reserved.variables.server.php – NHG

+0

你知道'01'和'02'是八进制数吗?现在它不是问题,但是一旦你代码为'08'和'09' –

+0

yes,在第二个php文件中,我请求数字,并且我想要获得真正的URL路径,那么你可能会得到意想不到的结果,那么我有代码插入MySQL数据库中的真实网址。 –

回答

0

你需要这样的事?

$path = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
0

尝试

$parts = parse_url('http://domain1.com'); 
echo $parts['host']; 

输出将我们domain.com的,如果你需要使用路径$部件[ '路径']

+0

请检查我更新的问题,我想请求ID和函数返回我的实际地址 –