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