daydreamer Posted October 15, 2008 Share Posted October 15, 2008 I have a contact form, which asks for name, email and a message, then emails the message to me. Is there any function I should be using to escape characters to prevent people running code in my PHP? e.g if they submit ".exit;." as the message it might run? Thanks. Link to comment https://forums.phpfreaks.com/topic/128518-html-form-php-security/ Share on other sites More sharing options...
Masna Posted October 15, 2008 Share Posted October 15, 2008 Running PHP code from a form = not possible. However you might want to escape using htmlspecialchars() to prevent JavaScript hacking. Link to comment https://forums.phpfreaks.com/topic/128518-html-form-php-security/#findComment-666022 Share on other sites More sharing options...
Andy17 Posted October 15, 2008 Share Posted October 15, 2008 Unless you're echoing the form value, you shouldn't worry about people running PHP codes. If you for some reason plan on echoing one of the form values, you could try something like this: <?php $message = $_POST['your_form_field']; $message = strip_tags(htmlspecialchars($message, ENT_QUOTES)); ?> This also protects you from JavaScript hacking like Masna wrote. Link to comment https://forums.phpfreaks.com/topic/128518-html-form-php-security/#findComment-666025 Share on other sites More sharing options...
daydreamer Posted October 15, 2008 Author Share Posted October 15, 2008 I dont plan on echoing the form values, just emailing them to me. Will I still need to use the above code to prevent code injection? Thanks. Link to comment https://forums.phpfreaks.com/topic/128518-html-form-php-security/#findComment-666026 Share on other sites More sharing options...
Shaun Posted October 15, 2008 Share Posted October 15, 2008 if your not using any sql, you dont have to worry about injection? Link to comment https://forums.phpfreaks.com/topic/128518-html-form-php-security/#findComment-666041 Share on other sites More sharing options...
daydreamer Posted October 15, 2008 Author Share Posted October 15, 2008 ok cool. its just im sure i read somewhere that it was possible for hackers to inject code into php. Link to comment https://forums.phpfreaks.com/topic/128518-html-form-php-security/#findComment-666056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.