如何从单个创建多个URL

时间:2015-08-26 13:47:41

标签: php html

我有以下链接: http://server3.rciti.unsw.edu.au/stopandgo/index.php

现在,我的主管希望我向他知道的50位受访者中的每一位发送一个自定义网址。他创建了一份看起来像这样的受访者名单。

ID    Person name  
1     John  
2     Ram 
3     Charlie
4     Daniel

...and so on

他希望我提出以下自定义网址: http://server3.rciti.unsw.edu.au/stopandgo/index.php_1,依此类推(下划线后的数字是上面提到的人物ID)

通过这种方式,他将能够识别被访者,而无需他们透露自己的身份。

我无法找到解决此问题的方法。我发现很多网站都展示了如何将多个网址组合成一个,但我想要相反。

我也尝试过小网址,但是当我点击这个小网址时,它会将我引导到相同的原始链接。

2 个答案:

答案 0 :(得分:3)

为每个人提供一个如下所示的链接:

http://server3.rciti.unsw.edu.au/stopandgo/index.php/?id=1

然后,使用php来获取访问该网站的用户:

if (isset($_GET['id']) && is_numeric($_GET['id'])) //if a specific and valid user has visited the site
    $user = $_GET['id']; //will return 1, whom you know to be John

    //log John as having visited the site
    $file = 'visited.txt';                //open the file and get existing content
    $current = file_get_contents($file);  //append a new person to the end of the file
    $current .= $user."\n";         // Write the contents back to the file
    file_put_contents($file, $current);   //write to the file
}

然后,给Ram链接http://server3.rciti.unsw.edu.au/stopandgo/index.php/?id=2

答案 1 :(得分:1)

  1. 使用$ _GET []变量:

    $id = $_GET["id"];
    if(isset($id) && is_numeric($id)){
    //do something
    }

  2. 使用HTACCESS REWRITE

    RewriteRule /index.php_(.*) /index.php?id=$1