|
-
Apr 30th, 2006, 04:41 AM
#1
Thread Starter
Fanatic Member
[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...
-
Apr 30th, 2006, 04:48 AM
#2
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.
-
Apr 30th, 2006, 04:58 AM
#3
Thread Starter
Fanatic Member
Re: Something with QueryStrings
pls explain more...i don't get it
-
Apr 30th, 2006, 05:03 AM
#4
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?
-
Apr 30th, 2006, 05:10 AM
#5
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($value, 0, $pos));
$value = urldecode(substr($value, $pos +1));
/* add to the $_GET array */
$_GET[$name] = $value;
}
}
parse_custom_query_string();
?>
-
Apr 30th, 2006, 08:18 PM
#6
Thread Starter
Fanatic Member
Re: Something with QueryStrings
yeah thats it... works like a charm... thanks visualAd/Penegate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|