|
Posted by David Haynes on 04/06/06 15:59
The Numerator wrote:
> I am having a problem with one of my PHP pages. Maybe its a simple
> coding error, or about something I don't know about $_GET, or something
> totally different. Could someone explain?
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=utf-8">
> <?
>
> $type = $_GET['type']
>
> if ($_GET['type'] == "")
> {
> echo " ?><script>
> setTimeout("window.location.replace('http://www.example.com/')" ,0000)
> </script><?
>
> ";
> }
>
> ?><title>Stuff - <?
>
> if ($_GET['type'] == "")
> {
> echo "Redirecting...";
> }
>
> elseif ($_GET['type'] == "youaremighty")
> {
> echo "You Are Mighty";
> }
>
> elseif ($_GET['type'] == "justgotowned")
> {
> echo "Just Got Owned"
> }
>
> ?></title>
> <meta name="keywords" content="stuff, internet, aninote, <?
>
> if ($_GET['type'] == "youaremighty")
> {
> echo "You Are Mighty";
> }
>
> elseif ($_GET['type'] == "justgotowned")
> {
> echo "Just Got Owned"
> }
>
> ?>">
> <meta name="description" content="This page links to personalized
> aninotes, in this case, <?
>
> if ($_GET['type'] == "youaremighty")
> {
> echo "You Are Mighty";
> }
>
> elseif ($_GET['type'] == "justgotowned")
> {
> echo "Just Got Owned"
> }
>
> ?>">
> <link rel="stylesheet" type="text/css" href="../styles/default.css">
> </head>
>
> <body>
>
> <p>blah</p>
>
> </body>
> </html>
>
>
> Thank you.
>
Spotting errors in code gets a lot easier if you try to do as much of
your processing as early as possible in the code. In the case of your
code here, it becomes much more readable if you do something like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php
if ($_GET['type'] == '') {
echo
"<script>setTimeout(\"window.location.replace('http://www.example.com/')\"
,0000)</script>";
exit;
}
switch($_GET['type']) {
case 'youaremighty':
$msg="You Are Mighty";
break;
case 'justgotowned':
$msg="Just Got Owned";
break;
}
?>
<title>Stuff - <?php echo $msg;?></title>
<meta name="keywords" content="stuff, internet, aninote, <?php echo
$msg;?>">
<meta name="description" content="This page links to personalized
aninotes, in this case, <?php echo $msg;?>">
<link rel="stylesheet" type="text/css" href="../styles/default.css">
</head>
<body>
<p>blah</p>
</body>
</html>
Also, try not to rely on the shortkeys feature (i.e. <? and <?=) use the
long forms (<?php and <?php echo) if you want the code to be portable.
-david-
Navigation:
[Reply to this message]
|