开发者

How to Create a One Time Offer for Values Passed in PHP Form?

开发者 https://www.devze.com 2023-03-21 07:09 出处:网络
I have an interesting problem to solve here that may require some creative direction.I have a PHP page which has a variety of different page outcomes depending upon which value is passed through the w

I have an interesting problem to solve here that may require some creative direction. I have a PHP page which has a variety of different page outcomes depending upon which value is passed through the web browser. For example:

http://examplesite.com/landingpage.php?id=one
http://examplesite.com/landingpage.php?id=two
http://examplesite.com/landingpage.php?id=three

With the current set-up, each of these pages has a different offer for the site visitor. Here is the catch...

I only want the page available to the visitor once per session. That seems like it would be easy enough, but I cannot make it work right. I have used a one-time offer script to submit a cookie which then re-directs the user to another page if they have already viewed the offer, but that did not work for this situation. It will work fine for one landing page, but it is based on the root PHP page s开发者_C百科o if any of the other values are passed it will re-route the user even though they have not seen the offer.

For example, if a site visitor goes to:

http://examplesite.com/landingpage.php?id=one

they will see the one-time offer. Then, if they go to:

http://examplesite.com/landingpage.php?id=two

They will be re-routed as if they had seen the offer for 'two' which they had not.

I hope this issue makes sense. If you need further clarification, just ask. Thank you for going through my problem and if you don't have the exact answer, but can point me in the right direction it would be much appreciated.


Without looking at the code for landingpage.php, I can only guess that you are not factoring in the id when you check for the existence of the cookie. You need to set cookies on a per-id basis. Otherwise the behavior you see will occur: viewing id=one will set a cookie and when the user views id=two, landingpage.php sees the cookie exists and redirects the user.

If you want to keep it simple enough, you can just have your cookie be a string of id fields delimited with a character such as a pipe or comma: viewed_ids=one,two,three. Then you could parse this to see if the id of the current page is in the list of viewed ids and redirect the user if it is, or add it if it isn't.

I am sure you realize that maintaining state in the session can be easily worked around by the user, since you mentioned you only need this redirection to occur on a 'per-session' basis.

0

精彩评论

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