View Full Version : hide some code by php.
chetanmadaan
01-04-2011, 09:03 PM
Well -
guys... i need a way to put into the php file so that the php code is hidden by country.
i know i can block the whole country by .htaccess but, i need a part of it hidden for a particular country.
like php if county china
show nothing
else {code}
something like that???
Thanks
bluewalrus
01-04-2011, 09:14 PM
You can't do it completely. You could somewhat block direct access by attempting to navigate from their IP addresses origin but that won't always be accurate. A user also may access via a proxy or by being directed from some other source. Your PHP code also will always be hidden from all users regardless of where they are. I assume you are referring to the generated source.
<?php
if ($user_location == "China") {
$location = "china";
} else {
$location = "unknown";
}
echo "You've location is $location";
//You can assign other variables if the output will be the same at the end or output the full code in each condition and use an exit or die to stop the execution.
?>
chetanmadaan
01-04-2011, 09:18 PM
Well -
should i be consistent with the names of the country...
China
or china
or CHINA???
and if i leave the echo blank... nothing will appear... right??
Thanks
There's no way to do this reliably. You will always be wrong sometimes. There are services and plugins (like geoplugin (http://www.geoplugin.com/webservices/php)) that offer this sort of functionality, but they never know where a user actually is.
If accuracy is important, you should be using the Accept-Language HTTP header, or simply ask users to select their country from a list.
bluewalrus
01-04-2011, 09:22 PM
You can convert is using strtoupper or strtlower that won't be the hard part. Are you going to basing it off of the user's IP address, the user's input, or some other method?
chetanmadaan
01-04-2011, 09:24 PM
to be honest... i will just be hiding the google analytics part of the site for my own ip address... but, i run dead link check on site like daily and it fetches all the pages and shows like traffic is like doubled.
Thanks
bluewalrus
01-04-2011, 09:53 PM
Why not do it with an include than? Put the google analytics part in another file.
Then when you are checking load it like http://www.site.com/index.php?hide=1
in index.php whereever you had the google analytics tracker put in. Keep the script type caller in the file as well (<script type=">..................</script>).
<?php
if(!isset($_GET['hide'])) {
include 'ga.html');
}
chetanmadaan
01-04-2011, 10:01 PM
This sounds like a good idea!
Thanks
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.