Jump to content

htmlspecialchars and javascript injection


fohanlon

Recommended Posts

Hi Guys

 

I have only realised that it is possible to injection javascript <script> tags in form fields.

 

I read that htmlspecialchars will solve this by encoding < as %lt; etc.

 

However, I cannot get the function to work.  Does utf-8 encoding have an effect on the function?

 

Thanks for the help

 

Fergal.

 

Link to comment
Share on other sites

Hi

 

Just some simply code to test:

 

<?php

$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);

echo $new;

?>

 

and it outputs <a href='test'>Test</a>

 

I thought it would output <a href= ....

 

Thanks

 

Fergal.

 

Link to comment
Share on other sites

Looked at the csource and yes it is in entity form.

 

I was trying to ensure that if a user enters something like <script>alert("test")</script> in a form field that on submission of the form the alert box will not work.  The form will not write anything to a database, variables are jsut gathered and emailed in the mail function.

 

Am I right using htmlspecialchars.  I have spent hours reading forums etc and am confused.

 

Thanks,

 

Fergal.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.