Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Cookies and redirection

Cookies and redirection

Locked

Views: 1,430

Results 1 to 5 of 5
This thread is locked. New replies are disabled.
11 Feb 2007, 11:42 AM
#1
kusogaki avatar

kusogaki

New Zenner

Join Date:
Feb 2006
Location:
San Diego, CA
Posts:
28
Plugin Contributions:
0

Cookies and redirection

Due to the nature of the material on my e-shop, I have a disclaimer at the beginning of the store (the actual store is in a subdirectory from the root directory) that people have to click through before entering. However, since google has indexed the site, I want to make sure people see the disclaimer before hopping on in.

To solve this problem, I figured I would use cookies to do the trick. The front page (with disclaimer) is an html page with a simple yes or no hyperlink. Well, there's more text than that but let's keep it at that for simplicity. Clicking yes to enter will send a value to the next page...which would be the store's index.php page:

./shop/index.php?input=some_value

That value is transmitted to the index.php page and a check is made to see that a value was sent to the page. If it is true, a cookie is set to allow the user regular access. If the user dropped in via a specific link to a product or section of the site and thus has not had the chance to send a value to index.php, the check will not set a cookie and send the user back to the beginning.

This sound straight forward and all, but I'm not sure how I would do the redirection if in the second situation. I guess because of what is loaded prior to getting to the index page, I can't use the header() function for redirection as it's already been called...or something like that. Unfortunately, my weak php skills is not helping me here. Is there another way to accomplish this?

Chris

11 Feb 2007, 12:02 PM
#2
kusogaki avatar

kusogaki

New Zenner

Join Date:
Feb 2006
Location:
San Diego, CA
Posts:
28
Plugin Contributions:
0

Re: Cookies and redirection

Okay, I think I might have solved my own problem. Using javascript, you are also able to utilize redirection:

<script type="text/javascript"> <!-- window.location = "some_other_page.php" //--> </script>

Throw that in a php echo statement and it's good to go. The only thing now is that I've only tested this on dummy pages so I don't know if the zc code is going to get angry if I put that stuff in the index page.

Also, it seems a bit "inelegant" to show the value being sent on clicking on the link in the beginning so if someone has a better way to do this I'm all ears. :)

Chris

11 Feb 2007, 2:20 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Cookies and redirection

You could set a session variable that when the customer hits the site for the first hit, since the session variable is not set it would do the disclaimer thing ... and then the session variable gets set so that now the disclaimer is ignored as the customer has already seen it ...

11 Feb 2007, 11:39 PM
#4
kusogaki avatar

kusogaki

New Zenner

Join Date:
Feb 2006
Location:
San Diego, CA
Posts:
28
Plugin Contributions:
0

Re: Cookies and redirection

Hmm, that sounds like a good idea. However, I ran into a bit of a roadblock...

First, I added a setcookie() line and a line to set a variable...let's say $_SESSION['verify'] = 1; in the root index page.

On the shop's index page I added my sessions checking mechanism:

if ($_SESSION['verify'] == 0) // check to see if it exists {
// javascript code from earlier to redirect back to the front
}

But nothing happened. I thought it might have been an out of scope issue since I had the session start in the root directory and the check in a subdirectory where the shop resides. I then did a quick check to verify that I could see the value by calling session_start(); in the shop's index page and it worked...but then I got an error:

Warning: Cannot modify header information - headers already sent by (output started at /home/"username"/public_html/shop/index.php:26) in /home/"username"/public_html/shop/includes/init_includes/init_templates.php on line 78

Am I completely missing something here? I'm a bit baffled, but hopefully I can brute-force some working code out of this.

Thank you for the suggestion though. I just hope I make a working solution. :)

Chris

12 Feb 2007, 12:10 AM
#5
kusogaki avatar

kusogaki

New Zenner

Join Date:
Feb 2006
Location:
San Diego, CA
Posts:
28
Plugin Contributions:
0

Re: Cookies and redirection

Odd...after reshuffling the code block around, I put it back and it seemed to work...until I flushed cookies from the browser and tried it again. I got this error by itself:

Fatal error: Call to a member function on a non-object in /home/"SITE_NAME"/public_html/shop/includes/autoload_func.php on line 90

Hmm...