Problems with HTTP_POST_VARS
Posted: Wed Mar 17, 2004 5:49 am
Dear All
I'm currently building a fully encapsulated site using PHP. The code is structured so that the whole site is a single script, index.php, and all of the pages are implemented as separate functions, with each page being called by an URL-posted variable (e.g. p=1, front page, p=2, search page etc.).
I have two problems:
(1) The value of 'p' is unpredictable until it has been defined. Therefore I do not know what to do when the site is first visited, where the variable 'p' is not posted on the URL signifying the page - to explain, if I want the front page, I need to use the address 'index.php?p=1'. However when first visiting the site, obviously the address is simply 'index.php'. How do I detect this and automatically place p=1 to call the front page function?
(2) Previously, I did have the site as a set of separate pages - index.php, search.php, etc. There is a search form on the front page, index.php, which has on it a form with a set of criteria you can select. When the user pressed the 'submit' button, the action was referred to search.php. In search.php, the criteria variables set by the user on the search form on index.php were obtained using the standard HTTP_POST_VARS.
However, now I have the search page all in the same index.php script, to call the search page I use 'index.php?p=2'. When I put this in the ACTION variable of the form enclosing the search form on the front page, it works, however now the HTTP_POST_VARS are coming up as NULL. How do I then effectively communicate these variables from the form on the front page?
Sorry for the heavy-handed explaining, I hope that makes sense to you seasoned programmers.
Thanks
Mark
I'm currently building a fully encapsulated site using PHP. The code is structured so that the whole site is a single script, index.php, and all of the pages are implemented as separate functions, with each page being called by an URL-posted variable (e.g. p=1, front page, p=2, search page etc.).
I have two problems:
(1) The value of 'p' is unpredictable until it has been defined. Therefore I do not know what to do when the site is first visited, where the variable 'p' is not posted on the URL signifying the page - to explain, if I want the front page, I need to use the address 'index.php?p=1'. However when first visiting the site, obviously the address is simply 'index.php'. How do I detect this and automatically place p=1 to call the front page function?
(2) Previously, I did have the site as a set of separate pages - index.php, search.php, etc. There is a search form on the front page, index.php, which has on it a form with a set of criteria you can select. When the user pressed the 'submit' button, the action was referred to search.php. In search.php, the criteria variables set by the user on the search form on index.php were obtained using the standard HTTP_POST_VARS.
However, now I have the search page all in the same index.php script, to call the search page I use 'index.php?p=2'. When I put this in the ACTION variable of the form enclosing the search form on the front page, it works, however now the HTTP_POST_VARS are coming up as NULL. How do I then effectively communicate these variables from the form on the front page?
Sorry for the heavy-handed explaining, I hope that makes sense to you seasoned programmers.
Thanks
Mark