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

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?

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
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']}";
?>

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/showthread.php?896348-Managing-Credits-In-Different-Currencies