Jump to content

[SOLVED] Messing up PHP


Ell20

Recommended Posts

Hi,

 

I have a messaging system where players can message each other in the game.

However if a player sends a message which contains --> there inbox dosent display correctly.

 

The code which sends the message to the database is:

 

$mailtext = addslashes(strip_tags($_POST['chat']));

 

Has anyone got any idea what I can do to stop this happening?

 

I have tried: - $mailtext = stripslashes(strip_tags($_POST['chat']));

                - $mailtext = stripslashes(trim($_POST['chat']))

 

But none of these combinations solved the problem.

 

Thanks for any help

 

Elliot

Link to comment
Share on other sites

Try using htmlentities($_POST['chat'], ENT_QUOTES) for when it's displayed on a page, and use mysql_real_escape_string() when you are putting it into the db.

 

Addslashes lull developers into a false sense of security in this respect.

Link to comment
Share on other sites

So something like this:

 

$mailtext = htmentities(ENT_QUOTES($_POST['chat']));

 

Thanks

 

ENT_QUOTES isn't a function, its a constant. It's meant to be used as such:

 

$text = htmlentities($_POST['chat'], ENT_QUOTES);

 

Also, to clarify, it's htmlentities, not htmentities (the L is crucial)

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.