SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Let user set currency?

    I've googled this but can't seem to find anything. Basically i want the user to be able to select their currency. I have clickable flag images and when clicked it needs to set a session variable or cookie or something? I then need to be able to use the value selected around the site.

    Can anyone point me in the right direction for this?

    Thanks

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    You'll most likely want to store their preference in the user table, so that it is stored for their next visit. You'll need a table that stores conversion rates. What type of site is this? Online store?

  3. #3
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Atlanta, GA
    Posts
    244
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Just make the link on each flags set a querystring variable for each currency, IE: http://www.yoursite.com/index.php?currency=eur

    Then:
    PHP Code:
    <?php
    session_start
    ();

    $supported_currencies = array('USD''EUR''GBP');

    if ((isset(
    $_GET['currency'])) && ($_GET['currency'] != ''
            && (
    array_search(strtoupper($_GET['currency']), $supported_currencies) !== false)) {
        
        
    $_SESSION['currency'] = strtoupper($_GET['currency']);

    } else {
        
    $_SESSION['currency'] = 'USD'// Set a default
    }

    // Then, later on if you want to grab the selected currency

    echo "The current currency is: {$_SESSION['currency']}";
    ?>

  4. #4
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Atlanta, GA
    Posts
    244
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    You'll need a table that stores conversion rates
    I would advise against this. Conversion rates change frequently .. sometimes a few times a day. It would be better to grab the live data from an external exchange rate API. It's pretty easy to do. Check out the thread at: http://www.sitepoint.com/forums/show...ent-Currencies


Bookmarks

Posting Permissions

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