Forum Moderators: coopster
example with $_POST
<form action="search.php" method="POST">
Search String::<input type="text" name="searchString">
<input type="submit" value="Search">
</form>
search.php
echo "You searched for ".$_POST['searchString'];
echo "You searched for ".$_POST['searchString'];
Although this "works," you need to be aware that this type of coding is the "foundation" of cross site scripting.
If user input is echoed back to the page results it can be crafted to inject cross site scripting or mysql injection.
Try this (using a get method for this example, but the same thing can be done using post via command line:)
http://www.example.com/yourscript.php?searchString=%22%3E%3Cscript%3Ealert%28123%29%3C%2Fscript%3E%22
Change example.com to your domain, yourscript.php to your script. If you get a Javascript alert, view the source of the resulting page. What you will see is
You searched for <script>alert('123')</script>
If the script content is anything but the harmless alert, you have big trouble on your hands.
It gets worse, this same approach can be abused for mysql injection.
http://www.example.com/yourscript.php?searchString=%20OR%201=1
Be mindful of this, filter your input and output only cleansed data back to the browser.