php-general Digest 27 Mar 2005 16:35:29 -0000 Issue 3362
Topics (messages 211650 through 211667):
Re: Avoiding SQL injections: htmlentities() ?
211650 by: Chris Shiflett
211651 by: Ryan A
211652 by: tg-php.gryffyndevelopment.com
211653 by: Chris Shiflett
211661 by: Jasper Bryant-Greene
211667 by: Raj Shekhar
live records
211654 by: Ryan A
211660 by: Burhan Khalid
211662 by: Jasper Bryant-Greene
setcookie issue
211655 by: John Hinton
211657 by: Chris Shiflett
211659 by: John Hinton
Re: NetFlix Drag and Drop Row Ordering
211656 by: Burhan Khalid
Re: create multiple jpg thumbnails and use in a page
211658 by: Jasper Bryant-Greene
Re: auto appending .php extension
211663 by: Jasper Bryant-Greene
Getting values from the Javascript namespace
211664 by: Daniel Lahey
Re: So this isnt a bug?
211665 by: Aaron
Illegal string offset error in array
211666 by: Johannes Findeisen
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Chris Ramsay wrote:
This is excellent:
http://www.shiflett.org/
I'm glad you think so. :-)
There's a free article there on SQL injection:
http://shiflett.org/articles/security-corner-apr2004
I'm always refining the methods in which I explain things like SQL
injection, so my replies on this thread might be as good or better than
that article. The article also has user comments at the bottom, so you
might find something useful there also.
Hope that helps.
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
--- End Message ---
--- Begin Message ---
Hey!
Thanks for replying.
I was just going to write to you (after your last reply to my questions)
that someone recommended your site and after i made a quick visit...if you
could direct me to the exact page/section...guess you read my mind :-D
Thanks,
Ryan
On 3/26/2005 7:47:36 PM, Chris Shiflett ([EMAIL PROTECTED]) wrote:
> Chris Ramsay wrote:
>
> > This is excellent:
>
> >
>
> > http://www.shiflett.org/
>
>
>
> I'm glad you think so. :-)
>
> There's a free article there on SQL
> injection:
>
>
>
> http://shiflett.org/articles/security-corner-apr2004
>
>
>
> I'm always refining the methods in which I explain things like SQL
> injection, so my replies on this thread might be as good or better than
> that article. The article also has user comments at the bottom, so you
> might find something useful there also.
>
> Hope that helps.
>
> Chris
>
> --
> Chris Shiflett
> Brain Bulb, The PHP Consultancy
> http://brainbulb.com/
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.3 - Release Date: 3/25/2005
--- End Message ---
--- Begin Message ---
Thanks a ton, Chris & Chris! Clear, concise and informative answers are always
the best :) I knew the basic theory but never looked into the specifics on
what, exactly, could be harmful in cases like this. In cases of security
'common sense' isn't always helpful because it's the uncommon sense that'll
bite you in the behind.
Thanks again!
-TG
= = = Original message = = =
Chris Ramsay wrote:
> This is excellent:
>
> http://www.shiflett.org/
I'm glad you think so. :-)
There's a free article there on SQL injection:
http://shiflett.org/articles/security-corner-apr2004
I'm always refining the methods in which I explain things like SQL
injection, so my replies on this thread might be as good or better than
that article. The article also has user comments at the bottom, so you
might find something useful there also.
Hope that helps.
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.3 - Release Date: 3/25/2005
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
So if I could broaden the question and ask, in general, what people
recommend for pre-processing data before it goes into a SQL
statement.
For escaping, I recommend an escaping function specific to your
database. These exist for most popular databases. As a last resort, you
can escape with addslashes(), but only if your database doesn't have a
native escaping function and also escapes things like single and double
quotes with a backslash.
htmlentities()
This is an escaping function for HTML, not SQL. For HTML, I think it's
the best. :-)
Hope that helps.
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
--- End Message ---
--- Begin Message ---
Ryan A wrote:
Hi,
Just a quick question, I have been reading a lot about SQL injection doing a
s**tload of damage to many sites, I myself use a pagentation class which
sends the page number from page to page in a $_GET['page'] request which
gets used in a LIMIT parameter.
From what i have been reading, wrapping all my GET and POST requests in a
htmlentities() function should keep me safe....right? or what else should
i/can i do?
eg:
$page= htmlentities($_GET[page]);
Thanks,
Ryan
htmlentities() is for displayed data. it will not protect against SQL
injection.
The best way to protect against SQL Injection is:
for string data, mysql_real_escape_string() or your database's equiv.
function
for all other data, type-check it with intval(), floatval() etc.
--
Jasper Bryant-Greene
Cabbage Promotions
www: www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
Public Key: Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
Fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--- End Message ---
--- Begin Message ---
<[EMAIL PROTECTED]> writes:
>
> So if I could broaden the question and ask, in general, what people
> recommend for pre-processing data before it goes into a SQL
> statement.. for security and for things like making sure
> singlequotes and other special characters are escaped properly?
>
>
> htmlentities()
> addslashes() (if magic quotes isn't turned on right?)
>
> What else?
>
Using some sort of database abstraction library (Pear::Db, Aoddb) also
helps. At least Adodb escapes the slashes in a SQL statement before
it is sent for execution. Using a library also provides a choke point
and you can add your own additional checks in the library without
letting the developers worry if they have done all the checks and
validations correctly.
--
Raj Shekhar Y! : Operations Engineer
MySQL DBA, programmer and slacker Y!IM : lunatech3007
home : http://rajshekhar.net blog : http://rajshekhar.net/blog/
--- End Message ---
--- Begin Message ---
Hey all,
Been working on this nearly the whole night so i dont really know if this is
all that hard or am just braindead.
Heres what i am doing:
I am reading off an array from the users cookie called "user_cookie"
the array is a bunch of numbers like this:
254
7785
5899
540055
etc
the numbers are the cart items the user has saved and they match a
"item_number" field in my mysql db, the arrays name is $cart_arr
what i am doing is running a select * from my_db where item_number=x and
item_number=x etc based on the items stored in the array, this info will be
displayed in a neat little table when he clicks on "show items in my cart"
or something as such...so far so good, heres my problem:
sometimes items get deleted or are taken off the "active" list, when this
happens I would like to take out these times from $cart_arr....how do i do
that?
eg:
user has these items in his cart ($cart_arr):
1
2
3
4
Item number 3 has been taken taken off the active list, so $cart_arr should
now contain only
1
2
4
Thanks in advance,
Ryan
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.3 - Release Date: 3/25/2005
--- End Message ---
--- Begin Message ---
Ryan A wrote:
Hey all,
Been working on this nearly the whole night so i dont really know if this is
all that hard or am just braindead.
Probably just need a pair of fresh eyes.
[ trimmed ]
sometimes items get deleted or are taken off the "active" list, when this
happens I would like to take out these times from $cart_arr....how do i do
that?
eg:
user has these items in his cart ($cart_arr):
1
2
3
4
Item number 3 has been taken taken off the active list, so $cart_arr should
now contain only
1
2
4
You can simply unset() the key that holds that value.
So, for item three, you would say unset($cart_arr[2]); This will leave
you with a gap in the array :
1
2
4
Your array still has 4 entries, but one of them is empty. You can modify
your query loop to check for this.
Hope this helps.
--- End Message ---
--- Begin Message ---
Ryan A wrote:
Hey all,
[snip]
I am reading off an array from the users cookie called "user_cookie"
the array is a bunch of numbers like this:
[snip]
the numbers are the cart items the user has saved and they match a
"item_number" field in my mysql db, the arrays name is $cart_arr
what i am doing is running a select * from my_db where item_number=x and
item_number=x etc based on the items stored in the array, this info will be
displayed in a neat little table when he clicks on "show items in my cart"
or something as such...so far so good, heres my problem:
sometimes items get deleted or are taken off the "active" list, when this
happens I would like to take out these times from $cart_arr....how do i do
that?
Thanks in advance,
Ryan
Hi Ryan
if $item_number is your item number to delete:
if(($array_key = array_search($item_number, $cart_arr) !== false) {
unset($cart_arr[$array_key]);
}
Best regards
--
Jasper Bryant-Greene
Cabbage Promotions
www: www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
Public Key: Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
Fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--- End Message ---
--- Begin Message ---
Seems my old setcookie scripts are busted in php with globals off.
--begin code--------------------------
<?
if(isset($_POST[tpassword]))
{
setcookie ("writer", "$_GET[twriter]");
setcookie ("password", "$_POST[tpassword]");
}
$action = $_REQUEST['action'];
define (Login, 0);
define (Entrance, 1);
define (Continue_Campaign, 2);
define (Finish_Campaign, 3);
##### LOGIN PAGE
#######################################################################
function login(){
include ('config.php');
$query = "SELECT * FROM atable";
$result = mysql_db_query($DBName, $query, $Link) or
print ("Query Failed");
printf ("<center><form METHOD=\"post\"
ENCTYPE=\"multipart/form-data\" ACTION=\"%s?action=%d\">\n",
$PHP_SELF, Entrance);
echo "<table><tr><td>\n";
echo "Writer Name: </td><td><select name=\"twriter\" size=\"0\"
VALUE=\"$writer\">\n";
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"" . $row[0] . "\">" . $row[0] . "\n";
}
echo "</select>";
echo "</td></tr><tr><td>Password: </td><td><INPUT TYPE=password
NAME=\"tpassword\" SIZE=10 VALUE=\"$password\"\n>";
echo "<tr><td colspan=\"2\"><INPUT TYPE=\"submit\" NAME=\"button\"
VALUE=\"Enter Reporter Area\"></td></tr>";
echo "</td></tr></table>";
echo "</center></form>";
---end code---------------------
When I run this, the cookies aren't transfered to the second action
switch on the first load, but if I hit reload, they appear. So, to the
user, they are presented with logging in twice unless they know this odd
trick.
Any ideas about how to make this work on the first time through? This is
driving me nuts on two sites at the moment.
Thanks,
John Hinton
--- End Message ---
--- Begin Message ---
John Hinton wrote:
Seems my old setcookie scripts are busted in php with globals off.
Use $_COOKIES['name'].
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
--- End Message ---
--- Begin Message ---
Chris Shiflett wrote:
John Hinton wrote:
Seems my old setcookie scripts are busted in php with globals off.
Use $_COOKIES['name'].
Chris
The thing is, on the next action switch
print_r($_COOKIE);
returns empty until I refresh the browser. So, thusly, the second page
load brings in the cookies.
And sorry about that $_GET I left in the earlier post. I was trying
about anything to see if I was missing something totally.
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
I don't see anything special about my Netflix queue. Am I missing
something there? And I have no idea what "Flex" is referring to, so I'll
check that out if anyone lets me know where. :o)
Sorry about that, I was referring to Macromedia Flex.
http://www.macromedia.com/products/flex
This page has a few demos, try the Flex Store demo, which has an
excellent example of the many controls available in Flex :
http://www.macromedia.com/devnet/flex/example_apps.html
To see the drag and drop control, click any product image and drag it to
the shopping cart.
--- End Message ---
--- Begin Message ---
Kevin Coyner wrote:
From php.net, I've found plenty of examples of how to create thumbnails
from files and have done a couple successfully. My objective, however,
is to have a page dynamically create multiple thumbnails from full sized
images. I don't want to be creating and saving thumbnails to be used
later.
Possible? If so, then please just a pointer in the right direction.
Thanks, Kevin
Without going into too much detail, you just need to use one of the
examples you found on PHP.net to create the thumbnail, and then rather
than calling something like:
imagejpeg('filename.jpg');
once you've created the thumbnail, call this instead:
header('Content-Type: image/jpeg');
imagejpeg();
That will output the jpeg image to the browser. Obviously this would be
in a separate file called from the main script in an img tag, like:
<img src="thumbnail.php?file=some_file_name.jpg" />
A couple of pointers:
1. You'd want to do input checking on the file GET variable to ensure
no-one could get hold of stuff they shouldn't.
2. Make sure you don't output anything else in the file that outputs the
thumbnail, or it won't work.
HTH -- if you need more specifics let me know.
--
Jasper Bryant-Greene
Cabbage Promotions
www: www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
Public Key: Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
Fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--- End Message ---
--- Begin Message ---
Evert | Rooftop Solutions wrote:
Hi Folks,
I'm using PHP 4.3.10, the Zend Optimizer and Apache 1.3.33.
Somehow, if I want to open for example /dikkerapper.php, it is also
possible to access it through /dikkerapper (without the .php extension)
I haven't seen this before, but when I checked it also occurs on my
other servers. The thing is, it causes some big problems with
mod_rewrite. For example:
[snip]
I think you'll find that the MultiViews Apache option is enabled.
Create an .htaccess file in your web root and put
Options -MultiViews
in it.
Best regards
--
Jasper Bryant-Greene
Cabbage Promotions
www: www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
public key: Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--- End Message ---
--- Begin Message ---
Is there any way to get values from the Javascript namespace into PHP?
I want to use a value passed into a Javascript function in a query
within some PHP code in the function which is used to dynamically
populate a select's options.
TIA
--- End Message ---
--- Begin Message ---
Ive made it clear.
If I use the success_box function that uses java to redirect it works
perfectly, but if I use the header command the variables are stripped.
This is only when a $_FILE is passed.
"A. S. Milnes" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>> Aaron wrote:
>> http://bugs.php.net/bug.php?id=32449
>> I dont see how its not a bug.
>
> You might find the advice here helpful as well:-
>
> http://www.catb.org/~esr/faqs/smart-questions.html
>
> Alan
--- End Message ---
--- Begin Message ---
Hello all,
sorry if this has been asked allready but i didn't find any usefull
information in the web.
Why is this function not working in PHP5?
function getNavigationContent($content_path) {
$i = 0;
$dir = opendir($content_path);
while ($file = readdir ($dir)) {
if ($file != "." && $file != ".." && !in_array($file, explode(',',
$this->arrConf['default_filtered_files']))) {
$arrAvailableContent[$i] = $file;
if(is_dir($content_path . $file)) {
echo $n = 0;
$subdir = opendir($content_path . $file);
while ($subfile = readdir ($subdir)) {
if ($subfile != "." && $subfile != "..") {
/*
* This line does not work in PHP5 cause off an
illegal string offset in an array ERROR
*/
$arrAvailableContent[$i]['submenu'][$n]['file'] =
$subfile;
$n++;
}
}
closedir($subdir);
}
$i++;
}
}
closedir($dir);
return $arrAvailableContent;
}
Can someone help?
Regards
--
# Johannes Findeisen
--- End Message ---