简体   繁体   中英

PHP Compatibility Check Inside HTML

Is there anyway I can use this code inside a html file?

I have tried everything possible and can't seem to get it to work...

Any help would be greatly appreciated.. Thanks!

$isUDIDProtected=TRUE;
$compatibleVersions=array("8.1.1","8.1","8.0");

I was the top code for each php file

if ($isUDIDProtected)
{
        echo "<p style=\"color: red;\">This package is UDID protected! You must have your device registered to download this package</p>";
    }

    if ($compatibleVersions) 
{
        $uaString = $_SERVER["HTTP_USER_AGENT"];
        if (preg_match("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/", $uaString)) {
            $version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/","$2.$3.$4", $uaString);
        } else if (preg_match("/(.*) OS ([0-9]*)_([0-9]*) (.*)/", $uaString)) {
            $version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*) (.*)/","$2.$3", $uaString);
        }
        if ($version) {
            if (in_array($version, $compatibleVersions)) {
                echo "<p style=\"color: green;\">This package is compatible with your iOS version :)</p>";
            } else {
                echo "<p style=\"color: #FFCC00\">This package is not comfirmed to work on your iOS version</p>";
            }
        }
    }

The html file is below

<ul data-role="listview" data-inset="true">
<li data-role="list-divider"><center>Compatibility</center></li>
<li><center>(show yes or no)</center></li>
</ul>

您需要根据是否构造情况,在html代码中的php打开和关闭标签下添加php代码。

Your code is PHP code. It won't work inside an "html" file. You need to place it inside a PHP file (with corresponding php tags) and run it through the server. Being said this, you could have a "compat.php" file with the code:

$compatibleVersions=array("8.1.1","8.1","8.0");

    if ($compatibleVersions) 
{
        $uaString = $_SERVER["HTTP_USER_AGENT"];
        if (preg_match("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/", $uaString)) {
            $version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/","$2.$3.$4", $uaString);
        } else if (preg_match("/(.*) OS ([0-9]*)_([0-9]*) (.*)/", $uaString)) {
            $version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*) (.*)/","$2.$3", $uaString);
        }
        if (isset($version) && in_array($version, $compatibleVersions)) {
           echo "<p style=\"color: green;\">This package is compatible with your iOS version :)</p>";
        } else {
           echo "<p style=\"color: #FFCC00\">This package is not comfirmed to work on your iOS version</p>";
        }
    }

Then, inside another file "htmlPage.php", something like:

<?php 
$isUDIDProtected=TRUE;
if ($isUDIDProtected)
{
        echo "<p style=\"color: red;\">This package is UDID protected! You must have your device registered to download this package</p>";
die();
    }
?>
<ul data-role="listview" data-inset="true">
<li data-role="list-divider"><center>Compatibility</center></li>
<li><center><?php include "compat.php" ?></center></li>
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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