PHP:设置变量以获取值
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定 if ($name=="*") 的作用是什么,但我会使用
它来检查名称是否传递到 url。
I'm not sure what the if ($name=="*") does, but I would use
instead, to check if the name was passed to the url.
我假设
$_GET['name'] == "*"
你混淆了一些东西。在这种情况下,它只是一个字符串比较。*
不是与 SQL 中的任何内容相匹配的通配符。如果你想检查$_GET['name']
中是否有内容,可以使用 空 或 isset< /a>.此外,我建议您只检查
name
,因为您的所有参数在概念上都属于游戏。如果没有名称
,就没有描述
,也没有说明
。但无论你做什么,一定要清理你要输出的参数,否则迟早有人会提供这个或类似的名称:
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 noname
, there will be nodescription
and noinstructions
.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: