Al Kasih
Al Kasih

Reputation: 886

Redirect after redirect

In my newsletter, I have some products there to represent to the members.

Saying that I have three products: Each product will have an unique token.

Product-One: href="index.php?username=klaudia&[email protected]&product=productOne"

Product-Two: href="index.php?username=klaudia&[email protected]&product=productTwo"

Product-Three: href="index.php?username=klaudia&[email protected]&product=productThree"

As we can see that all link will go to the index.php even though there is one string there which is different.

What is the aim of the index.php is TO GET the username and my email in order to set the SESSION letter. That's why all the link have to enter the index page.

Now, after it comes to the index page, I want it is redirected in no second based on the product name $_GET['product'];

Anybody can help me here? I hope it is clear what I am going to achieve here.

Upvotes: 1

Views: 44

Answers (1)

Fluffeh
Fluffeh

Reputation: 33542

You can create a landing page that looks for $_GET info, then redirects like this:

<?php

    session_start();
    if(!empty($_GET['username']))
    {
        $_SESSION['User']=$_GET['username'];
        header('Location: http://www.example.com/?product='.$_GET['product']);
        exit;
    }

?>

This has super basic checking, I would suggest adding more to it properly (that product isn't empty etc...)

Then you simply use the session on your redirected page while using whatever info you want off the GET request there.

Edit: Also, as Peehaa points out, an email address is best encoded before being passed to a URL.

Upvotes: 1

Related Questions