/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Limit certian html tags?

I’m using a mysql database to store the data entered on my site but I don’t want users to use javascript or frames ect.

What would I do to check the data entered in the textbox before it was sent to the database?

I hope this makes since

Thanks in advance!

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 26.2008 — A server-side validator, naturally.

Just a note: [I]You[/I] can not stop users to use javascript. ?. You can choose not to use javascript in your site, which is a different issue.
Copy linkTweet thisAlerts:
@ScoobyDooobyD00authorMar 26.2008 — I've seen on sites where if I enter <script type="text/javascript"></script> it comes out on the page as < type="text/javascript"></>

I hope that makes sense.
Copy linkTweet thisAlerts:
@KorMar 26.2008 — ?

Enter where? Comes out where? Can you use the proper terms or, at least, can you be more descriptive? Detail your aim, please.
Copy linkTweet thisAlerts:
@ScoobyDooobyD00authorMar 26.2008 — I'm sorry I wasn't even paying attention to what I wrote.

For instance if I put a textbox on my site for users to enter html to there profile it wouldn't allow certian tags.

Like: The user goes to their control panel and they enter some html into the textbox
[code=html]
<body bgimg="http://someimageurl.com">
<iframe width="*" height="*" src="http://someurl.com"></iframe>
</body>
[/code]


I don't want users to use frame, iframes, javascript, flash, php ect

So I want the javascript to search what the user entered (above) and take out specific words so when it is sent it to the database it looks like this
[code=html]
<body bgimg="http://someimageurl.com">
< width="*" height="*" src="http://someurl.com"></>
</body>
[/code]


Again I'm sorry I didn't explain myself more.
Copy linkTweet thisAlerts:
@KorMar 26.2008 — 
Again I'm sorry I didn't explain myself more.[/QUOTE]

Nor you did more this time ?

I don't want users to use frame, iframes, javascript, flash, php ect
[/QUOTE]

I guess you wanted to say that [B][I]you[/I][/B] don't want to use frame, iframes, javascript, flash, php etc. in your page...

So I want the javascript to search what the user [I]entered[/I] (above) and take out specific words [..]
[/QUOTE]

entered? [I]Where[/I] entered? In a textarea? Or? [I]Where[/I] the user should enter? And [I]what[/I]?

Still very confusing for me... I would like you to explain more about what your project is, what do you want to do and why.
Copy linkTweet thisAlerts:
@ScoobyDooobyD00authorMar 26.2008 — Ok, give me about 10 minutes to make a video explaining
Copy linkTweet thisAlerts:
@ScoobyDooobyD00authorMar 26.2008 — Ok, heres the video, I hope it makes sense

http://brwpages.com/movies/blockwords.swf
Copy linkTweet thisAlerts:
@SyCoMar 26.2008 — If you don't use server side scripting (like PHP), circumventing your validation is as easy as turning off javascript in the users browser. Then I can post all the script/PHP tags I like and pwn your server ?

In php it's you can do this

[code=php]
<?
$_POST['inputed_value']=" remove these tags <iframe></iframe><? ?> <?php <script> </script> they should be gone<br><br>";
echo $_POST['inputed_value'];

//create an array of banned words
$banned_words=array('<iframe>','</iframe>','<?php','<?','?>','<script>','</script>');

//loop throught he array and replace th banned word with '' (nothing)
foreach($banned_words as $v){
$_POST['inputed_value']=str_replace($v,'',$_POST['inputed_value']);
}

echo $_POST['inputed_value'];
?>[/code]
Copy linkTweet thisAlerts:
@ScoobyDooobyD00authorMar 26.2008 — AWESOME!!! Thank you so much!
Copy linkTweet thisAlerts:
@SyCoMar 26.2008 — no worries. I've omitted the submitted conditional for clarity but you get the idea.

You can read up on the str_replace() here.

http://us3.php.net/manual/en/function.str-replace.php

It's a good idea to understand what and why you're doing stuff, so please read up. Like I say if you'd used jS you'd have been wide open. I could have entered a simple drop table statement guessed your table names and wiped out your data.

And go easy on them Scooby-Snacks, they mess you up. ?

Edit: actually I wouldn't have bneeded to guess the table names, I coul just read them with PHP too. Allowing users to input scripts of any kind (html included) is a potential hole so consider how you do this. Similar methods to BBcode is the usual way to allow users to template.
Copy linkTweet thisAlerts:
@KorMar 26.2008 — My first thought was the good one. A server-side validator, as I said. I was not sure of the server-side language accepted, but if php, yes, [B]SyCo[/B]'s code looks ok to me ?
Copy linkTweet thisAlerts:
@ScoobyDooobyD00authorMar 26.2008 — Thanks both of you!
×

Success!

Help @ScoobyDooobyD00 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...