简体   繁体   English

如何使用两个if条件php和java脚本

[英]how to use two if condition php and java script

I'm using this code and I get the JavaScript working with the URL and every thing is fine so 我正在使用此代码,并且使JavaScript与URL一起使用,一切都很好,因此

<?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. 如果尝试使用美国或英国的用户,要获得JavaScript的工作,我曾尝试过,但我对PHP感到很失望。

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. 如果我对您的理解正确,那么您只想向其IP检查显示来自英国或美国的用户显示一些内容。 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生成输出,因此可以将所有可能对某些用户隐藏的代码放入if语句中,并在else显示他们无法访问此内容:

<?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!";
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM