开发者

Can I header redirect to mutiple URL's or use a variable to do so?

Here is what I want to do. At the moment I have 3 sign up pages. 2 for affiliates and 1 for members who happens to wonder into the site. The issue I had was that when the affiliates would send members if the members left their join form and ended up at the main join form for the site which is my join form...then the affiliates would not get credit for the sale.

To fix this I created a cookie on the two affiliate join forms. Now if they visit the affiliate join form first...the cookie is created...then if they wonder the site and end up clicking the Register link for my join form...it redirects them to the affiliates join for that they came to the site on.

This works fine but I have no way to make both join forms redirect without getting the "header already sent" message.

What I have is this:

<?php // find the ip address cookie, if its set, redirect
if (isset($_COOKIE["ipaddress"])) {
    // redirect
    header ('Location: usersignupcredit.php');
} 
?>
<?php echo((isset($_COOKIE["ipaddress"]))?$_COOKIE["ipaddress"]:"") ?>

What I need is something like this that works

<?php // find the ip address cookie, if its s开发者_JS百科et, redirect
if (isset($_COOKIE["ipaddress"])) {
    // redirect
    header ('Location: page1.php');
}
if (isset($_COOKIE["ipaddress2"])) {
    // redirect
    header ('Location: page2.php');
?>
<?php echo((isset($_COOKIE["ipaddress"]))?$_COOKIE["ipaddress"]:"") ?>

So it would look for both cookies ipaddress and ipaddress2

If ipaddress is found then it would send to page1.php If ipaddress2 is found then it would send to page2.php

Any help would be appreciated.


I'd think about the design for a second - why do you need to have 3 forms? Isn't it cleaner to just have 1 form and take the affiliate variable through GET and store that in a cookie?

For example, a member visits your page through /join.php?aff=<aff-id>, the affiliate with aff-id gets credited for the signup. If a member visits your page simply as /join.php, nobody gets credit.

Seems simpler and more straight-forward if you ask me.

PS: If you don't want ?aff to mean the obvious, rename it to some obscure variable, most regular users won't even notice it.


If you receive a headers already sent message, the most likely problem is that your are outputting stuff to the browser before the header command. You need to make sure that you don't echo anything or have any spaces or new-lines outside of your php tags before the part where you use header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜