如何为用户确认页面创建新的URL,而不首先将其手动添加到服务器


How do I create a new URL for a users confirmation page, without first manually adding it to my server.

在浏览静态页面并付费后,我希望用户在.com/confirmation/randomkey看到一个确认页面。我如何创建支付后的随机密钥,如果我没有通过手动添加一个php文件到我的服务器之前创建它。之前创建URL没有意义,因为我不知道谁会购买,而且每个URL都应该是唯一的。

您可以使用seo友好链接来重写URL。
那么你将能够处理随机键作为一个参数,而不需要为每个用户一个单独的页面。

例子:
www.example.com/confirmation/randomkey将被重写为www.example.com/?a=confirmation&key=randomkey

这是MVC经常使用的:例如,第一个参数(确认)将是控制器,根据参数(randomkey),内容将不同。在这种情况下,您不需要静态站点。

好的,我需要道歉,因为我误解了你的问题。我可以看到其中一个答案简短地触及它,所以我将更深入地解释一下,同时利用我的随机密钥的答案。

所以现在(从你的评论和问题判断)你有静态页面,但你希望确认页面是动态的。

最好在.com/confirmation/的根中有一个index.php。这可以将静态确认页面HTML与PHP内容放在一起。

.com/confirmation/index.php ?关键= 123456

<?php 
   $key = $_GET['key'] //Get key from URL which 123456
   //Check if Key is set or else redirect them somewhere else
   if (!isset($key)) {
          header('Location: http://www.foo.com/foo.php' );       
   }

?>
<html>
<head> </head>
<body>
   <p> Confirmation Key: <?php echo $key; //Print confirmation key to screen ?> </p>
</body>
</html>

这也可以通过使用会话传递数据来实现,这意味着不通过URL传递数据。这可以在$_SESSION变量中拾取,该变量可以从一个页面访问到另一个页面。通过这样做,您不需要在URL中传递变量,您只需要在确认之前从页面生成它并发送确认密钥。会话一直持续到浏览器关闭,所以它不像cookie,你可以设置数据的过期时间。

确认前的页面

<?php
//Start a session 
session_start();
//add to session variable
$key = $_SESSION['key'] = "Your KEY";
?>

.com/confirmation/index.php

<?php 
   session_start(); //Needs to start before session data can be read
   $key = $_SESSION['key'] //Data is queried from server NOT URL.
   //Check if Key is set or else redirect them somewhere else
   if (!isset($key)) {
          header('Location: http://www.foo.com/foo.php' );       
   }

?>
<html>
<head> </head>
<body>
   <p> Confirmation Key: <?php echo $key; //Print confirmation key to screen ?> </p>
</body>
</html>

:

http://php.net/manual/en/function.session-id.php