469,936 Members | 2,365 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

checking paramters in the url bar

<?php
if ((!isset($s)) && (!isset($msg))) {
echo("<table>
....
I want some pictures displayed on the main page if its a new visit, but when they
search and the url bar changes its skips displaying them, to save scrolling down all the time.

I tried the above to read the parameters but get an error when they are not set.

Is there something simple like this :

if (url has no parameters) {
echo("...draw front page section")
Herc

--
www.TopCounters.com www.Chatty.net
Jul 17 '05 #1
7 1744
"-erc" wrote:
<?php
if ((!isset($s)) && (!isset($msg))) {
echo("<table>
....
I want some pictures displayed on the main page if its a new visit,
but when they
search and the url bar changes its skips displaying them, to save
scrolling down all the time.

I tried the above to read the parameters but get an error when they
are not set.

Is there something simple like this :

if (url has no parameters) {
echo("...draw front page section")
Herc

--
www.TopCounters.com www.Chatty.net


url parameters are made available in $_GET array.

So you can say:
if (count($_GET) == 0) ....

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-checking...ict136679.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=456582
Jul 17 '05 #2
*** |-|erc wrote/escribió (Thu, 05 Aug 2004 03:00:59 GMT):
Is there something simple like this :

if (url has no parameters) {
echo("...draw front page section")


This should be enough:

if($_GET['parameter'] != ''){
echo foo();
}

You really don't need to have zero parameters, just check for the required
ones (you don't mind whether there's a PHPSESSIONID or anything similar).

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #3
.oO(Alvaro G Vicario)
This should be enough:

if($_GET['parameter'] != ''){
echo foo();
}


This will show a notice if there's no such parameter.

Better:

if (isset($_GET['parameter'])) {
...
}

Micha
Jul 17 '05 #4
*** Michael Fesser wrote/escribió (Thu, 05 Aug 2004 14:54:22 +0100):
if($_GET['parameter'] != ''){
echo foo();
}
This will show a notice if there's no such parameter.


Not for me. Does it depend on error_reporting settings?
if (isset($_GET['parameter'])) {
...
}


Just note that a parameter can be set and empty.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #5
.oO(Alvaro G Vicario)
*** Michael Fesser wrote/escribió (Thu, 05 Aug 2004 14:54:22 +0100):
if($_GET['parameter'] != ''){
echo foo();
}


This will show a notice if there's no such parameter.


Not for me. Does it depend on error_reporting settings?


Yep. On a development system error_reporting should be set to E_ALL to
show everything. Even a notice could be a reason for a hard to find bug.
Good code should be notice-free IMHO.
if (isset($_GET['parameter'])) {
...
}


Just note that a parameter can be set and empty.


Of course. If necessary additional checks should be done, but first you
have to test if the parameter exists at all.

Micha
Jul 17 '05 #6
"steve" <Us************@dbForumz.com> wrote in
"-erc" wrote:
> <?php
> if ((!isset($s)) && (!isset($msg))) {
> echo("<table>
> ....
>
>
> I want some pictures displayed on the main page if its a new visit,
> but when they
> search and the url bar changes its skips displaying them, to save
> scrolling down all the time.
>
> I tried the above to read the parameters but get an error when they
> are not set.
>
> Is there something simple like this :
>
> if (url has no parameters) {
> echo("...draw front page section")
>
>
> Herc
>
> --
> www.TopCounters.com www.Chatty.net


url parameters are made available in $_GET array.

So you can say:
if (count($_GET) == 0) ....


perfect thanks all, I found

if (isset($_GET['s'])) echo

in the code just after I posted works a treat. Don't you hate scolling down after a
big blocky forum header every single post? much faster now.

Herc

Jul 17 '05 #7
I just want to point out that PHP's behavior also changed (somewhere around 4.2.0 ?)

test URL: http://www.foobar.com/test.php?hello

isset($_GET['hello']) will return true in newer versions of PHP
slightly older versions require .../test.php?hello=1 (or = any value)
to get around this, you can check $_SERVER['QUERY_STRING']
Michael Fesser <ne*****@gmx.net> wrote in message news:<9u********************************@4ax.com>. ..
.oO(Alvaro G Vicario)
This should be enough:

if($_GET['parameter'] != ''){
echo foo();
}


This will show a notice if there's no such parameter.

Better:

if (isset($_GET['parameter'])) {
...
}

Micha

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Web Developer | last post: by
22 posts views Thread by Qopit | last post: by
4 posts views Thread by Patient Guy | last post: by
125 posts views Thread by jacob navia | last post: by
7 posts views Thread by polas | last post: by
5 posts views Thread by K Viltersten | last post: by
4 posts views Thread by BillE | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.