Problem with PHP Page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Numerator

    #1

    Problem with PHP Page

    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("win dow.location.re place('http://www.example.com/')" ,0000)
    </script><?

    ";
    }

    ?><title>Stuff - <?

    if ($_GET['type'] == "")
    {
    echo "Redirecting... ";
    }

    elseif ($_GET['type'] == "youaremigh ty")
    {
    echo "You Are Mighty";
    }

    elseif ($_GET['type'] == "justgotown ed")
    {
    echo "Just Got Owned"
    }

    ?></title>
    <meta name="keywords" content="stuff, internet, aninote, <?

    if ($_GET['type'] == "youaremigh ty")
    {
    echo "You Are Mighty";
    }

    elseif ($_GET['type'] == "justgotown ed")
    {
    echo "Just Got Owned"
    }

    ?>">
    <meta name="descripti on" content="This page links to personalized
    aninotes, in this case, <?

    if ($_GET['type'] == "youaremigh ty")
    {
    echo "You Are Mighty";
    }

    elseif ($_GET['type'] == "justgotown ed")
    {
    echo "Just Got Owned"
    }

    ?>">
    <link rel="stylesheet " type="text/css" href="../styles/default.css">
    </head>

    <body>

    <p>blah</p>

    </body>
    </html>


    Thank you.

  • Jerry Stuckle

    #2
    Re: Problem with PHP Page

    The Numerator wrote:[color=blue]
    > 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("win dow.location.re place('http://www.example.com/')" ,0000)
    > </script><?
    >
    > ";
    > }
    >
    > ?><title>Stuff - <?
    >
    > if ($_GET['type'] == "")
    > {
    > echo "Redirecting... ";
    > }
    >
    > elseif ($_GET['type'] == "youaremigh ty")
    > {
    > echo "You Are Mighty";
    > }
    >
    > elseif ($_GET['type'] == "justgotown ed")
    > {
    > echo "Just Got Owned"
    > }
    >
    > ?></title>
    > <meta name="keywords" content="stuff, internet, aninote, <?
    >
    > if ($_GET['type'] == "youaremigh ty")
    > {
    > echo "You Are Mighty";
    > }
    >
    > elseif ($_GET['type'] == "justgotown ed")
    > {
    > echo "Just Got Owned"
    > }
    >
    > ?>">
    > <meta name="descripti on" content="This page links to personalized
    > aninotes, in this case, <?
    >
    > if ($_GET['type'] == "youaremigh ty")
    > {
    > echo "You Are Mighty";
    > }
    >
    > elseif ($_GET['type'] == "justgotown ed")
    > {
    > echo "Just Got Owned"
    > }
    >
    > ?>">
    > <link rel="stylesheet " type="text/css" href="../styles/default.css">
    > </head>
    >
    > <body>
    >
    > <p>blah</p>
    >
    > </body>
    > </html>
    >
    >
    > Thank you.
    >[/color]

    What happens when you try to load the page?


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Steffen

      #3
      Re: Problem with PHP Page

      <!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("win dow.location.re place('http://www.example.com/')" ,0000)
      </script><?


      ";



      }


      ?><title>Stuff - <?

      if ($_GET['type'] == "")
      {
      echo "Redirecting... ";



      }


      elseif ($_GET['type'] == "youaremigh ty")
      {
      echo "You Are Mighty";


      }


      elseif ($_GET['type'] == "justgotown ed")
      {

      //Here
      echo "Just Got Owned" ;


      }


      ?></title>
      <meta name="keywords" content="stuff, internet, aninote, <?

      if ($_GET['type'] == "youaremigh ty")
      {
      echo "You Are Mighty";



      }


      elseif ($_GET['type'] == "justgotown ed")
      {
      //Here
      echo "Just Got Owned" ;


      }


      ?>">
      <meta name="descripti on" content="This page links to personalized
      aninotes, in this case, <?

      if ($_GET['type'] == "youaremigh ty")
      {
      echo "You Are Mighty";



      }


      elseif ($_GET['type'] == "justgotown ed")
      {

      //Here
      echo "Just Got Owned" ;


      }


      ?>">
      <link rel="stylesheet " type="text/css" href="../styles/default.css">
      </head>

      <body>


      <p>blah</p>


      </body>
      </html>

      I think i have found your errors. I have commented them in the code.

      Comment

      • David Haynes

        #4
        Re: Problem with PHP Page

        The Numerator wrote:[color=blue]
        > 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("win dow.location.re place('http://www.example.com/')" ,0000)
        > </script><?
        >
        > ";
        > }
        >
        > ?><title>Stuff - <?
        >
        > if ($_GET['type'] == "")
        > {
        > echo "Redirecting... ";
        > }
        >
        > elseif ($_GET['type'] == "youaremigh ty")
        > {
        > echo "You Are Mighty";
        > }
        >
        > elseif ($_GET['type'] == "justgotown ed")
        > {
        > echo "Just Got Owned"
        > }
        >
        > ?></title>
        > <meta name="keywords" content="stuff, internet, aninote, <?
        >
        > if ($_GET['type'] == "youaremigh ty")
        > {
        > echo "You Are Mighty";
        > }
        >
        > elseif ($_GET['type'] == "justgotown ed")
        > {
        > echo "Just Got Owned"
        > }
        >
        > ?>">
        > <meta name="descripti on" content="This page links to personalized
        > aninotes, in this case, <?
        >
        > if ($_GET['type'] == "youaremigh ty")
        > {
        > echo "You Are Mighty";
        > }
        >
        > elseif ($_GET['type'] == "justgotown ed")
        > {
        > echo "Just Got Owned"
        > }
        >
        > ?>">
        > <link rel="stylesheet " type="text/css" href="../styles/default.css">
        > </head>
        >
        > <body>
        >
        > <p>blah</p>
        >
        > </body>
        > </html>
        >
        >
        > Thank you.
        >[/color]

        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>setTim eout(\"window.l ocation.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="descripti on" 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-

        Comment

        • The Numerator

          #5
          Re: Problem with PHP Page

          Thanks, I hope it helps... I thought that "<? /* code */?>" was the
          same as "<?php /* code */ ?>". What's the difference?

          Comment

          • Andre Frashek

            #6
            Re: Problem with PHP Page

            The Numerator wrote:[color=blue]
            > Thanks, I hope it helps... I thought that "<? /* code */?>" was the
            > same as "<?php /* code */ ?>". What's the difference?
            >[/color]

            You can see the difference in your php-configuration file. There´s a
            option called "short_open _tag =". If it´s set to On, then you can use
            "<? /* code */?>". This is the setting which most webhosters (the one´s
            I know) use. But the DEFAULT setting for this option is "Off". Then your
            php code won´t be executed if you use anything else than "<?php /* code
            */ ?>.

            So you should always use the long form to get the code portable.

            Comment

            • Tim Van Wassenhove

              #7
              Re: Problem with PHP Page

              On 2006-04-07, Andre Frashek <andre.frashek@ stud-mail.uni-wuerzburg.de> wrote:[color=blue]
              > The Numerator wrote:[color=green]
              >> Thanks, I hope it helps... I thought that "<? /* code */?>" was the
              >> same as "<?php /* code */ ?>". What's the difference?
              >>[/color]
              >
              > You can see the difference in your php-configuration file. There´s a
              > option called "short_open _tag =". If it´s set to On, then you can use
              > "<? /* code */?>". This is the setting which most webhosters (the one´s
              > I know) use. But the DEFAULT setting for this option is "Off". Then your
              > php code won´t be executed if you use anything else than "<?php /* code
              > */ ?>.
              >
              > So you should always use the long form to get the code portable.[/color]


              The most annoying about short_open_tag = on is that you have to perform
              workaround to get a simple line as: <?xml version="1.0" encoding="UTF-8"?>

              --
              Met vriendelijke groeten,
              Tim Van Wassenhove <http://timvw.madoka.be >

              Comment

              • The Numerator

                #8
                Re: Problem with PHP Page

                The only problem with the code that David gave me is that the title,
                and the meta tags don't work. For example, the title is "Stuff -"
                instead of "Stuff - Title", etc...

                Comment

                • David Haynes

                  #9
                  Re: Problem with PHP Page

                  The Numerator wrote:[color=blue]
                  > The only problem with the code that David gave me is that the title,
                  > and the meta tags don't work. For example, the title is "Stuff -"
                  > instead of "Stuff - Title", etc...
                  >[/color]
                  This would happen if $_GET['type'] was not one of '', 'youaremight' or
                  'justgotowned'.

                  Try putting a default case into the switch. e.g.

                  case 'justgotowned':
                  $msg="Just Got Owned";
                  break;
                  default:
                  $msg="type is not legal";
                  break;
                  }

                  -david-

                  Comment

                  • The Numerator

                    #10
                    Re: Problem with PHP Page

                    thenk i got it... i just forgot to define that variables before
                    actually using it, and instead of the js i used to replace the window,
                    i used the function "header".

                    Comment

                    • The Numerator

                      #11
                      Re: Problem with PHP Page

                      no, i got it... i just forgot to define that variables before actually
                      using it, and instead of the js i used to replace the window, i used
                      the function "header".

                      Comment

                      Working...