PHP - Country Specific Website
same with trivago Welcome to www.trivago.com. trivago is available locally: Continue to trivago Australia or Stay on www.trivago.com Hello from the UK! We want to make sure you get to the right place, and noticed you appear to be visiting us from Australia. If you would prefer to visit our Australian site, please just follow the link below. Go to our Australian site comparethemarket.com.auhi professionals I was not sure where to exactly post this as I am not to sure if it is a php question. We are developing a new website for another country and are looking to geo target people with the country in mind for instance if I visit comparethemarket .com or comparethemarket uk from here in Australia a pop up window appears saying the following Similar TutorialsI am trying to invert some arrays, making the x-values y, and the y-values x. I have found the code that works, but I cannot understand for the life of me, I have a multidimensional $data array; that looks like this: Code: [Select] row:0 :: Country:Algeria row:1 :: Country:USA row:2 :: Country:Morocco The following code successfully extracts the appropriate 'column' from my array. Code: [Select] foreach($data as $value){ $invert['country'][] = $value['country']; } It returns: Code: [Select] $invert['country'] = Algeria, USA, Morocco But this makes no sense, it seems more logical that the code should be: Code: [Select] foreach($data as $value){ $invert[] ['country']= $value['country']; } Since we are accepting all values of the first array, and then specifying the second array. What am I missing here? Why is it working backwards? I am wondering if it's possible to get some data from another website via PHP? I would like to get data from website http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier, and the exact data which I need is "Level" which is in this case 2. Can this value be grabbed and if it can, where can I get some info about how to do it? I am following along in a PHP, MySQL book and the way they clear session variables is by: Code: [Select] session_start(); session_unset(); session_destroy(); They clear session variables like that in that exact order. My question is that this apparently clears ALL session variables for the browser in use. Every website I have visited when you click a LOGOUT button ONLY logs you out of their specific site and DOES NOT seem to clear ALL session variables as this would log you out of any other websites that you might be logged into with that same browser. So, I went to the PHP website and found out that instead of using the session_unset () function you can clear individual session variables using the unset ($_SESSION['varname']) function. Is this a good way of clearing session variables ONLY for a PARTICULAR website and NOT clearing session variables for the WHOLE browser? If so, would I then NOT use the session_destroy () function after clearing each individual session variable specific to that ONE website using unset ($_SESSION['varname'])? Thank you in advance! Hello first time poster here . Soni have been in the proccess of designing a website that would give images to users . But only owner of an image will get thier own image . And some people may not access thier image whom are invalid untill i make them valid users. Si.my problem is i want to stop people from accessing these images by typing thier mysite.com/path and these files only be accessable via a php that is in my website . How do i go about doing that . Is it iam my new to this or there is not a convenient way to do this . Thanks in advance I have this code, its working pretty fine until i insert "echo "$ipDetail['country']";" to get the converted ip to name its origin Code: [Select] <?php $ip=$_SERVER['REMOTE_ADDR']; function countryCityFromIP($ipAddr) { //function to find country and city from IP address //Developed by Roshan Bhattarai http://roshanbh.com.np //verify the IP address for the ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : ""; $ipDetail=array(); //initialize a blank array //get the XML result from hostip.info $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr); //get the city name inside the node <gml:name> and </gml:name> preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match); //assing the city name to the array $ipDetail['city']=$match[2]; //get the country name inside the node <countryName> and </countryName> preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches); //assign the country name to the $ipDetail array $ipDetail['country']=$matches[1]; //get the country name inside the node <countryName> and </countryName> preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match); $ipDetail['country_code']=$cc_match[1]; //assing the country code to array //return the array containing city, country and country code return $ipDetail; }$ipDetail="countryCityFromIP('12.215.42.19')"; echo "<b>IP Address= $ip</b> "; echo "$ipDetail['country']"; ?> this is the error Code: [Select] Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/GGME/public_html/addons/iptest.php on line 25 I use the Wholesale Suite Premium Prices plugin with WooCommerce. I have 6 specific wholesale roles out of 15 that I wish to hide two specific shipping methods from being selected for the 6 exceptions. I'm just trying this on my staging server at this time using a code snippet example that I found and modified for my specific conditions. Would the following work for this purpose? /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array( 'ws_silvia_silver' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles) ) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; }); Any insights as to how to accomplish this would be greatly appreciated. Lyse This script should detect what contry a visitor is from via there IP and display there contrys flag. However it does not work, please could you take a look and let me know if there are any obviouse errors as im stumped. Code: [Select] <?php $IPaddress=$_SERVER['REMOTE_ADDR']; $two_letter_country_code=iptocountry($IPaddress); Print "$IPaddress" include("IP_FILES/countries.php"); $three_letter_country_code=$countries[ $two_letter_country_code][0]; $country_name=$countries[$two_letter_country_code][1]; print "Two letters code: $two_letter_country_code<br>"; print "Three letters code: $three_letter_country_code<br>"; print "Country name: $country_name<br>"; // To display flag $file_to_check="flags/$two_letter_country_code.gif"; if (file_exists($file_to_check)){ print "<img src=flags/$file_to_check width=30 height=15><br>"; }else{ print "<img src=flags/noflag.gif width=30 height=15><br>"; } function iptocountry($ip) { $numbers = preg_split( "/\./", $ip); include("ip_files/".$numbers[0].".php"); $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]); foreach($ranges as $key => $value){ if($key<=$code){ if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} } } if ($two_letter_country_code==""){$two_letter_country_code="unkown";} return $two_letter_country_code; } ?> Thanks in Advance, Monk3h. Hi all Got a problem that seems simple, but I fail to solve it. Anybody who can help with country array? Right now the following code is active, which limits the available country to US only, for a certain language/area selection. It works fine. I would now only like to include an additional country (CA) as a choice besides US for the same language/area selection (without changing the language/area selection). If anyone knows the trick pls help. Existing Code:
if( !function_exists('filter_woocommerce_countries_shipping_countries') ) {
I have the product catalog/shopping cart. I need to modify the registration so that it allows the customer to complete the form but then takes him to a message telling him who to contact based on the country he enters during registration. Maybe an if country=A go to... If country=B go to... else go to... Hello I am trying to show/geo target content for certian countries that my visitors to my site are from. I have doing a little research on google and have found a few script but for some reason they do not work. I know about the geoip database from maxmind but I am looking for a remote solution as the geoip database is said to be a heavy strain on servers if you get a lot of visitors. I am hosted on a shared server so I do not want to get my account suspended for over working the server. Also I have a few sites that will use this idea. This is a script I found whilst googling and all it does is give me an error. Code: [Select] <?php $ip = $_SERVER [ 'REMOTE_ADDR' ]; $country = file_get_contents ( 'http://api.hostip.info/country.php?ip=' . $ip ); if ( $country == "US" ) { echo "<American-English Ringtone Ad Tag>" ; } elseif ( $country == "AU" OR $country == "UK" OR $country == "IE" ) { echo "<British-English Ringtone Ad Tag>" ; } else { echo "<YPN Ad Tag>" ; } ?> This is the error it gives me:- Quote Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/username/public_html/webaddress.co.uk/test/test.php on line 7 What I am trying to do is to geo target Javascript ads for different countries. When I add the javascript ad it gives me that error. If I just put in normal text then it works ok. Thank you all for your help in advance. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=353007.0 Okay we are using a javascript, but the javascript that the site comes from has bans all irans ips... and it loads slow for those people, how would I place a if statement saying dont load this javascript if in Iran, thanks... I know how to do it, but I can't find a real set number, and I would use just 1 ip but the guy has dynamic... thanks ahead of time I'm trying to block access to a particular page if the visitor is not from a specific country (using Maxmind Geoip Country database), but not quite sure how to code this properly: I tried this and many variations of this inside the head tags, bud doesn't work. Any suggestions on the best way to go about this? Code: [Select] <?php require_once("geoip.inc"); $gi = geoip_open("/home/username/GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if($country_code !== 'US') header("HTTP/1.0 404 Not Found"); exit; ?> Hi, I have a search form where users can search by age and country. Users can also save their search so they can go back and do it again but the problem is when they reload their saved search, I need it to select the country that has been saved in the drop down. So if someone searched the United Kingdom, I need it to show United Kingdom in the select drop down instead of (Select Country). Is there any easy and quick way around this? Many Thanks This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=359083.0 hey guys just wondering what u think the best way to do this.....on my form registration for users....I have a drop down for countrys....but I dont want to have 2 drop downs 1 for state and 1 for province if they choose canada/usa....I have seen alot of java scrit on such sites where if you choose Canada for country, then it switches to a drop down for just provinces, not states. Same for zip code/postal code...american zip code would be like 90210 where as a postal code would be like n5j2S1. Is there a script or something already I can use with all the countrys/provinces/states etc already entered so im not re-inventing the wheel here? If someone can point me in right directon id appreciate it. Thanks This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=345840.0 I'm trying to make a League of Legends (a video game) community website, both as a personal project and for practice. Now the game has a lot of champions, each of whom have 5 unique abilities. Now, I thought about manually inputting all the details about each champion into a MySQL database, but that would long and tedious, and I don't really have the time for it now. Also, the game patches very oftern (like, once every 2 weeks) which changes many of the stats, etc. of the champion, and it is not possible for me to keep manually updating these every time there is a patch. Fortunately, there is a League of Legends Wiki which has all the data I need in their specific champion pages, which they keep updated per patch. So I was wondering if there was any way to get the data from the divs in the wiki, and have it display on my site. What I want to do in my website is that whenever someone types a champion's name (in a post or whatever), I want it to display a hover-over dialog with some of the champions details. And a lot of other features such as that. In plain English I need a way to : > Tell PHP to go to the wiki's source code on a specific page > Find a specific div container > Get X data from there > Pass X data into a function to display the hover-over I think this way, I would not have to maintain a database as I can leech off the wiki's data. I have not coded anything like this before, so I would like a few pointers as to how to achieve this. Any help will be appreciated! |