Using variable declared in URL?

March 11th, 2010 | Posted by admin under enart.qthx.com with
  • How would I go about have a script do a couple different things based on a variable in the URL without specifying each variable within the script?
    ex)
    lyrics.php?fed=fedname would display a dir listing of everything in the "fedname" directory (preferably split into tables, but I didn't even look for that yet, so I'll try that later), and
    lyrics.php?fed=fedname&name=wrestlername would display the file "wrestlername" in the "fedname" directory.
    I don't know if this is possible at all, but I'd figure I'd ask, I looked through the php docs but didn't see anything


  • thanks for all your help so far John, I have it working except for one problem, the "." and ".." in the dir listing, I can't seem to get them to be removed, I get an error in that line of the file
    other than that, its working great


  • I'm learning vB in school, atleast thats what I signed up for anyway, damned public school system


  • yesterday i started learning php. I started on a nice intro book "PHP Fast and Easy Web Development" before i get onto my Wrox press book. Guess what the exact page i am on is about.. you guessed it .. listing a directory :)


  • you are lucky. We never got taught to use a computer at all let alone programming (and i am only 19 so it was not long ago!).

    I always think it is hard to be taught to use a computer and especially to be taught to program somthing. Seems something you just have to learn yourself with the aid of books (or online manuals for the experts here :) )


  • Take a look at this:

    http://www.phpbuilder.com/manual/ref.dir.php

    here's basically what'd you'd want to do:


    $dir = opendir("/path/to/dir/$name");
    echo "

    Directory listing for $name

    n";
    echo "Files:
    n";
    while ($file = readdir($dir)) {
    if ($file != "." && $file != ".." {
    echo "$file
    n";
    }
    }
    closedir($dir);


    or you could do this:


    $dir = dir("/path/to/dir/$name");
    echo "

    Directory listing for $name

    n";
    echo "Files:
    n";
    while ($file = $dir->read()) {
    if ($file != "." && $file != ".." {
    echo "$file
    n";
    }
    }
    $dir->close();


    [Edited by JohnM on 10-21-2000 at 03:53 PM]


  • I'm 13 and I learned PHP w/o any books... took me about 2 hours to read the manual on the basic stuff, and a couple days to get used to it...


  • I did not know that, thanks...but how would I be able to print a dir listing of "John", if the variable is "$name"?


  • When something is passed via the querystring (?this=that), PHP automatically converts it to variables.

    For example, if you type "test.php?name=John", PHP would create a variable called $name with the value of John.


  • I didn't use no steenken book either (backwards redneck double-negative used on purpose)

    .. but it helps to know C :)


  • you guys are so great :) lol


  • oops!

    change this:

    if ($file != "." && $file != ".." {

    to

    if ($file != "." && $file != "..") {


  • I can not believe I didn't notice that


  • well, the programming class is a joke, so it doesn't really matter. I only took it because I desperately needed an easy class in my schedule.


  • I learned PHP w/o a book.. tho I am thinking about getting Professional PHP Programming...







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Using variable declared in URL? , Please add it free.
    edit