Results 1 to 6 of 6

Thread: [RESOLVED] Something with QueryStrings

  1. #1

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Resolved [RESOLVED] Something with QueryStrings

    in querystrings you always have something like this
    Code:
    page.php?start=10&offset=5&category=45
    but in some cases, i see the querystring like this
    Code:
    page.php?start=10;offset=5;category=45
    replacing the Amperand - & with a semi-colon - ;

    how is that done?
    how do you read out the querystring values?

    thanks in adv...
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: Something with QueryStrings

    All querystring parameters are stored in the $_GET[] superglobal* array. The parameter delimeter can be set in php.ini, if you really want, but it is immaterial if you use $_GET.

    PHP Code:
    $start $_GET['start']; 
    etc.

    Remember if you use GET parameters in SQL queries, to always ensure they are secured. For example, casting to a number for numeric parameters, and enclosing string paremeters in quotes.

    So if you were to use 'start' in a SQL query, you would do this:
    PHP Code:
    $start = (int) $_GET['start']; 
    * superglobal means you can access it from within a function without having to declare it using the global keyword.

  3. #3

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Something with QueryStrings

    pls explain more...i don't get it
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: Something with QueryStrings

    OK...

    If you pass this querystring
    Code:
    start=10&offset=5&category=45
    and your delimiter is set as '&' (which is default), you can access each parameter like this:
    PHP Code:
    $start $_GET['start'];
    $offset $_GET['offset'];
    $category $_GET['category']; 
    etc.

    If you have this querystring
    Code:
    start=10;offset=5;category=45
    and the delimiter is set as ';', the same PHP code will yield the same result.

    Understand?

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    Re: Something with QueryStrings

    There is a setting which can be set in the php.ini file called arg_separator.input. If you don't have access to the php.ini file, you can access the query string through $_SERVER['QUERY_STRING'] and use explode to set up your array:
    PHP Code:
    <?php

    function parse_custom_query_string($arg_separator ';'$value_separator '='
    {
        
    $_GET = array(); // clear old $_GET array

        /* separate query string uising the arg_separator */
        
    $pairs explode($arg_separator$_SERVER['QUERY_STRING']); 

        
    /* loop through each name vlaue pair */
        
    foreach($pairs as $value) {
            
            
    /* ignore if no value separator is present */
            
    if (($pos strpos($value$value_separator)) === false) {
                continue;
            }   

            
    /* extract and decode each componenet */
            
    $name urldecode(substr($value0$pos));
            
    $value urldecode(substr($value$pos +1));

            
    /* add to the $_GET array */
            
    $_GET[$name] = $value;
        }
    }

    parse_custom_query_string();
    ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Something with QueryStrings

    yeah thats it... works like a charm... thanks visualAd/Penegate
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width