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> &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > > > |
|
|||
|
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> |