Hello,

Since ive been on the internet ive seen many websites that end there URLs like this:
.php?**=
Or something like that. Well, i was wondering, exactly how would you do that? Ive looked at numerous tutorials everywhere but i couldn't really find a specific one on that. Thanks in advance.

    What are you trying to do?

    You will access the variables using the $GET var.
    .php?id***** would be accessed in your script using $
    GET['id']

    for example:
    .php?foo=bar in the address bar (or href link)

    and a script like:

    <?php
    
    echo $_GET['foo'];
    
    ?>

    Would print "bar" on the screen;

    Or

    .php?num=1 in the address bar (or href link)

    and a script like:

    <?php
    
    echo $_GET['num'] + 4;
    
    ?>

    Would print "5" on the screen;

    Post more questions and I will help as much as I can

      Thats kinda confusing, could you give me an example of a link that when clicked would show me that?

        Make a file named numbers.html on your site and paste the following into it

        <a href="www.yoursite.com/number.php?num=1">1</a>

        Then cut the following into a file and save it as number.php on your site

        <?php
        
        echo $_GET['num'] + 4;
        
        ?>

        These are not regular variables, they are arrays. Have you learned much about arrays yet? I can suggest a few good tuts if not.

        Sorry if this does not help. Feel free to post back if you need more

          Hmm, i get it, so say i had a page named downloads.php, then i wanted it to go to say download.php?id=2 when they clicked on a certain download, and then display info on that download, how exactly would i go about that?

            That's sort of complicated... It depends on how the information on the downloads are stored. Are you trying to build a downloads app, or are you linking to one that's already made?

              No no no, i dont mean it neccesarily has to be for downloads. Lets try this:
              Im making a page called tutorials.php, and when someone click a php link, it goes to tutorials.php?id=html and displays different tutorials on it.

                Well for that you might do this:

                tutorials.html

                <p>Tutorials:</p>
                <a href="tutorials.php?tut=html">HTML Tutorial</a><br />
                <a href="tutorials.php?tut=css">CSS Tutorial</a><br />
                <a href="tutorials.php?tut=php">PHP Tutorial</a><br />
                <a href="tutorials.php?tut=flash">Flash Tutorial</a>

                and then in tutorials.php:

                <?php
                
                include($_GET['tut'].".html");
                
                ?>

                And this would display the files html.html, css.html, php.html, or flash.html
                Please note that this code isn't safe and is for a simple example only

                  Ok thanks. As soon as a have my idea done, ill show it to you.

                    Hmm, say i wanted to do that on a single page like tutorials.php.. ie:

                    You go to tutorials.php and it has a bunch of php tutorials, then you click on tutorial #1, and it goes to tutorials.php?id=1. how would i do that since im only using one file?

                      Try

                      <?php
                      
                      if(!isset($_GET['tut']))
                      {	echo "<p>Tutorials:</p>".
                      		  "<a href=\"tutorials.php?tut=html\">HTML Tutorial</a><br />".
                      		  "<a href=\"tutorials.php?tut=css\">CSS Tutorial</a><br />".
                      		  "<a href=\"tutorials.php?tut=php\">PHP Tutorial</a><br />".
                      		  "<a href=\"tutorials.php?tut=flash\">Flash Tutorial</a>";
                      }else
                      {	include($_GET['tut'].".html"); 
                      }
                      
                      ?>

                        Yep that works, and one more thing, is there a way to do it without having to use the include function? Just to be able to right what you want on the original page? Or even, to have them with seperate extensions instead of awlays having to be "tutorial".html.

                          Heres another way you could do it. I find it alot easyer. Make a index.php and add the fallowing code to it.

                          Read the comments.

                          // php Includes for noobs By DeathfireD 
                          // Add this somewhere on your page. 
                          <? switch($_GET['id']) 
                          { 
                          default: 
                          case "news": 
                          include "news.php"; 
                          break; 
                          
                          case  "contacts": 
                           include "contacts.php"; 
                          break; 
                          
                          } 
                          ?> 
                          //Place this where you want your content to go 
                           <? include("$id.php"); ?> 
                          // Then to add links 
                          http://yourhost/index.php?id=news 
                          http://yourhost/index.php?id=contacts 

                          My example is set up for .php but you can alwase change the include "news.php" to a include "news.html" and also edit the <? include("$id.php"); ?> to <? include("$id.html"); ?>

                          The first code posted above is basicly what include($_GET['tut'].".html"); does but it makes a defualt page (news.php) so when someone goes to your site (ex. www.yoursite.com) the defualt page is alwase displayed.

                          This method is mainly used for the content in the middle of your page.

                            Write a Reply...