I am currently working on a small PHP project for my college. I am quit new to it, so this query might seem trivial to you.
What I am trying to do is use the index.php to act as the front page of the site, as well as be able to handle queries using the GET method. For example, http://localhost/index.php?search=somestring should work as well. That is, there might or might not be a query string. All I want to know is whether such a query string exists or not. And if yes, what is(are) the parameter(s) (in this case, search is the parameter).
Thanks in advance.
Sometime on Sun, Feb 26, 2006 at 07:35:42PM +0000, Sanket Medhi said:
What I am trying to do is use the index.php to act as the front page of the site, as well as be able to handle queries using the GET method. For example, http://localhost/index.php?search=somestring should work as well. That is, there might or might not be a query string. All I want to know is whether such a query string exists or not. And if yes, what is(are) the parameter(s) (in this case, search is the parameter).
$_GET is an array which keeps track of query string, not a method.
<?php if ($_GET) print_r($_GET); else echo "There is no query string"; ?>
You could then access individual elements in query string by using echo $_GET['search'];
Anurag
On 2/27/06, Sanket Medhi sanketmedhi@gmail.com wrote:
example, http://localhost/index.php?search=somestring should work as well. That is, there might or might not be a query string. All I want to know is whether such a query string exists or not. And if yes, what
A query string is the part of the URL after the question mark.
The syntax is as follows: <scheme>://<authority><path>?<query>#<fragment>
So for example, in
http://localhost/index.php?search=somestring
the whole "search=somestring" is the query string. How you happen to deal with it is up to you.
In CGI culture, we normally pass "key=value" pairs separated by an ampersand (&)
-- Rohan http://rohan.almeida.in
Sometime Today, RRA cobbled together some glyphs to say:
In CGI culture, we normally pass "key=value" pairs separated by an ampersand (&)
the correct way is to pass them separated by a semicolon (;). Ampersands are legacy and their usage is deprecated since they have special meaning in XML and HTML.
On Mon, Feb 27, 2006 at 02:16:10PM +0530, Philip Tellis wrote:
the correct way is to pass them separated by a semicolon (;). Ampersands are legacy and their usage is deprecated since they have special meaning in XML and HTML.
My documents validate fine using & in the source. On the other hand, you are correct. The W3 validators chould maybe throw up a deprecation warning.
Sometime Today, S cobbled together some glyphs to say:
My documents validate fine using & in the source. On the other hand, you are correct. The W3 validators chould maybe throw up a deprecation warning.
& is the valid way of passing it in.
There are other problems with semi-colons though. You can't use them in a redirect link because ; is a parameter separater in HTTP headers
On Sunday 26 February 2006 19:35, Sanket Medhi wrote:
What I am trying to do is use the index.php to act as the front page of the site, as well as be able to handle queries using the GET method. For example, http://localhost/index.php?search=somestring should work as well. That is, there might or might not be a query string. All I want to know is whether such a query string exists or not. And if yes, what is(are) the parameter(s) (in this case, search is the parameter).
<? echo '<pre>'; print_r( $_GET ); echo '</pre>'; ?>
put that in index.php and call it with different query strings for eg:
http://foobar.com/index.php?a=1&b=2&c=3
and see what you get ;)
On 2/27/06, Rohan R. Almeida arcofdescent@gmail.com wrote:
A query string is the part of the URL after the question mark.
The syntax is as follows: <scheme>://<authority><path>?<query>#<fragment>
I know!
So for example, in
http://localhost/index.php?search=somestring
the whole "search=somestring" is the query string. How you happen to deal with it is up to you.
In CGI culture, we normally pass "key=value" pairs separated by an ampersand (&)
That helped a lot! :P
-- Regards, Sanket Medhi.
On 2/27/06, Anurag anurag@gnuer.org wrote:
$_GET is an array which keeps track of query string, not a method.
<?php if ($_GET) print_r($_GET); else echo "There is no query string"; ?>
You could then access individual elements in query string by using echo $_GET['search'];
Worked, thanks a lot! -- Regards, Sanket Medhi.
On 2/28/06, Dinesh Joshi dinesh.a.joshi@gmail.com wrote:
<? echo '<pre>'; print_r( $_GET ); echo '</pre>'; ?>
put that in index.php and call it with different query strings for eg:
http://foobar.com/index.php?a=1&b=2&c=3
and see what you get ;)
I get this when I send a query string like the one you suggested...
Array ( [a] => 1 [b] => 2 [c] => 3 )
and this when no query string is entered...
Array ( )
I think Anurag's answer has solved my problem. Thanks to all for your replies. Will get back to you ppl for any more queries regarding PHP in some time. :-) -- Regards, Sanket Medhi.
On Tuesday 28 February 2006 17:55, Sanket Medhi wrote:
I get this when I send a query string like the one you suggested...
Array ( [a] => 1 [b] => 2 [c] => 3 )
So what does that tell you? You can use this associative array to find out all the arguments passed to your script using the GET method ;)