Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Get variables off URL and use

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #158852
    jack21
    Participant

    Hi,

    I have a url such as domain.com/search.php?q=ipad&page=23&v=0&v2=2

    My problem is how can I obtain and use all of these variables? The variables q and page are static and I can call them independently however for some of the v & v2 variables it is difficult to as these are static.

    Thanks,

    Jack

    #158853
    Senff
    Participant

    How do you want to use them, in what language? PHP? JavaScript?

    #158854
    jack21
    Participant

    Hi,

    Thanks for your reply. Yes in PHP.

    #158855
    __
    Participant

    in PHP, use the $_GET superglobal array.

    #158882
    jack21
    Participant

    I use the $_GET, however I don’t how this would work with any variables attached to the url which are dynamic and generated by the system or external API queries.

    #158911
    __
    Participant

    I use the $_GET, however I don’t how this would work with any variables attached to the url which are dynamic and generated by the system or external API queries.

    Very simply: check for variables you expect, and refuse all that you don’t.

    For example, if you might get the params a, b, and c, then check for them:

    $a = isset( $_GET['a'] )? $_GET['a']: null;
    $b = isset( $_GET['b'] )? $_GET['b']: null;
    $c = isset( $_GET['c'] )? $_GET['c']: null;
    

    Or, if your program depends on these vars for decisions:

    if( isset( $_GET['a'] ) ){
        /*  do "a" stuff  */
    }
    //  etc. …
    

    If someone sends you a parameter d in the query string, and you aren’t expecting it, then trying to do something with it would be a critical security risk. Don’t do it.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.