OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Jun 01, 2024 5:13 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: simple, safe php-based forum
PostPosted: Fri Jan 14, 2005 3:47 pm 
Hi all!
I have a sumbiting form, fetching data from the user, saving it to a file, and then another php reading all the data.

Is there anything I should consider? For example, are there some cool-ready-to-use database functions in php?

And, is it possible for a user to type something like <?php exec("rm /etc/passwd"); ?> and make it run on my server? And for html tags: is it reasonable, to just embrace the output with <verbatim></verbatim> tags? What if.. the user typed in "blabla</verbatim><a href..."? However it would be simple to check for </verbatim> flags.

Cheers :)


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Fri Jan 14, 2005 9:30 pm 
Adek336 wrote:
Is there anything I should consider? For example, are there some cool-ready-to-use database functions in php?


Yes. There are functions for a wide variety of databases (See manual for further information).

Quote:
And, is it possible for a user to type something like <?php exec("rm /etc/passwd"); ?> and make it run on my server?


Not unless you actually want them to, and even if you did you'd have to call a function with the string they inputed. It can't be done accidentally.

Quote:
And for html tags: is it reasonable, to just embrace the output with <verbatim></verbatim> tags? What if.. the user typed in "blabla</verbatim><a href..."? However it would be simple to check for </verbatim> flags.


I really wouldn't bother letting them use raw html on a webboard. Aim for something like the BB Code this board uses, where things like [[i]] are translated int <i> by the php script. That's a lot safer than trying to deny dangerous html code on a case by case basis.


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Sat Jan 15, 2005 9:58 am 
Just before I find the proper chapter in the manual, how do I manage single characters in a string, just like good-ol' C text[offset-1] ? Is a php string null-terminated? Is there any function like memmove? How do I allocate more space for a string when I want to add a char? Are there functions to prepend data in the middle of a string? And most basically, are there any prebuilt functions which would change any "\n" into "<br>"?

Cheers ;)
Curufir: I'll look at the mysql thing, cheers ;)


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Sat Jan 15, 2005 11:29 am 
Adek336 wrote:
Just before I find the proper chapter in the manual, how do I manage single characters in a string, just like good-ol' C text[offset-1] ?


text{offset-1} will do the same thing.

Quote:
Is a php string null-terminated?


Probably, I haven't bothered checking.

Quote:
Is there any function like memmove?


No. You can't access memory directly. About the closest you could get would be to just make a copy of the variable.

Quote:
How do I allocate more space for a string when I want to add a char?


Just concatenate it. Eg $String = $String . $Char
The interpreter will take care of the messy memory allocation details.

Quote:
Are there functions to prepend data in the middle of a string? And most basically, are there any prebuilt functions which would change any "\n" into "<br>"?


Yes. In fact there's a specific PHP function for exactly that purpose ("\n" to "<br>"), but if you wanted a general way of replacing things in strings you'd use a regular expression.

Code:
eg
$string = ereg_replace("\n", "<br />", $string);


I strongly recommend grabbing a copy of the manual (http://www.php.net/download-docs.php) and running through some tutorials. Pretty much all of the standard C functionality (Aside from memory allocation and pointers) is there in one way or other.


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Sat Jan 15, 2005 3:53 pm 
I recommend using preg_replace() rather than ereg_replace() because it's faster.

Although for this case there isn't any need for either since you arn't even using regex expressions in the replace so it would be better to use str_replace() instead. str_replace() is alot faster since it doesn't parse the regex expressions.


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Mon Jan 17, 2005 2:48 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1223
Location: Sweden
$new_text = nl2br($oldtext); // "\n" to <br />

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Mon Jan 17, 2005 4:36 am 
That will work fine... well unless he wants to use HTML instead of XHTML, which I think he may since he used <br> in his post not <br />


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Mon Jan 17, 2005 6:47 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1223
Location: Sweden
so what? most people who use html and not xhtml don?t care about validation anyway.. ;)

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Mon Jan 17, 2005 8:41 am 
Another tip would be using a HTML filter
like:
Code:
$c=htmlspecialchars($_POST['message']);


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Mon Jan 17, 2005 1:47 pm 
bubach wrote:
so what? most people who use html and not xhtml don?t care about validation anyway.. ;)
Not always, people trying to give backwards compatability for browsers that don't have XHTML... and people who prefer HTML to XHTML(I know it's not alot of people... but some people just do for some reason or another. ::))

As for the validation comment... there are people who still use HTML, and keep it valid, simply because they didn't want to change it all to XHTML. Or heck some people still might not even know about XHTML and just know about HTML.(was the case for me until I started working on YaBBSE a few years ago.)

Anyway... rant over... I love XHTML.


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Tue Jan 18, 2005 10:06 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1223
Location: Sweden
OT: i have to tell you how proud i am over my new OS homepage in XHTML..
lots of hours spend on divs and css-classes.. ;-)
a preview can be found at http://bubach.1go.dk/BOS/test/

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Tue Jan 18, 2005 3:05 pm 
Looks good. :)


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Wed Jan 19, 2005 5:47 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 9:01 am
Posts: 842
This is what i got.
was that some test text or something else?

_________________
Only Human


Top
 Profile  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Thu Jan 20, 2005 4:49 am 
Read the url... it says "test". ;)


Top
  
 
 Post subject: Re:simple, safe php-based forum
PostPosted: Fri Jan 21, 2005 3:34 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1223
Location: Sweden
yeah, it?s only for filling up space.. ;)

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group