Rusty php _$request

by 4 replies
5
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.
#programming #_$request #$request #php #rusty
  • 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
    • [ 1 ] Thanks
    • [1] reply
    • Many thanks Mohit
      • [1] reply
  • 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.

Next Topics on Trending Feed