1

I'm using this code and I get the JavaScript working with the URL and every thing is fine so

<?php

// Settings to generate the URI
$secret = "P4ss#w0rD";                  // Same as AuthTokenSecret
$protectedPath = "/media/videos/mp4/";  // Same as AuthTokenPrefix
$ipLimitation = true;                   // Same as AuthTokenLimitByIp
$hexTime = dechex(time());              // Time in Hexadecimal
//$hexTime = dechex(time()+120);        // Link available after 2 minutes

$filee = basename($_GET['f']);          // The file to access
$fileName = "/$filee";                  // The file to access

// Let's generate the token depending if we set AuthTokenLimitByIp

if ($ipLimitation) {
  $token = md5($secret . $fileName . $hexTime . $_SERVER['REMOTE_ADDR']);
} else {
  $token = md5($secret . $fileName . $hexTime);
}

// We build the url

$url = $protectedPath . $token. "/" . $hexTime . $fileName;

?>
<script type="text/javascript" src="/kt_player/kt_player.js"></script>

<div id="kt_player" style="visibility: hidden">
    <a href="http://adobe.com/go/getflashplayer">This page requires Adobe Flash Player</a>
</div>

<script type="text/javascript">
var flashvars = {
    hide_controlbar: '1',
    hide_style: 'fade',
    preview_url: 'http://www.kernel-video-sharing.com/kt_player/poster.jpg',
    bt: '5',
    video_url: 'http://7.7.7.7<?php echo $url; ?>',
    video_url_text: '720p'

};

var params = {allowfullscreen: 'true', allowscriptaccess: 'always'};
kt_player('kt_player', '/kt_player/kt_player.swf', '854', '480', flashvars, params);
</script>

I want to add this code to it:

<?php 

$user_ip = $_SERVER['REMOTE_ADDR'];
$res = file_get_contents("http://ipinfo.io/${user_ip}/country");
$country = trim($res);
if (in_array($country, array("US", "UK"))) {
    echo "hello us and uk";
} else {
    echo "";
} 

To get the JavaScript work if the user in US or UK I tried but I'm very poor with PHP.

1 Answer 1

2

If I understood you correctly, you want to display some content only to the users that their IP check says they are from the UK or the USA. Since you are generating your output in PHP, you may put all the code that might be hidden from some users inside the if statement, and in else print that they cannot access this content:

<?php

// Settings to generate the URI
$secret = "P4ss#w0rD";                  // Same as AuthTokenSecret
$protectedPath = "/media/videos/mp4/";  // Same as AuthTokenPrefix
$ipLimitation = true;                   // Same as AuthTokenLimitByIp
$hexTime = dechex(time());              // Time in Hexadecimal
//$hexTime = dechex(time()+120);        // Link available after 2 minutes

$filee = basename($_GET['f']);          // The file to access
$fileName = "/$filee";                  // The file to access

// Let's generate the token depending if we set AuthTokenLimitByIp

if ($ipLimitation) {
  $token = md5($secret . $fileName . $hexTime . $_SERVER['REMOTE_ADDR']);
} else {
  $token = md5($secret . $fileName . $hexTime);
}

// We build the url
$url = $protectedPath . $token. "/" . $hexTime . $fileName;

// check the country
$user_ip = $_SERVER['REMOTE_ADDR'];
$res = file_get_contents("http://ipinfo.io/${user_ip}/country");
$country = trim($res);

// show content only to the users in the UK or USA
if(in_array($country, array("US", "UK"))) { ?>
    // your javascript code - make sure to check if this is right
    <script type="text/javascript">

    var flashvars = {

        hide_controlbar: '1',

        hide_style: 'fade',

        preview_url: 'http://www.kernel-video-sharing.com/kt_player/poster.jpg',

        bt: '5',

        video_url: 'http://7.7.7.7<?php echo $url; ?>',
        video_url_text: '720p'

    };

    var params = {allowfullscreen: 'true', allowscriptaccess: 'always'};

    kt_player('kt_player', '/kt_player/kt_player.swf', '854', '480', flashvars, params);

</script><?php
} else {
    echo "You are not allowed to view this content!";
} 
Sign up to request clarification or add additional context in comments.

6 Comments

thank you , do you mean to add your code to the first code
First of all you should understand what is written there. Then you may add the if statement to your code, I did not change anything before if (in_array... part
In your first code block you replace the whole <script></script> tag with my code and it should do what you ask. Don't forget to add <?php ?> where needed
sorry i tried but not working can you please edit your answer with the full code
I merged two of your code blocks with mine. Try this
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.