Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Querystring Problem

Status
Not open for further replies.

BKer

Programmer
Apr 17, 2001
62
US
I am new to php and I am trying to figure out why I cannot view a variable that I am trying to grab from the querystring. I am using the code below to try and figure if there was a setting that changed somehow.

Here is the querystring i am trying to pull from.



/testlinks.php?type=adoption

the output is "parameter type is undefined"

Can anyone tell me what is wrong?
Thanks for the help.

<?php
if (empty($type))
{ echo 'parameter "type" undefined';}
else
{ echo 'parameter "type" value is "' . $type . '"' ;}
phpinfo();
?>
 
Can you tell me if register_globals needs to be turned on?

Here is essentially my page. All I want to do is be able to grab the variable from the querystring.

In the php info that is output register_globals is off.
In the querystring for php_info() it has the correct value.

does this mean that get and post data will not be available to me?

Thanks again for the help.

<table width="725" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4"><font size=-3>&nbsp;</font></td>
</tr>
<tr>
<td valign="top" colspan=2 align=center><h1><? if ($type=="family") { ?>
Family Law Links
<? } else if($type=="adoption") { ?>
Adoption Links
<? } else if($type=="divorce") { ?>
Divorce Links
<? } else if($type=="education") { ?>
Education Links
<? } else if($type=="general") { ?>
General Links
<? } else { ?>
All Links
<? } ?>
</h1></td>
<td><?php
if (empty($type))
{ echo 'parameter "test" undefined';}
else
{ echo 'parameter "test" value is "' . $type . '"' ;}
phpinfo();
?>
</td>
</tr>
</table>
 
Turning register_globals on is a bad idea due to security purposes. You can still access variables from querystring or posted variables but you must reference them accordingly. They reside in their respective superglobal arrays:

querystring: index.php?variable=1 use $_GET['variable']
posted: use $_POST['variable']

Hope it helps.
 
Ok, thanks for your responses. I just called our web host and they turned the register_globals on for our domain and it fixed the problem.

We are not authenticating or doing anything but hosting static pages.

Should I still be concerned about having this turned on?

Thanks again.
 
<vocabulary anal=true>
If you are doing php then, by definition, you are not using static pages.
</vocabulary>
 
register_globals are ev0l...

$_REQUEST['variable']
$_POST['variable']
$_GET['variable']

All work just fine. Would suggest like others here, that you transition your development habits twoards this method instead of the previous. You will see that it makes for much nicer code. ;)
 
If you have global_variables turned off, your code
Code:
<?php
  if (empty($type))
    { echo 'parameter "type" undefined';}
  else
    { echo 'parameter "type" value is "' . $type . '"' ;}
  phpinfo();
?>
would work if you put this instead
Code:
<?php
  if (empty($_GET['type']))
    { echo 'parameter "type" undefined';}
  else
    { echo 'parameter "type" value is "' . $type . '"' ;}
  phpinfo();
?>

As you can see I've just swapped $type for $_GET['type'] like people have already mentioned to do, its a bit weird if you are new to php, it took me a while to get the hang of not using global variables, but trust me it is the way to proceed.

As also mentioned more than once previously in this thread, global_variables turned on is a bad idea. It is a major security hole.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top