![]() |
alternative to die() function and echo?
hi, is there an alternative to writing die functions in something like this?
Code:
would i be needing to learn javascript to test for empty textfields.. what im wondering is how secure can that be? because what if someone were to grab the forms action url and make himself a local file on his desktop calling the form on his local pc with sql injection or xss. this is what i mean Code:
|
I would use Jooney to send the form across with ease but if you wanted to do it without a framework it would be something like this
Quote:
Quote:
|
You could alternatively use your own error handler in conjunction with trigger_error() instead of die() if all you're doing is looking for another way to show that something went wrong.
Never trust javascript to do anything that you need to make sure is done. Especially form validation - take care of everything server side, then if you want to add additional "usability", work your javascript or ajax into it afterwards. Frameworks. Pssht. :-D It sounds like you're asking how to validate a form field, more than how to return the error from it though, is this correct? -m |
Quote:
example of a form Code:
Code:
|
lol i dont know how i went from asking one question to changine the question :p i need rest lol
|
Hi
An attacker can bypass your javascript validation by creating a program(script) that will send a post header to the file you specify in <form action="file.php"> Or the easiest method I guess is deactivating javascript support in his broqser :) javascript is never reliable on security, but you can implement javascript validation just to show users that the name, email or whatever they entered is not wrong, so they don't have to wait the whole reload for your php script to tell them this. In the example above, there is no xss because you don't show the input variables in the browser, however the sql inj, might work |
There's a couple things you're going to want to do when you accept a form, and a lot of resources for reading a variety of different ideas on how to get it done. I could post you the methods I use to sanitize and then validate data when it comes in through a form, but honestly when it comes to security I think it's something you really should understand fully what you are accomplishing, otherwise the opportunity for something to slip through is rather huge.
Generally the process takes atleast a couple steps; 1. Sanitize all incoming data. This is where you catch most xss and sql injection type vulnerabilities by cleaning your form data of any corrupt or malicious entries. Check out such functions as trim(), htmlentities(), htmlspecialchars(), strip_tags(), and addslashes(). Also be sure to read up on magic_quotes_gpc when you get to that last one, as some servers mistakenly have this turned on, requiring you to do some extra coding in order to deal with it. 2. Validate incoming data to make sure you're getting the right kind. Again, there's various ways of doing this, such as using ctype functions, preg_match(), filter_input() and filter_var(), or completely writing your own from the ground up (though that usually requires some regular expresssions and preg_match() anyways.) Once again, never trust javascript. Never. Ever. -m |
PHP Code:
|
Code:
class Kill extends Homicide { |
| All times are GMT. The time now is 02:16 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0