PDA

View Full Version : PHP Querystrings


Ooryl
11-03-2004, 03:47
I've just started to have a play with PHP and to this end I have installed Apache Web Server 2.0.48, PHP 4.3.4 and mySQL4.0.18 on a computer.

The problem I'm having is trying to parse data into a php page, for example:

index.php in the root of the web documents folder

<html>
<body>

<?php
if (!$id) { echo "nice going *@!$tard"; } else { echo $id; }
?>

</body>
</html>

Am I right in assuming that if I access the page with path/index.php?id=1 it should spit back 1 as opposed to insulting me? If so, I'd appreciate any suggestions as to what I may have setup wrong (Or corrections of my dubious code)

I have added these lines to my httpd.conf file
LoadModule php4_module "c:/php/sapi/php4apache2.dll"
AddType application/x-httpd-php .php
as suggested in the PHP online help

Please help, I'm tired of my webpage swearing at me.

Clarksy
11-03-2004, 11:02
You need to have the following line set in your the php.ini file which will automatically assign querystring and post variables:


register_globals = On


The better way to do it is...

<?
// read "id" from the querystring (GET)
$id = $_GET['id'];

// Your code to test the output
if (!$id) { echo "nice going *@!$tard"; } else { echo $id; }
?>

Ooryl
11-03-2004, 14:29
Okay, cheers for that. I was lead to believe that PHP would automatically assign the variable if it found it in a querystring. It didn't do this even when I edited the .ini file so I switched it off again. (First my webpage, now the .ini files are having a go with "You should do your best to write your scripts so that they do not require register_globals to be on. Using form variables as globals can easily lead to possible security problems, if the code is not very well thought of. or If you switch this on, then you can't program for cack.)

The $_GET method(?) is just what the doctor ordered. Thanks again for your help.