Results 1 to 8 of 8

Thread: hide some code by php.

  1. #1
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default hide some code by php.

    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

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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 Code:
    <?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.
    ?>
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default ok....

    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

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    There's no way to do this reliably. You will always be wrong sometimes. There are services and plugins (like geoplugin) 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.

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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?
    Corrections to my coding/thoughts welcome.

  6. #6
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    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

  7. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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 Code:
    <?php 
    if(!isset($_GET['hide'])) {
    include 
    'ga.html');
    }
    Corrections to my coding/thoughts welcome.

  8. #8
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    This sounds like a good idea!

    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •