我编程一个PHP登记制度,其中有两个入口(如果是有道理的):PHP注册问题
如果客户想要购买产品,但没有一个帐户,并它通过注册过程一直存储产品的ID。然后它允许在注册后处理付款。
客户端首次注册时未尝试购买产品。
这些是将用户引导到注册页两种方法上面的链接:
1. <a href="register.php?id=<?php echo $row['product_id'] ?>"></a>
2. <a href="register.php?type=first"></a>
这是文件register.php的代码:
<?php
if(empty($_GET['type'])== "first") {
header("Location: register.php?type=first&step=1");
}
if(empty($_GET['id'])) {
if($_GET['type']) {
//show the content first registration
}
header("Location: register.php?type=first&step=1");
}else{
$product_id=$_GET['id'];
header("Location: register.php?id=".$product_id."&step=1");
//show the content with the product information
}
?>
<html>...</html>
的问题是:
当使用上面的第一种方法时,php说它有一个重定向循环,我似乎无法解决这个问题。一旦我们有这个工作,我想要显示的内容,但这导致第二个问题。
当使用第二种方法时,它工作并显示首次注册的内容,但它不显示此代码下面的任何html内容。
任何帮助,将不胜感激。
感谢
UPDATE:
感谢你的答案我已经重写它像这样和现在的工作。
<?php
if($_GET['type'] == "first" && empty($_GET['step'])) {
header("Location: register.php?type=first&step=1");
//If user clicks on (<a href="register.php?type=first"></a>)
//show the content first registration
}elseif(empty($_GET['id']) && empty($_GET['type'])) {
header("Location: register.php?type=first&step=1");
//if user types in the address bar www.domain.co.uk/register.php
//redirect and show the content first registration
}elseif(isset($_GET['id']) && empty($_GET['step'])){
$product_id=$_GET['id'];
header("Location: register.php?id=".$product_id."&step=1");
//if the user clicks on <a href="register.php?id=<?php echo $row['product_id'] ?>"></a>
//show the content with the product information
}
?>
你总是要退出脚本,所以下面的代码不执行过程中(HTML) – Grumpy
@脾气暴躁好吧,问题是如果我退出它退出它继续与代码的其余部分是否有任何方法跳转到HTML在这一点上? –
@David Passmore你应该适当地嵌套if-elses,例如elseif或case。 – Quasdunk