tags:

views:

62

answers:

3

Hi. I'm trying to make a small script for my site where the user would go to the page, lets say, http://example.com/test.php?p=22. From there, a script would read the 'p' variable, and result with a hyperlink going to http://example.com/diffdir/22.exe. So far, this is what I have coded:

<?php
 $test = $HTTP_GET_VARS['p'];
 ?>
 <a href="diffdir/".$test.">Test</a>

Now, I would think that inserthing that $test into the <a href> would do the trick, but sadly the hyperlink only leads to http://example.com/diffdir. Would anyone mind pinpointing what I am doing wrong?

A: 

Use $_GET instead of HTTP_GET_VARS, it is deprecated.

And, you need to put the variable into PHP tags:

<a href="diffdir/<? echo $test; ?>">Test</a>
Pekka
+2  A: 
  • $HTTP_GET_VARS is deprecated, try use $_GET instead.
  • Your 'link' is outside of php tags, by the way, so the interpreter won't execute $test, hence, can't fill in your desired value ..

     <?php  
        $test = $_GET['p'];
     ?>
     <a href="diffdir/<?php echo $test ?>">Test</a>
    
The MYYN
Even when I use that (I even copy and pasted just to make sure our script are the exact same), it still only brings me to http://test.com/diffdir.
PuppyKevin
Could it be that your scripts are not being parsed by PHP at all? Can you paste the actual HTML source code here?
Pekka
What you see is all that I have. Would it not be as simple and grabbing the p variable, and inserting it into a link?
PuppyKevin
I mean the actual HTML that your script is producing in your browser? From "View" > "Source code"?
Pekka
Oh, my bad. Here you go:<a href="diffdir/".22.">Test</a>
PuppyKevin
A: 

Directly passing data from the URL parameters in $_GET into your HTML output may result in a security threat. Anybody could create a link that leads to your script and passes ANYTHING into the page that the person who is following the link will get, for example harmful javascript code, unwanted ads, etc.

Alway filter input data for possible threats before using it for anything.

Techpriester
Why of course. I'm just getting the main script to work. After that, I'll only make it work with 2 numbers.
PuppyKevin