Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member Richard S's Avatar
    Join Date
    Jul 2004
    Location
    SW Lonodn
    Posts
    219
    Member #
    6728
    Liked
    3 times
    Hi I'm building a simple shoping cart system using PHP and MySQL.

    I'm using a Cookie set to a unique "customer number" to act as a refernce to the items they have stored in the 'basket' table.

    The cookie is set to expire after a week so poeple can come back to the cart and have there items stored, without having to login or set up a account.

    Below is the code I use to check for the Cookie, if it's not set they get a number which is stored in the cookie and in the 'Customers' table.

    PHP Code:
    <?
    if (!isset($_COOKIE['cust_no']))
        {
            
    $week =(36000 24) * 7;

            
    mysql_connect ("localhost""*******""*********") or die ('I cannot connect to the database because: ' mysql_error());
            
    mysql_select_db ("******_*****");
            
    $no_cust_sql "SELECT * FROM customers";
            
    $result=mysql_query($no_cust_sql);
            
    $rows mysql_numrows($result);
            
    $value $rows 1;
            
            
    $sql "INSERT INTO `customers` ( `index` , `date` ) 
                    VALUES ( 
    $value , CURDATE( ) )";
            
    mysql_query($sql);
            
            
    setcookie("cust_no"$valuetime()+$week"/cooper3/",".rrss.co.uk") or die("Could not set cookie");
            echo 
    "This is your first visit here today.";//this here just for debuging
            
    mysql_close();
        }
    else
        {
            echo 
    'welcome back '.$_COOKIE['cust_no'];//this here just for debuging
        
    }
    ?>
    Works great in Firefox just as it should, but is very odd in IE.

    The trouble is the first time you leave the shoping page, then return the cookie dosn't show up, however clicking 'refresh' or clicking to buy another product suddenly kicks the cookie back in to action and it then works perfectly.

    This is realy anoying. Not a major problem, becasue if you do refresh it works again. But I'd realy like to find a solution.

    Thanks in advance.

  2.  

  3. #2
    Senior Member Richard S's Avatar
    Join Date
    Jul 2004
    Location
    SW Lonodn
    Posts
    219
    Member #
    6728
    Liked
    3 times
    LOL,

    Problem solved.


    It was nothing to do with Cookies (which I've spent the last three hours playing with).

    The problem was caused by IE caching pages, so when you left the page and then returned, you where returning to the page cached before the new items where added. There is a setting in 'Internet Options' to control where pages are loaded from, I had it set to Automatic and it was causing problems.

    IE seems to see a page such as:

    buy.php

    to be completly different from

    buy.php?add=1

    Anyway, I've got round it by using a Meta tag to tell IE not to cache the page at all.

    HTML Code:
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:38 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com