newbie querystring variables

This is a discussion on newbie querystring variables within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am new to PHP and am having problems using variables passed in a querystring. For example: <html> &...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-06-2003
Kelly Soden
 
Posts: n/a
Default newbie querystring variables

I am new to PHP and am having problems using variables passed in a
querystring. For example:

<html>
<head>
<title>submit-vars.html</title>
<body>
<a href="http://localhost/print-vars.php?id=1"> test</a>
</body>
</html>

<html>
<head>
<title>print-vars.php</title>
</head>
<body>
<p>The query string is: <?php echo $_SERVER['QUERY_STRING']; ?></p>
<p><? echo $_GET['id'] ?></p>
<?php printf("\n</br>print variable here->%s",$id); ?>
</body>
</html>

Clicking on the link in submit-vars.html calls print-vars.php producing the
following html source:

<html>
<head>
<title>print-vars.php</title>
</head>
<body>
<p>The query string is: id=test</p>
<p>test</p>

</br>print variable here-></body>
</html>


From the tutorials I have read, it is my understanding that PHP
automatically create a variable when it sees a name=value pair in a
querystring. Therefore I would expect the word "test" to again be printed
after "print variable here->". The behavior is the same if I submit the
querystring using a form instead of embedding it in a link. The simple PHP
scripts I have written seem to work fine except for this. What am I
missing?

My configuration is as follows:
Apache/1.3.28 (Win32), PHP/4.3.4, on Win 2K.

Apache is running in a command shell, not as a service. I have PHP loading
as a DSO, not as CGI, and have added the following lines in my httpd.conf:

LoadModule php4_module "c:/php/sapi/php4apache.dll"
AddType application/x-httpd-php .php

Thanks!
-Kelly



Reply With Quote
  #2 (permalink)  
Old 12-06-2003
lallous
 
Posts: n/a
Default Re: newbie querystring variables

Hello,

From PHP.INI

; - register_globals = Off [Security, Performance]
; Global variables are no longer registered for input data (POST, GET,
cookies,
; environment and other server variables). Instead of using $foo, you
must use
; you can use $_REQUEST["foo"] (includes any variable that arrives
through the
; request, namely, POST, GET and cookie variables), or use one of the
specific
; $_GET["foo"], $_POST["foo"], $_COOKIE["foo"] or $_FILES["foo"],
depending
; on where the input originates. Also, you can look at the
; import_request_variables() function.
; Note that register_globals is going to be depracated (i.e., turned off
by
; default) in the next version of PHP, because it often leads to
security bugs.
; Read http://php.net/manual/en/security.registerglobals.php for further
; information.

HTH
Elias

"Kelly Soden" <ksoden@alltel.net> wrote in message
news:LQiAb.757$R%4.87@fe10.private.usenetserver.co m...
> I am new to PHP and am having problems using variables passed in a
> querystring. For example:
>
> <html>
> <head>
> <title>submit-vars.html</title>
> <body>
> <a href="http://localhost/print-vars.php?id=1"> test</a>
> </body>
> </html>
>
> <html>
> <head>
> <title>print-vars.php</title>
> </head>
> <body>
> <p>The query string is: <?php echo $_SERVER['QUERY_STRING']; ?></p>
> <p><? echo $_GET['id'] ?></p>
> <?php printf("\n</br>print variable here->%s",$id); ?>
> </body>
> </html>
>
> Clicking on the link in submit-vars.html calls print-vars.php producing

the
> following html source:
>
> <html>
> <head>
> <title>print-vars.php</title>
> </head>
> <body>
> <p>The query string is: id=test</p>
> <p>test</p>
>
> </br>print variable here-></body>
> </html>
>
>
> From the tutorials I have read, it is my understanding that PHP
> automatically create a variable when it sees a name=value pair in a
> querystring. Therefore I would expect the word "test" to again be printed
> after "print variable here->". The behavior is the same if I submit the
> querystring using a form instead of embedding it in a link. The simple

PHP
> scripts I have written seem to work fine except for this. What am I
> missing?
>
> My configuration is as follows:
> Apache/1.3.28 (Win32), PHP/4.3.4, on Win 2K.
>
> Apache is running in a command shell, not as a service. I have PHP

loading
> as a DSO, not as CGI, and have added the following lines in my httpd.conf:
>
> LoadModule php4_module "c:/php/sapi/php4apache.dll"
> AddType application/x-httpd-php .php
>
> Thanks!
> -Kelly
>
>
>



Reply With Quote
  #3 (permalink)  
Old 12-06-2003
wedger
 
Posts: n/a
Default Re: newbie querystring variables

Kelly Soden wrote:

> I am new to PHP and am having problems using variables passed in a
> querystring. For example:
>
> <html>
> <head>
> <title>submit-vars.html</title>
> <body>
> <a href="http://localhost/print-vars.php?id=1"> test</a>
> </body>
> </html>
>
> <html>
> <head>
> <title>print-vars.php</title>
> </head>
> <body>
> <p>The query string is: <?php echo $_SERVER['QUERY_STRING']; ?></p>
> <p><? echo $_GET['id'] ?></p>
> <?php printf("\n</br>print variable here->%s",$id); ?>
> </body>
> </html>
>
> Clicking on the link in submit-vars.html calls print-vars.php producing
> the following html source:
>
> <html>
> <head>
> <title>print-vars.php</title>
> </head>
> <body>
> <p>The query string is: id=test</p>
> <p>test</p>
>
> </br>print variable here-></body>
> </html>
>
>
> From the tutorials I have read, it is my understanding that PHP
> automatically create a variable when it sees a name=value pair in a
> querystring. Therefore I would expect the word "test" to again be printed
> after "print variable here->". The behavior is the same if I submit the
> querystring using a form instead of embedding it in a link. The simple
> PHP
> scripts I have written seem to work fine except for this. What am I
> missing?
>
> My configuration is as follows:
> Apache/1.3.28 (Win32), PHP/4.3.4, on Win 2K.
>
> Apache is running in a command shell, not as a service. I have PHP
> loading as a DSO, not as CGI, and have added the following lines in my
> httpd.conf:
>
> LoadModule php4_module "c:/php/sapi/php4apache.dll"
> AddType application/x-httpd-php .php
>
> Thanks!
> -Kelly



In my setup, I get the following source code (as expected):
--
<html>
<head>
<title>print-vars.php</title>
</head>
<body>
<p>The query string is: id=1</p>
<p>1</p>

</br>print variable here->1</body>
</html>
--

The line:
printf("\n</br>print variable here->%s",$id);
prints the variable $id, which has the value '1' (set as a GET-variable in
the link on the first page).

Test is just the linked text on the first page, and does not get passed on
to the second page.

If you wanted the value 'test' transferred, you should have written:
<a href="http://localhost/print-vars.php?id=test">test</a>
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:29 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0