Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
I working on a script that will allow users to upload text fields which will be displayed on an HTML page. (Kind of like here, I guess [Linked Image]

I want to strip out any HTML, or anything else that could have security risks.

Would this be adequate?
$text =~ s/<.*>//g;

Or is it neccessary to explicitly check for scripting keywords like the UBB does in ubb_library.pl/sub check_html?

Sponsored Links
Joined: Mar 2000
Posts: 615
Member
Member
Offline
Joined: Mar 2000
Posts: 615
I don't know much about perl, but wouldn't it be

$text ~= s/<.*)>//g;

?

Back to the question, removing all HTML tags would be fine, but you might wanna do:

$text ~= s/<(.*?)>/& lt;$1& gt;/g;

without the spaces for & lt; and & gt;.
that'll allow you to display all HTML, but not process it as HTML.

------------------
JohnM - moderator of server side scripting


This message has been edited by JohnM on January 23, 2001 at 04:35 PM

Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Thanks for the response [Linked Image]

I don't understand your first regex:
$text ~= s/<.*)>//g;
Should that be:
$text ~= s/<.*?>//g;
If so, that makes sense, and would be better than the regex I posted, since it would avoid removing text in between HTML tags.

Your second regex is a good idea too. However, I can't think of any good reason to display the HTML, so I'm more inclined to stick with just removing the tags.


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Gizmo
Gizmo
Portland, OR, USA
Posts: 5,833
Joined: January 2000
Forum Statistics
Forums63
Topics37,575
Posts293,930
Members13,823
Most Online6,139
Sep 21st, 2024
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2025 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.1
(Snapshot build 20240918)