dealing with international traffic

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 539
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC

dealing with international traffic

Post by Vegan »

my site gets a lot of international traffic and right now I have US and UK ads available

so I was wondering, PHP switch seems like the obvious choice, then I can load the ad manager that is suitable for the visitor's local needs etc

I was considering new ideas but I am not sure about the best approach for a globalized site

Code: Select all

/*Get ip address*/  
  
$ip=$_SERVER['REMOTE_ADDR'];  
  
/* Now get ip details  with geoplugin.net      */  
  
$geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip;  
$unarr= file_get_contents($geopluginURL);     // Get File Contents   
$AddArr = unserialize($unarr);    // Get PHP values from file contents  
  
/* print_r($AddArr); */  // Print all the values  
  
$city = $AddArr['geoplugin_city'];  // City Name  
  
  
$country = $AddArr['geoplugin_countryName']; // Country Name  
  
$country_code = $AddArr['geoplugin_countryCode']; // Country Code  
  
$currency_code = $AddArr['geoplugin_currencyCode']; // Country Name  
  
$latitude = $AddArr['geoplugin_latitude']; // Latitude  
  
$longitude = $AddArr['geoplugin_longitude']; // Latitude  
  
  
echo '<strong>IP Address</strong>:- '.$ip.'  
';  
echo '<strong>City</strong>:- '.$city.'  
';  
echo '<strong>Country</strong>:- '.$country.'  
';  
echo '<strong>Country Code</strong>:- '.$country_code.'  
';  
echo '<strong>Currency Code</strong>:- '.$currency_code.'  
';  
echo '<strong>Latitude </strong>:- '.$latitude.'  
';  
echo '<strong>Longitude </strong>:- '.$longitude.'  
';  
  
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: dealing with international traffic

Post by Christopher »

Vegan wrote:PHP switch seems like the obvious choice
If you have something as structured as country codes, I would recommend using convention over code (like a switch statements). You can load the ad manager by either having database keys or file/folder names that use the country codes. That makes the system extensible by simply adding records or files/folders, rather than updating the code each time.
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: dealing with international traffic

Post by requinix »

Basically the code goes like

Code: Select all

$file = "/path/to/ads/{$country}/index.php";
if (!is_file($file)) {
	$file = "/path/to/ads/default/index.php";
}
include $file;
Using more PHP code gives you flexibility, or you use straight ad HTML or whatever for simplicity. Point is, you pick a filename, and if that thing doesn't exist then you use a default instead. Want to add stuff for a new country? Drop the files right in.
User avatar
Vegan
Forum Regular
Posts: 539
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC

Re: dealing with international traffic

Post by Vegan »

requinix wrote:Basically the code goes like

Code: Select all

$file = "/path/to/ads/{$country}/index.php";
if (!is_file($file)) {
	$file = "/path/to/ads/default/index.php";
}
include $file;
Using more PHP code gives you flexibility, or you use straight ad HTML or whatever for simplicity. Point is, you pick a filename, and if that thing doesn't exist then you use a default instead. Want to add stuff for a new country? Drop the files right in.
That looks like an easier way to get it done, another issue, how to deal with cultural issues, try to offer products that appeal to the local market

My vegan site is one that I am considering some new ideas, I noticed PHP has fairly good support for DBF files, which can be leveraged possible more easily than other contains I can think of
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: dealing with international traffic

Post by Christopher »

Vegan wrote:That looks like an easier way to get it done, another issue, how to deal with cultural issues, try to offer products that appeal to the local market
This kind of using convention to select based on a data point can load the appropriate code, but can also select the correct data. So you can access alternate data files as well.
Vegan wrote:My vegan site is one that I am considering some new ideas, I noticed PHP has fairly good support for DBF files, which can be leveraged possible more easily than other contains I can think of
Hopefully you are only using DBF files for read-only data, unless your site is has low traffic. I would recommend using a regular database server like MySQL. If you are most comfortable using Excel or Access, you might want to create a work flow to export your data to CSV, upload it to the server, and import using LOAD DATA INFILE for database updates. That would allow you to work in the programs you are comfortable with, but have the site use a real database server with record locking.
(#10850)
User avatar
Vegan
Forum Regular
Posts: 539
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC

Re: dealing with international traffic

Post by Vegan »

very little to no writes to the DBF file, 99.9% would be all read access

any writes would be a simple add to the table, however I see PHP does support PACK so at least I do not have to open FoxPro or other classic development tools

I was considering using a simple DBF to store recipes in, seems like an easy way to store them

Databases in the cloud are expensive, so I am looking to see what PHP can be leveraged to do

some databases I have are in Access format, so I have to figured out how to best leverage what I have
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: dealing with international traffic

Post by Christopher »

Vegan wrote:Databases in the cloud are expensive, so I am looking to see what PHP can be leveraged to do
You have hosting that does not include a database? Can't you get hosting these days for under $5 a month?

Also, SQLite might be a good option to look into.
(#10850)
User avatar
Vegan
Forum Regular
Posts: 539
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC

Re: dealing with international traffic

Post by Vegan »

I am considering mostly what I can do directly with PHP and JavaScript so that the site can be moved around easily. So any resource needs to be in the document root or a subfolder.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: dealing with international traffic

Post by Celauran »

MySQL is fairly ubiquitous so shouldn't pose a problem. An SQLite database would be stored as a file right in your project's directory structure, so should also be very portable. Just something to consider.
User avatar
Vegan
Forum Regular
Posts: 539
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC

Re: dealing with international traffic

Post by Vegan »

dBase tables are OK for my needs, a lot of the functionality needed is already intrinsic with PHP and I suspect it will remain useful as the old database is still a solid workhorse

Once I figure out some nutritional databases I have I was thinking of how best to leverage them which gets back to the recipes database, so clearly I need to consider a lot of options
Post Reply