GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default Form Processor - ereg

Is there a shortcut way of letting your form proceesor know that if ANY fields besides the email contain html or script tags that it should die?

Here's the code I have (from John-Marc) to keep it out of the comments text area:

PHP Code:
if (ereg('[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments'])) 
{
header("Location: error.php");
exit;

__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-26-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

Good morning dangerous!

Actually, that code is to look for url's in comments.
To check all, you need to loop through the POST array like so:
PHP Code:
 
while (list($varname,$value) = each($_POST)) {

if (
ereg('[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$value)) {
  
header("Location: error.php");
  exit;
 }  

To check for ANY html, the easiest is to strip it out and compare sizes before and after.
PHP Code:
while (list($varname,$value) = each($_POST)) {
$aftervalue=strip_tags($value);
if (
strlen($aftervalue)!=strlen($value)) {
 echo 
"$varname has code in it";
  
header("Location: error.php");
  exit;
 }  


PHP: strip_tags - Manual

Hope that helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-26-2008
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

Good morning to you also

That is exactly what I looking for as far as an example - I didn't know what to search for on the php.net site.

I'm going to try it out! I have a (what used to be a 6-page document) form for a client and I wanted to get a little lazy instead of having to put an ereg statement for every value.

Thanks so much for the response. I hope I can get this figured out. lol
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-27-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

I am sure you can get it figured out!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-11-2008
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

John-Marc,
How do I implement the code and still allow for an email address to be entered?

I need some sort of else statement right?
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-11-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

You should try it. Since an email addy is not html code, it passes through fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-12-2008
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

Thanks for your response. I actually had tried both examples and wasn't getting the results I anticipated so thought I would ask about the email address before going any farther.

When I place this:

PHP Code:
while (list($varname,$value) = each($_POST)) {
 
if (
ereg('[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$value)) {
  
header("Location: error.php");
  exit;
 }  

I get the error page regardless of what I type in (html or no html).

With the other example, it processes regardless of what I type in (html or no html).

I used a form wizard to shortcut which has some add slashes and 'what not' - I'm going to try using my other form processor and see if I can't narrow things down a bit.

Thanks as always!!
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-12-2008
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

I just tried out the wizard at: phpFormGenerator - create professional web forms in minutes

which is pretty cool as you can have the captcha function and break long forms into pages.

I like it!!
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-12-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

The first was to strip URL's and the second was for HTML code.
Well if phpFormGenerator does that for you then all the better. If not and we need to revisit, let us no.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-12-2008
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

I honestly haven't tested it to see if it allows the html code yet, but it's a super long form, and requires input in each section and finishes up with the captcha. What I'm hoping for is that it's too much of a pain to send a bunch of spam. lol

I'll let you know - as usual!
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:43 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com