Discussion:
[PHP-INSTALL] multi threading
kranthi
2008-07-08 11:45:51 UTC
Permalink
hi all,

i m using a single php script to do several jobs using if statements(for
example /login.php?action=profile instead of profile.php). but one of my
friend said that since php is unable to handle multi threads this is not
advisable. how far is it true????
Max Thayer
2008-07-08 13:12:23 UTC
Permalink
The practice of sending request/response variables to determine what
action or process to perform isn't exactly multi-threading.

What you need to be aware of is cross-site scripting attacks and
cross-site request forgery; XSS and CSRF (pronounce see-surf)
respectively. First two concepts to study up on will be:

Filter input
Validate output

http://en.wikipedia.org/wiki/Cross-site_scripting
http://www.owasp.org/index.php/Cross-Site_Request_Forgery

Chris Schiflet has made a name for himself writing about the subject.
http://shiflett.org/articles/cross-site-request-forgeries is a direct
link to his blog on CSRF.

Max H. Thayer
Software Developer
Center for High-Throughput Structural Biology

Hauptman-Woodward Medical Research Inst.
700 Ellicott St.
Buffalo, NY 14203
Phone: 716-898-8637
Fax: 716-898-8660
http://www.chtsb.org
http://www.hwi.buffalo.edu
-----Original Message-----
From: kranthi [mailto:***@gmail.com]
Sent: Tuesday, July 08, 2008 7:46 AM
To: php-***@lists.php.net
Subject: [PHP-INSTALL] multi threading

hi all,

i m using a single php script to do several jobs using if statements(for
example /login.php?action=profile instead of profile.php). but one of my
friend said that since php is unable to handle multi threads this is not
advisable. how far is it true????
mike
2008-07-08 18:31:14 UTC
Permalink
Actually I'd change that slightly:

1) Filter/sanitize input (php.net/filter works great for this)
2) Sanity check input (bounds/type checking and then check if it is
legit against the datasource)
a) I use intval() when I expect numeric input. It will scrub out
anything that isn't an integer. Depending on your needs, additional
functionality like a regexp or substr() might be needed but that's up
to you. Remember to get it into the right type first.
b) I always include a default value in case the value does not exist
from the input too.
3) Store data in its original form, do encoding/other things at
runtime on output
4) Encode output (so the browser is not gven <script> tags but
&lt;script&gt; for untrusted content for example)

When dealing with db queries, use mysql_escape_string or equivalent at
runtime, prior to the query. Makes it easier to keep track of things
that way, instead of escaping the data up top.

example:

# sanitizing, filtering
$foo = filter_input(INPUT_GET, 'foo', FILTER_SANITIZE_STRING);

# if default value is needed
if(empty($foo)) {
$foo = 'default value';
}

# escaping - could make this into a single line too by using sprintf
or other things.
$foo = mysql_escape_string($foo);
$result = db_query("SELECT foo FROM bar WHERE baz='$foo'");

for numeric input:

# sanitizing, filtering - you'll get a type int with anything
malicious scrubbed out already
$foo = intval(filter_input(INPUT_GET, 'foo', FILTER_SANITIZE_NUMBER_INT));

# bounds checking examples (assume $maxpages has already been determined)
if($foo < 0 || $foo > $maxpages) {
redirect user back to foo.php?foo=1
}

(pretend $foo is the page number. I could have made a better example there)
kranthi
2008-07-09 10:08:13 UTC
Permalink
tnkz for the reply...

but i intended to know bout performance/speed aspects(srry if i misused the
term "multi threading" ter).... i m afraid that this post is going towards
security issues...

wat i wanted to know is which is better (in terms of speed and performance)

- /login.php?action=profile *or*
- /profile.php

Loading...