Search code examples
phpregistrationredirect-loop

PHP Registration Problem


I am programming a php registration system where there is two points of entry (if that makes sense):

  1. If the client wants to purchase a product but doesn't have an account and it stores the id of the product all the way through the registration process. Then it allows to process the payment after registration.

  2. The client is registering first time without trying to purchase the product.

These are the links directing the user to the registration pages for the two methods above:

1. <a href="register.php?id=<?php echo $row['product_id'] ?>"></a>
2. <a href="register.php?type=first"></a>

This is the code for the file 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>

The problems are:

  1. When using the 1st method above the php says it has a redirect loop and i can't seem to work it out. Once we have this working i want is to show the content but this leads on to the second problem.

  2. When using the second method it works and shows the content for first registration but it doesn't show any of the html content below this code.

Any help would be appreciated.

Thanks

UPDATE:

Thanks to your answers i have rewritten it like this and it works now.

<?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

}
?>

Solution

  • His update will work

    <?php
    if($_GET['type'] == "first" && empty($_GET['step'])) {
        header("Location: register.php?type=first&step=1");
    
    
    }elseif(empty($_GET['id']) && empty($_GET['type'])) {
        header("Location: register.php?type=first&step=1");
    
    
    }elseif(isset($_GET['id']) && empty($_GET['step'])){
        $product_id=$_GET['id'];
        header("Location: register.php?id=".$product_id."&step=1");
    
    }
    ?>
    

    Because it is what i have worked out myslf