Announcement

Collapse
No announcement yet.

PHP in url? Teach me please ^_^

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP in url? Teach me please ^_^

    Hello,

    I'm working on v2 for my Tales of Symphonia site. Now, I am trying to learn PHP and I would really like to be able to do this.

    I'm really new to PHP so I can't do really anything with it.

    I would love to have something like this for my site..

    http://symptales.net/?about

    and in a game catagory

    http://symptales.net/?games=gamename

    Please help me do this ^_^

  • #2
    With this kind of url, you'll have to create a file called index.php (http://symptales.net/index.php), and then put somewhere in it something like the following :
    Code:
    <?php
    if ($_GET[games] == "wolfenstein") { echo "<br/>You're on the wolfenstein page"; }
    elseif ($_GET[games] == "doom3") { echo "<br/>You're on the doom3 page"; }
    ?>
    Hope this helps a little

    For the first case (http://symptales.net/?about), I don't know... I personnaly use something like : http://symptales.net/?page=about
    Syntax errors in my post ? Well, I'm a french-speaking Swiss user..

    Comment


    • #3
      It should be

      PHP Code:
       if ($_GET['games'] == 'wolfenstein') {
        echo 
      '<br />You are on the wolfenstein page';
        }
        else if (
      $_GET['games'] == 'doom3') {
        echo 
      '<br />This is the Doom 3 page';
        }
        else {
        echo 
      '<br />This is the default page';
        } 


      It would be index.php?game=wolfenstein or index.php?game=doom3
      That's the end of that!

      Comment


      • #4
        If you're looking to do something like

        http://www.example.com/?value

        and you want to get value then, assuming you have register_argv set to on in php.ini, $_SERVER["argv"][0] will contain "value". Be aware that in the following case:

        http://www.example.com/?value&foo=bar&one=two

        $_SERVER["argv"][0] will contain "value&foo=bar&one=two"

        If you want to take it to the next level and have

        http://www.example.com/games/doom3

        Where you only have a file in the root folder, then you're looking at Apache's mod_rewrite, which is a whole other ball game

        Martin

        Comment


        • #5
          Thanks everyone, but I think newspoint is doing it the way I wanted it the most.

          I think I understand what you are talking about, but where can I find the php.ini?

          Comment


          • #6
            Just use $_SERVER['QUERY_STRING'] to get "value" or "about". It's most likely that this array is being populated on your server.

            Comment


            • #7
              I'm going to go with the other way.

              So if I put..

              Code:
              if ($_GET['games'] == 'wolfenstein') {
                echo '<br />You are on the wolfenstein page';
                }
                else if ($_GET['games'] == 'doom3') {
                echo '<br />This is the Doom 3 page';
                }
                else {
                echo '<br />This is the default page';
                }  
              That on my index.php

              How would I change it to look like this?
              http://symptales.net/index.php?id=about

              and for the game section..
              http://symptales.net/games.php?id=tos

              Comment


              • #8
                You can use if($_GET['id']=='about') etc. .

                Comment


                • #9
                  PHP Code:
                    if ($_GET['id'] == 'about')
                       {
                       include(
                  'about.php');
                       }
                       elseif (
                  $_GET['id'] == 'page')
                       {
                       include(
                  'page.php');
                       }
                       elseif (
                  $_GET['id'] == 'tos')
                       {
                       include(
                  'games.php')
                       }
                       else
                       {
                       include(
                  'home.php')
                       } 

                  Comment


                  • #10
                    Actually, using a switch in this case is faster than using if conditions.

                    Example:
                    PHP Code:
                    <?php
                    switch(trim($_GET['id']))
                    {
                        case 
                    'about':
                                
                    $file 'about.php';
                            break;

                        case 
                    'page':
                                
                    $file 'page.php';
                            break;

                        case 
                    'tos':
                                
                    $file 'games.php';
                            break;

                        default:
                                
                    $file 'home.php';
                    }
                    include 
                    $file;
                    ?>
                    <@Bane>Go on baby, be kinky and talk to me in PHP.

                    I recommend MBSHost to all my clients
                    PHP scripts I'm working on
                    My favourite search engine

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X