无论如何我可以在html文件中使用这段代码吗?
我已经尽了一切努力,似乎无法让它发挥作用......
非常感谢任何帮助..谢谢!
$isUDIDProtected=TRUE;
$compatibleVersions=array("8.1.1","8.1","8.0");
我是每个php文件的顶级代码
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>";
}
}
}
html文件位于
之下<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>
答案 0 :(得分:1)
你需要根据if else构造情况在html代码中的php开启和关闭标签下添加php代码。
答案 1 :(得分:1)
您的代码是PHP代码。它不会在&#34; html&#34;内部工作。文件。您需要将其放在PHP文件中(带有相应的php标记)并通过服务器运行它。 说到这里,你可以得到一个&#34; compat.php&#34;文件包含代码:
$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>";
}
}
然后,在另一个文件&#34; htmlPage.php&#34;里面,像:
<?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>