我要做的是检查用户是否已登录,以便游戏可以加载播放。如果我不检查登录状态,但下面的代码中的else语句只显示一个没有任何内容的白页,页面有效。 else语句中的代码直接从Unity生成的html文件中复制。我是php和html的新手,所以我真的不知道我需要做什么改变才能使它在我当前的布局中工作,所以任何帮助都会非常有用。我知道else语句中的代码如果只是在一个单独的html文件中没有登录检查。
<div id="main">
<h3>Get started with your website</h3>
<ol class="round">
<li class="one">
<?php if(!logged_on()) { //This if statement works
echo '<li><a href="/logon.php">Please login to play</a></li>' . "\n";
}
else //This doesnt work
{
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity Web Player | Cool Ninja Platformer</title>
<script type='text/javascript' src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.min.js'></script>
<script type="text/javascript">
<!--
var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
if (document.location.protocol == 'https:')
unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
-->
</script>
<script type="text/javascript">
<!--
var config = {
width: 960,
height: 600,
params: { enableDebugging:"0" }
};
config.params["disableContextMenu"] = true;
var u = new UnityObject2(config);
jQuery(function() {
var $missingScreen = jQuery("#unityPlayer").find(".missing");
var $brokenScreen = jQuery("#unityPlayer").find(".broken");
$missingScreen.hide();
$brokenScreen.hide();
u.observeProgress(function (progress)
{
switch(progress.pluginStatus)
{
case "broken":
$brokenScreen.find("a").click(function (e)
{
e.stopPropagation();
e.preventDefault();
u.installPlugin();
return false;
});
$brokenScreen.show();
break;
case "missing":
$missingScreen.find("a").click(function (e)
{
e.stopPropagation();
e.preventDefault();
u.installPlugin();
return false;
});
$missingScreen.show();
break;
case "installed":
$missingScreen.remove();
break;
case "first":
break;
}
});
u.initPlugin(jQuery("#unityPlayer")[0], "game.unity3d");
});
-->
</script>
<style type="text/css">
<!--
body {
font-family: Helvetica, Verdana, Arial, sans-serif;
background-color: white;
color: black;
text-align: center;
}
a:link, a:visited {
color: #000;
}
a:active, a:hover {
color: #666;
}
p.header {
font-size: small;
}
p.header span {
font-weight: bold;
}
p.footer {
font-size: x-small;
}
div.content {
margin: auto;
width: 960px;
}
div.broken,
div.missing {
margin: auto;
position: relative;
top: 50%;
width: 193px;
}
div.broken a,
div.missing a {
height: 63px;
position: relative;
top: -31px;
}
div.broken img,
div.missing img {
border-width: 0px;
}
div.broken {
display: none;
}
div#unityPlayer {
cursor: default;
height: 600px;
width: 960px;
}
-->
</style>
</head>
<body>
<p class="header"><span>Unity Web Player | </span>Cool Ninja Platformer</p>
<div class="content">
<div id="unityPlayer">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
<img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
</a>
</div>
</div>
</div>
<p class="footer">« created with <a href="http://unity3d.com/unity/" title="Go to unity3d.com">Unity</a> »</p>
</body>
</html>
}
?>
</li>
</ol>
</div>
答案 0 :(得分:1)
作为替代方法,您可以让Unity游戏本身检查您的站点服务器的身份验证状态。这可以说是优越的,因为只要页面没有重新加载,统一播放器就会在php会话可能已经过期后继续运行。
见Unity Web Player and Browser Communication。
作为附带好处,您现在已经在游戏中实施了DRM。祝贺。
答案 1 :(得分:0)
在尝试使用echo
打印显式HTML之前,必须使用?>
关闭php代码块。在做更多PHP代码之前,你必须再次打开它<?php
。
另一个问题是,您需要<!DOCTYPE html...
成为网页的第一行行。所以上面有<div id="main">
等等就会引起一个大问题。所以总是把它放在最顶端。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
if(!logged_on())
{
echo '<li><a href="/logon.php">Please login to play</a></li>' . "\n";
}
else
{
?>
<head>
all whatever html you want to have explit
<?php
}
?>