Guys, I need to show Country Specific ads to the users of my website. This works well intially when i am able to get the users Ip address and get the Country Code and set a session variable to that country and use that variable to show ads for that country. But I also have flags (links) on my website for each country the user could go to and browse that countrys items. How do i reset the session variable at that time to the exact flag that the user has clicked. Here is what i have until now <?php // index.php session_start(); require_once('ip.php'); //this variable below is set in ip. php $_SESSION['country'] = based on the users country; //then somewhere in the index.php i have images with href <a href="index.php" target="_self"><img src="images/UK.png" />UK</a> // how do i reset the $_SESSION['country'] = based on what the user has selected; PHP:
You could set two session variables user_country selected_country So when a user clicks on the different flag, set the session variable for selected country. Now when you display ads, make a if else statement if (isset($_SESSION['selected_country']) && ($_SESSION['selected_country']!='') ) { // Show this country ads } else { // User Country ads }
thank you mac83 thank makes sense the only problem now i have is how to set the session variable on the click of the hyperlink, if a sample code is provided that will be good.
Your Link: echo '<a href="'.$_SERVER['PHP_SELF'].'?selected_country=UK" target="_self"><img src="images/UK.png" />UK</a>' PHP: On the top of the page: if ( isset($_GET['selected_country'])&&($_GET[$_GET['selected_country']]!='') ) { $_SESSION['selected_country'] = $_GET['selected_country']; } PHP: