4 replies
I did 18 month's of php to get a telescope on the net back in 2005.

That was a long time ago.

Now I'm scraping off the rust from those dormant neurons & on the coding path again for a bit - so please don't bite my head off

(The title is meant to be a pun by the way)


On with the show:

Example:

http://mywebsite.com/code.php?09809898998randomstuff

Question:

Can I use _$REQUEST to parse the 098.... into a variable like this:

$mystring = ($_REQUEST);

I just want to capture all the stuff after the ? into a variable and then do some funky stuff with the variable afterwards

Dez.
#_$request #$request #php #rusty
  • Profile picture of the author eminc
    Hi,

    First off, the type of request which you have indicated is a GET request.

    Secondly, you will require to add a variable to the value, otherwise it won't recognize the value. Every value you pass must have a variable name
    Make,
    http://mywebsite.com/code.php?09809898998randomstuff

    as

    http://mywebsite.com/code.php?myvar=09809898998randomstuff

    This way you can access the variable myvar in your PHP code somewhat like this

    $myVariable = $_REQUEST['myvar']; or $myVariable = $_GET['myvar']

    Here's a tutorial for feedback form script. I guess it'll help more.

    PHP Tutorial: Writing Your First PHP Script: A Feedback Form (a FormMail Script) (thesitewizard.com)


    Mohit
    {{ DiscussionBoard.errors[4960242].message }}
    • Profile picture of the author dezfutak
      Many thanks Mohit
      Signature
      {{ DiscussionBoard.errors[4960269].message }}
      • Profile picture of the author Tim Brownlaw
        Another nice thing to put back into your Neurons is the print_r() function...

        So when you are playing with arrays etc such as $_REQUEST which is a catch all for , $_GET, $_POST and stuff back from Databases... it's a handy little debug command to have...

        So in your case - say using print_r($_GET) will show you what it's is seeing.

        Good to see you are getting back into PHP

        Cheers
        Tim
        {{ DiscussionBoard.errors[4960841].message }}
  • Profile picture of the author mgkimsal
    There's a couple other ways to get at that information if you want/need to keep 'clean' URLs.

    print_r($_SERVER);

    will show you likely $_SERVER['QUERY_STRING'] has the value you're looking for.

    foo.php/foobarbaz would give you a $_SERVER['PATH_INFO'] (or $_SERVER['REQUEST_URI'] in some cases) with 'foobarbaz' (maybe '/foobarbaz') - but you can play around with that

    $_SERVER['QUERY_STRING'] should get you the raw data if you don't want to (or can't!) modify code to have a "?var=" named prefix.
    {{ DiscussionBoard.errors[4975360].message }}

Trending Topics