Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    San Diego, CA
    Posts
    29
    Plugin Contributions
    0

    Default 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

  2. #2
    Join Date
    Feb 2006
    Location
    San Diego, CA
    Posts
    29
    Plugin Contributions
    0

    Default 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

  3. #3
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default 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 ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  4. #4
    Join Date
    Feb 2006
    Location
    San Diego, CA
    Posts
    29
    Plugin Contributions
    0

    Default 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

  5. #5
    Join Date
    Feb 2006
    Location
    San Diego, CA
    Posts
    29
    Plugin Contributions
    0

    Default 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...

 

 

Similar Threads

  1. v151 zenid and cookies
    By luckystu in forum General Questions
    Replies: 4
    Last Post: 26 Mar 2014, 02:48 PM
  2. v137 Redirection and duplicity of webpage
    By PK76 in forum General Questions
    Replies: 3
    Last Post: 1 Dec 2012, 09:36 PM
  3. UK Legislation and Cookies?
    By tsrplatelayer in forum General Questions
    Replies: 22
    Last Post: 11 Jun 2012, 02:33 PM
  4. Sessions and cookies
    By FreeArticlePublishin in forum Bug Reports
    Replies: 1
    Last Post: 29 Nov 2010, 02:58 AM
  5. Cookies Log In and PayPal
    By Garby in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 5 Jul 2009, 03:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg