Re[2]: [PHP] Super bizarre changing variable!!

2007-10-05 Thread Richard Davey
Hi Brian,

Friday, October 5, 2007, 1:28:35 PM, you wrote:

 This is indeed the complete code, I did not cut anything out for  
 brevity, which is why this appears to be so impossible.

 eAccelerator is activated, could something be corrupt? Could a  
 corrupt index cause this?

 In table1, `referer` is int(12).
 In table2, `data` is text
 In table2, `friend_id` is mediumint(9) - which I see is a problem in  
 some cases, $referer can (rarely) be 10 digits long, so I just  
 changed it to int(12)

The number in () after the int doesn't apply to the number of digits
it can contain. A mediumint field will never hold a value above
16,777,215 assuming you are using an unsigned field, otherwise the
limit is a mere 8,388,607 - neither of which are big enough to hold the
value you're trying to put into it (69,833,818)

An unsigned int field MAY be enough, the limit being 4,294,967,295 -
but if you've got a 10 digit value LARGER than this, it'll still fail.
Meaning you either need to use a bigint field, or rethink how you are
storing these values in the first place.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Super bizarre changing variable!!

2007-10-05 Thread Richard Davey
Hi Brian,

Friday, October 5, 2007, 2:10:32 PM, you wrote:

 I definitely misunderstood what you guys are saying about the length.
 That's clearly a problem for a lot of my values.

 I can switch them both to bigint. One table has 34,000,000 records  
 and it's OK if this is hung up for a few minutes but not much longer  
 than that - any chance this change might take longer than 5 or 10  
 minutes?

Impossible to quantify to be honest - it will depend a lot on what the
server is doing at the time, how much RAM/CPU it has, etc. I'd
recommend duplicating the table to a different server entirely (a
local test box perhaps) and then running the change and timing it.

It's the only way you'll really know - at the very least I'd strongly
recommend you take the MySQL server totally offline when you make the
change. Not only will it do it faster, it will avoid anyone on the
site browsing into a world of pain.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Super bizarre changing variable!!

2007-10-04 Thread Richard Davey
Hi Brian,

Thursday, October 4, 2007, 4:50:09 PM, you wrote:

 I'm running the following code:

 $query3 = DELETE FROM table1 WHERE referer=$referer ORDER BY  
 creation LIMIT $numtodelete;
 $result3 = mysql_query($query3);
 $string = $total found, $n kept, $numtodelete extras removed  
 ($query3);
 $x = mysql_query(insert into table2 (friend_id,data) values  
 ($referer,'$string'));

 I created the table2 log file just so I could see what the hell is  
 going on. Here is a typical entry in table2:

 FRIEND_ID = 8388607

 DATA = 908 found, 100 kept, 808 extras removed (DELETE FROM table1  
 WHERE referer=69833818 ORDER BY creation LIMIT 808)

 Notice that the value in FRIEND_ID, which was set with $referer, is  
 DIFFERENT than the value of $referer shown in DATA! How the flying  
 f*^%k is this possible??? I've been tearing my hair out for 3 days  
 over this.

 Almost all records show 8388607 in that FRIEND_ID field. Once in a  
 blue moon, a different value is shown, which does match the value in  
 DATA. So it's displaying this erroneous behavior 95% of the time but  
 not always.

What data type do the referer / friend_id columns have in MySQL? int?
tinyint? etc

Also show all of your code - there is no way that the value changes
between lines 1 and 4 in the code above, which means you've missed
something out (probably for post brevitys sake)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Opening a file

2007-09-05 Thread Richard Davey
Hi Dan,

Wednesday, September 5, 2007, 3:24:43 PM, you wrote:

 Opening this file is proving to be a pain. I have a folder that contains a
 PHP page and a text file. I am trying to open the contents of the txt file
 using file() but it keeps erroring out. Below is the code I'm using to try
 and open it:

 ?php
 $fruit = apple);
 $lines = file(fruits.txt);
 if (in_array($fruit,$lines))
   {
   $a = Y;
   }
?

 So, I'm setting my variable, opening my file as an array in $lines, then
 checking to see if my variable is in the array, and if it is, assign a value
 ot a new variable.  However, I am getting the following error:

 PHP Warning: in_array()
 [function.in-arrayhttp://develop1/credit%20card%20processing/function.in-array]:
 Wrong datatype for second argument

The call to file() has probably failed.

Check to see if $lines === false, if so that is your problem. In which
case you probably need to address the path to fruits.txt, or check
file permissions.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting a 'newline' out of a string

2007-08-10 Thread Richard Davey
Hi Faither,

Friday, August 10, 2007, 5:16:09 PM, you wrote:

 I'm kind of lost with how str_replace , preg_replace, ereg_replace or
 even explode are handling a \n-ewline.

 I have a text string from a form and am trying to replace the \n or 
 chr(10) or however you might call the newline with a simple html break tag.

Why not just use nl2br() in this case?

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recursion and threaded message boards...

2007-08-10 Thread Richard Davey
Hi Tony,

Friday, August 10, 2007, 5:23:28 PM, you wrote:

 I have to write some PHP backend code for a threaded message board.
 The db has a message table, and each message has a parent id.

 Does anyone have any advice for someone whos never done this in PHP?

 I'm currently thinking that I write function that takes a db row as
 an argument, and initially, it is passed the root node of the whole
 tree. It is also probably passed a string variable.

 The first thing it will do is append the code for itself to the string.

 Then it will query the DB for all its children (with an order by post
 timestamp), and for every child, it will call itself on that child row.

 Am I on the right track? (I've done simmilar things in C++, just not in
 PHP)...

To be honest this is less of a PHP issue (at this stage) and more of a
SQL one. What SQL package are you using? (MySQL? if so v4 or v5?). I
would strongly consider looking at using a nested set system for the
structure (or at least a derivative of it, there are many good ones
out there) in combination with a standard parent/child hierarchy.

You can wrap up nearly all of the complexity of this requirement (i.e.
the tree walking / retrieval) on a stored procedure level with some
decent table design.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Friday morning brain farts....

2007-08-10 Thread Richard Davey
Hi Stut,

Friday, August 10, 2007, 4:44:14 PM, you wrote:

 On my production servers error_reporting is set to E_ALL,
 display_errors is off and log_errors is on. I get an email from each
 server containing the contents of the error log from the previous
 day and my first task each day is to go through that and track down
 any issues that usage has highlighted.

Snap :)

We do exactly the same here. The PHP log is checked first thing every
morning for notices, fatal errors, etc. The notices are especially
useful to finding out where other devs have forgotten (or incorrectly
named) variables, etc - as a number of people work on the sites each
day.

I wrote a very simple script that parses the log file into a web page
and colour codes each element (red = fatal, green = notice, yellow =
warning). We can also inject developer notes into it (using
error_log() with some set keywords at the start) which appear in blue.

Here's a small grab from an internal development server log:

http://www.corephp.co.uk/images/php_error_log.jpg

Simple, but effective.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Friday morning brain farts....

2007-08-10 Thread Richard Davey
Hi Robert,

Friday, August 10, 2007, 4:13:02 PM, you wrote:

 On Fri, 2007-08-10 at 11:00 -0400, Daniel Brown wrote:

 Remember to clean that input before you sit down at the table, there, 
 boy!
 
 It's safe to ignore the `Undefined index` notices.  That will just
 appear if a variable is referenced without first being instantiated or
 defined.  No biggie, just put this at the head of your code:
 
 ini_set(error_reporting,E_ALL  ~E_NOTICE);

 I'm in the that's sloppy and poor style camp for the above setting.

I've got to agree. A clean E_ALL error log is a good error log.

It's not like it's hard to fix.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] manual vs. meta refresh

2007-08-10 Thread Richard Davey
Hi Kevin,

Friday, August 10, 2007, 7:26:30 PM, you wrote:

 I doubt this, but is there any way to determine via PHP if a browser  
 was refreshed automatically via a META tag vs the person clicking the
 refresh button?

You could dynamically generate the meta tag, so it refreshes to your
page with some extra parameter that wouldn't exist if someone just hit
F5. It's not foolproof (as the meta tag can of course be seen in plain
text), but it should give you a high success rate.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Hosting cost

2007-08-10 Thread Richard Davey
Hi Richard,

Friday, August 10, 2007, 11:10:21 AM, you wrote:

 This is off topic so feel free to reply off list.

 My question is how much is it reasonable to charge for the following:

 1. Building a very small website (you can see it here:
 http://www.cleardebtadvice.co.uk)
 2. Hosting it for two years
 3. Providing email accounts as need be
 4. Probably a days worth of update work

Would you be re-designing the site? (God I hope so)

It's not exactly complex, but I don't know how quickly you can design,
even so I'd be looking at £200 - £250 per day spent on that.

Hosting would be barely anything for such a small site, do you already
have a host you use? If so take their prices, add your mark-up (x2)
and voila.

I'd hope the hosting would include email by default. I'd never charge
extra for this (unless the email requirements were well out of the
ordinary)

A days worth of update work.. see above.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] javascript in head or in body ?

2007-08-07 Thread Richard Davey
Hi Greg,

Tuesday, August 7, 2007, 9:52:28 PM, you wrote:

 PHP is the absolute worst language to do any sort of OO programming
 in.

Ignoring the digg user mentality of that statement, try ASP if you
want to see OO suck *royally*

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array difficulty

2007-07-31 Thread Richard Davey
Hi Carlton,

Tuesday, July 31, 2007, 2:27:46 PM, you wrote:

 I have an array like this:

 $chance = array(lowercase = 27, uppercase = 62, integer = 46);

 The values for each of the keys are randomly generated. I want to
 find the key name of the one which has the highest value. Currently, I'm 
 doing this as follows:

 arsort($chance);
 foreach ($chance as $type = $value)
 {
 $result = $type;
 break;
 }

 At this point, $result would be equal to uppercase.  I feel like
 this is a really kludgey way to accomplish this.  Is there a better way?

Not tested it, but max() should work as the first parameter can be an
array:

http://uk3.php.net/max

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Reading registry values

2007-07-30 Thread Richard Davey
Hi,

Monday, July 30, 2007, 7:40:52 PM, you wrote:

 I'm not sure that there's actually anything you'd need to access in
 the server registry (and certainly no registry in Linux if you're
 also transitioning from Windows to Linux). And depending on what the
 ActiveX control your ASP pages accessed actually does, it may be
 better to recreate it in PHP instead of trying to access ActiveX via
 PHP.

I've seen ASP components that required access to the registry in order
to validate they were legal. I.e. the installer of the component wrote
some serial number or something to the registry, which the ASP scripts
checked.

Nasty, but true. Just saying that he may well have a genuine need for
it.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to use imagestring() function with Chinese String

2007-07-28 Thread Richard Davey
Hi Davis,

Saturday, July 28, 2007, 1:54:22 AM, you wrote:

 Hi! I am trying to use the imagestring() function to put a string of 
 Chinese characters from a $_GET variable onto an image. However, the 
 characters do not display right (English is fine). Is there a way I can
 fix this or it is the limitation of the function itself? Thanks.

Using the built-in fonts will not give you Chinese character support.
You need to either build your own font, or find a True Type font that
does have the character set you require, and use the image ttf
functions instead.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] query not working properly

2007-07-26 Thread Richard Davey
Hi Joey,

Thursday, July 26, 2007, 1:36:37 PM, you wrote:

 Hi everyone,
 I'mt trying to do the below query which itself works correctly, but when I
 add a order by statement just bombs.

 $query = select * from articles where ( {$now} BETWEEN startdate
 AND enddate) and categoryid = 1 limit 0,3;

  $query = select * from articles order by startdate asc where (
 {$now} BETWEEN startdate AND enddate) and categoryid = 1 limit 0,3;

 This one just doesn't work, can you tell me what I have done wrong??

Err.. ORDER BY comes at the END of your query, not the start.

SELECT * FROM blah WHERE blahblah ORDER BY y ASC LIMIT x,y

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to get stored procedure return values via PDO?

2007-07-26 Thread Richard Davey
Hi,

I'm calling a MySQL Stored Procedure via PDO (PHP 5.2.3)

$stmt = $dbh-prepare('CALL forum_post(?, ?, ?, ?, ?, @status, @thread_id, 
@message_id)');

At the moment in order to get the values of status, thread_id and
message_id I need to issue a second query:

$sql = SELECT @status AS status, @thread_id AS thread_id, @message_id AS 
message_id;

and then foreach my way through it:

foreach ($dbh-query($sql) as $row)
{
$status = $row['status'];
$thread_id = $row['thread_id'];
$message_id = $row['message_id'];
}

Which seems a bit insane.. is there no way to do a bindValue at the
same time as I do my bindParams?

Now I write this I really can't remember why I am even putting that
second query into a foreach loop, even so it's still a step I'd like
to remove entirely if possible?

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to get stored procedure return values via PDO?

2007-07-26 Thread Richard Davey
Hi M.,

Thursday, July 26, 2007, 2:09:47 PM, you wrote:

 Richard Davey wrote:
 Hi,
 
 I'm calling a MySQL Stored Procedure via PDO (PHP 5.2.3)
 
 $stmt = $dbh-prepare('CALL forum_post(?, ?, ?, ?, ?, @status, @thread_id, 
 @message_id)');
 
 At the moment in order to get the values of status, thread_id and
 message_id I need to issue a second query:
 
 $sql = SELECT @status AS status, @thread_id AS thread_id, @message_id AS 
 message_id;
 
 and then foreach my way through it:
 
 foreach ($dbh-query($sql) as $row)
 {
 $status = $row['status'];
 $thread_id = $row['thread_id'];
 $message_id = $row['message_id'];
 }
 
 Which seems a bit insane.. is there no way to do a bindValue at the
 same time as I do my bindParams?
 
 Now I write this I really can't remember why I am even putting that
 second query into a foreach loop, even so it's still a step I'd like
 to remove entirely if possible?
 
 Cheers,
 
 Rich

 From: http://www.php.net/manual/en/ref.pdo.php

 Example 1716. Calling a stored procedure with an input/output parameter

It's not an INOUT parameter though.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Better way to store data in memory?

2007-07-25 Thread Richard Davey
Hi Richard,

Wednesday, July 25, 2007, 5:20:32 AM, you wrote:

 It's possible, maybe, that using imagecolorat and imagesetcolor (or
 whatever it is) would be faster than array access...

In the end I implemented RLE on the image data, and depending on the
image in question it is saving sometimes up to 70%, which I'm quite
happy with. I also found a neat way to avoid using a temporary
location, dropping my requirement for the massive array entirely.

 It would be Really Nifty if the GD library provided functions to
 convert a pixel column to an array and vice versa, eh?

Certainly, but I won't hold my breath. You can *almost* get a similar
result to this by holding the image data in a string and grabbing
chunks from it that way (GDs imagestring() function being a god-send
here)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Notice warnings and performance

2007-07-25 Thread Richard Davey
Hi Erfan,

Wednesday, July 25, 2007, 9:39:35 AM, you wrote:

 The site I'm working on has a lot of notice warnings, thousands. And
 they are all about: (Notice: Undefined variable..)

 I was wondering if I set the php.ini file to not log these in file or 
 display them, does all of these notice warnings still degrade 
 performance? Or does it become a performance issue only when you log 
 this on either file or display them?

You could always fix them? :)

But sure, setting PHP to ignore notices will stop your logs filling
up, and will of course result in less disk IO, so you'll get a teeny
tiny performance gain from it, but nothing to bet your life savings
on.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] global variable does not exist anymore?

2007-07-25 Thread Richard Davey
Hi Patrik,

Wednesday, July 25, 2007, 11:30:56 PM, you wrote:

 Dear my friends...

 I create a very simple script in html and php as a first step. I use suse, 
 apache2, mysql and php.

 I wonder why this script does not work:
 !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
 html
 head

   meta content=text/html; charset=ISO-8859-1 http-equiv=content-type
   titleGuru - Virtual bookstore who understands you for those want to be a 
 GURU/title


 /head
 body

 Help us for statistic data collection for increasing our service by 'filling 
 our guestbook'.br
 form action=cgi/cgibukutamu.php method=post
 table
 trtd align=rightName: /tdtd align=leftinput
 type=text name=tfnama/td/tr
 trtd align=rightLocation: /tdtd align=leftinput
 type=text name=tflokasi/td/tr
 trtd align=rightE-Mail: /tdtd align=leftinput
 type=text name=tfemail/td/tr
 trtd align=rightURL: /tdtd align=leftinput type=text 
 name=tfurl/td/tr
 trtd align=rightComments: /tdtd align=leftinput
 type=text name=tfkomentar/td/tr
 trtd align=rightinput type=submit/tdtd
 align=leftinput type=reset/td/tr
 /table
 /form

 /body
 /html

 The value of tfnama is empty.
 cgi/cgibukutamu.php
 html
 table
 trtd/tdtd/td/tr
 trtd align=rightName/tdtd align=left?php echo $tfnama 
 ?/td/tr
 /table
 /html

 I had a look the into the /etc/apache2 but I didn't find any
 global_variable switch as I used to find in httpd.conf
 
 suseonthelap:/etc/apache2 # grep -n -r global_variable ./*
 suseonthelap:/etc/apache2 #  
 

 I got used to find global_variable=on line in the httpd.conf.

Try looking in php.ini

Then leave it disabled, and code your script properly so it checks the
user input and validates it before using it.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] module loading problems

2007-07-25 Thread Richard Davey
Hi Chris,

Wednesday, July 25, 2007, 5:36:29 PM, you wrote:

 I'm running PHP 5.2.0 on windows XP SP2  lately when it starts I
 have been getting the an error when it tries to load the mysqli dll.
 It loads the standard mysql dll fine and all the dlls are in the
 same place the path and php ini file all seem to be fine. I recently
 added the exif module and now it doesn't load either. Anyone have
 any idea why these 2 modules won't load when the others do?

Have you changed anything else recently? Perhaps installing a new
version of PHP, moving some files around, updating Windows, etc?

What do you use to set the location of the PHP files? (i.e. have you
modified your System Path, or did you just throw them all into the
Windows\System folder?)

Is this with Apache or IIS btw?

My checklist would be something like this:

1) Check that the PHP.INI file you *think* PHP is using, it really is.
2) Check that you don't have redundant DLL files lurking around (in
the Windows folder for example)
3) Ensure you're using a recent enough version of the MySQL DLL for it
to work
4) Check your paths!
5) Check your dependances.. some DLLs require others.

The following may help:

http://wamp.corephp.co.uk

and

http://www.corephp.co.uk/archives/36-A-Guide-to-using-PHP-5-Extensions-on-Windows.html

Sorry that my blog is running so slow, for some reason sy3 has crawled
to a halt, while other sites on my server work perfectly. Most
annoying!

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Help needed with Curl

2007-07-24 Thread Richard Davey
Hi Daniel,

Tuesday, July 24, 2007, 2:34:06 PM, you wrote:

 In order to enable cURL on a Windows box, you have to copy
 libeay32.dll and ssleay32.dll from the DLL folder of the PHP/ binary
 package to the SYSTEM folder. (to be safe, you may want to do both
 C:\WINDOWS\SYSTEM\ and C:\WINDOWS\SYSTEM32\, but I think Windows
 allows you to `copy *.dll C:\%SYSTEM% - I'm a *nix guy, but I think
 I remember doing that on Windows a while back).

*Never* put PHP DLLs into the Windows System folder.
It's neither required, nor sensible.

Keep them where they belong - in your PHP folder.

 Then edit php.ini to remove the semicolon from the front of this
 line: extension=php_curl.dll

He must have already done this to see the output in phpinfo.

Dave - As well as the OpenSSL DLL do you also have a local certificate
created? (curl-ca-bundle.crt by default)

http://curl.netmirror.org/docs/sslcerts.html

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Help needed with Curl

2007-07-24 Thread Richard Davey
Hi Daniel,

Tuesday, July 24, 2007, 3:57:11 PM, you wrote:

 On 7/24/07, Richard Davey [EMAIL PROTECTED] wrote:
 *Never* put PHP DLLs into the Windows System folder.
 It's neither required, nor sensible.

 Keep them where they belong - in your PHP folder.


 Heh which is why I prefer to stick with what I know which
 is not so much with Windows servers, to be honest.

It's not just you - there are tutorials and mailing list posts all
over the net that impart the same advice. So I'm not surprised that
you recommended it, you probably picked it up as a byproduct of
someone else's flawed recommendation long ago :)

As a Linux person - think of the absolute *last* possible root only
place that you could ever stick a PHP library into, with the most risk
to security possible. That is the equivalent of C:\Windows\System.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Help needed with Curl

2007-07-24 Thread Richard Davey
Hi Dave,

Tuesday, July 24, 2007, 4:45:13 PM, you wrote:

 No I don't have a local certificate created.
 I'm only need to do a post using xml-rpc and I have SSLVerifyPeer turned
 off. This turns off client certificate authentication 
$xmlrpc_client-setSSLVerifyPeer(0); 

What does your PHP error log show-up? (if anything)

I assume that the site you are sending the RPC request to requires it
to be delivered over SSL? (is it the very same site that worked in the
previous build of PHP, but not this one?)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Pirate PHP books online?

2007-07-23 Thread Richard Davey
Hi Crayon,

Monday, July 23, 2007, 4:09:57 PM, you wrote:

 On Monday 23 July 2007 22:26, Larry Garfield wrote:

 So when does Rasmus Lerdorf and the Deathly Hallows open in theaters?

 They've got to make Rasmus Lerdorf and the Order of the PHP first.

Or even Rasmus Lerdorf and the Order of Function Arguments :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Better way to store data in memory?

2007-07-23 Thread Richard Davey
Hi php-general collective,

I'm building up some image data in my PHP script (ready for output to
the browser). Having to do some complex per pixel manipulation, which
is fine - but I'm just wondering is there a quicker / more efficient
way of storing the pixel data than in an array?

At the moment I hold it in $array[$x][$y], which makes the drawing
loop painless, but it's creating an array with 307,200 elements which
is proving to be quite slow. As I'm only storing fixed width byte
values is there an alternative method? For example the ability to
read/write to a chunk of memory instead? (so I can read out whole
strips of data rather than one by one?)

I was looking at the Shared Memory functions, but that isn't exactly
what I need (I don't want it shared, I want it process specific)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Better way to store data in memory?

2007-07-23 Thread Richard Davey
Hi Robert,

Monday, July 23, 2007, 6:00:50 PM, you wrote:

 What kind of data? Can't you just store it in the image? Or a working
 copy of the image?

Afraid not, I'm performing deformation on the data that requires a
temporary location before rendering to the final image. If this was a
straight single pixel change I could do it directly to the canvas as
you suggest.

 Is it possible for you to just store the entires you use? or are you
 actually storing data for 307,200 elements?

The 307,200 comes from a 640x480 image. I'm storing all elements at
the moment. I can implement RLE to save on space, and was about to
start doing that before I posted to the list to find out if I could
avoid using an array at the same time. Depending on the image RLE
itself will help considerably.

 Sure, store it in a string and treat the string as a binary chunk.

Looks like being the only way. It'd be nice to be able to create a
memblock and literally poke/peek to it (safely of course, I'm not
talking about arbitrarily writing to system memory or anything). I'll
check Pear first, but if there's no pre-built lib for it then it might
be time to create one.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: Pirate PHP books online?

2007-07-17 Thread Richard Davey
Hi John,

Tuesday, July 17, 2007, 1:02:15 PM, you wrote:

 Really?  Did you cite and pay every source you used in your book?  And
 what about those of us who downloaded books that we've bought?

Neither of these things apply to my rant, don't quote me out of
context.

 Seriously, I think you need to get a grip yourself.  When and if you 
 become that popular, and when and if PHP becomes that popular, then you
 can discuss rampant pirating of PHP books online.  But until then, it's
 more theoretical.

There's nothing theoretical about what is happening today, right this
second, and affecting genuine authors as has been demonstrated in this
thread (and I'm not talking about myself here):

http://marc.info/?l=php-generalm=118462486109342w=2

The only part of it that could be classed as theoretical is what the
net *result* of these actions are, not that it is happening.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: Pirate PHP books online?

2007-07-17 Thread Richard Davey
Hi John,

Tuesday, July 17, 2007, 2:01:42 PM, you wrote:

 So it isn't as black and white as you say. There apparently is a
 place where you can not only copy, but redistribute, and as long as
 you gave proper credit, you don't have to pay.

Citing a reference in a book to another is not the same as reproducing that
ENTIRE book wholesale, page for page, illustration for illustration.

Compare oranges with oranges please.

 First off, I'd like to know where you got that 2,000 number.  Closest I
 could find was 456 on TPB, and I'm guessing that's 456 people that have
 downloaded the torrent.  Not necessarily 456 that have completely 
 downloaded the book.

I didn't post that figure, but it doesn't matter if the actual numbers
are 2000 or just 2, it doesn't change a thing.

You said this problem was theoretical, I've proven it blatantly isn't.

I am not standing on some pulpit preaching here, I did my fair share
of cracking and spreading back in the 8/16 bit day, my slate is far
from clean - but the difference is that I *will not* hide behind any
'copyright is flawed' or 'they can afford it' facade. I'm well aware
that those actions are illegal, and I loath it when people attempt to
argue otherwise. I have far more respect for someone who says I
copied it because I can't afford to buy it. At least they are honest
about their dishonesty.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: Pirate PHP books online?

2007-07-17 Thread Richard Davey
Hi John,

Tuesday, July 17, 2007, 3:27:16 PM, you wrote:

 Citing a reference in a book to another is not the same as
 reproducing that ENTIRE book wholesale, page for page, illustration
 for illustration.

 All right, supposing I do a cut copy paste on a section of a book,
 not the whole thing, and send it out to a friend via e-mail. What if
 it's 25 percent? 15 percent? A single section of a single chapter.
 And what if you put a quote on in. That black and white is blurring
 a lot. Maybe we're not oranges to oranges, but certainly we're
 getting to orange juice:

Technically it has still breached the Copyright, Designs and Patents
Act (1988) - from a UK publication at least. I'm sure there is a US
equivalent. Open up a book on your (non-digital) book shelf, take a
look at that page a couple pages in. Chances are it will tell you all
you need to know. Here's an example from a book on my desk:

No part of this book may be reproduced or transmitted in any form by
any means, electronic, mechanical, photocopying, recording, or
otherwise, without the prior written permission of the publisher.

So no, technically I shouldn't copy and paste it into an email to you.
I see nothing blurred about this quite frankly.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Re: Pirate PHP books online?

2007-07-16 Thread Richard Davey
Hi Crayon,

Monday, July 16, 2007, 4:22:14 PM, you wrote:

 I think no matter which way you dice it, sending 1 email is a lot more
 energy efficient than printing 1 book. Just because the tree itself is
 renewable, the *energy* used in cutting it down, turning it into paper,
 turning the paper into a book and all the transporting in between, is 
 most likely not renewable.

It wasn't about comparing emails to paper, it was about stating that
at least ripping off someones book as a PDF saves the environment,
while I'd argue that the very act of reading it electronically is
still detrimental to the environment. The irony just amused me.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: Pirate PHP books online?

2007-07-16 Thread Richard Davey
Hi Jochem,

Monday, July 16, 2007, 6:11:12 PM, you wrote:

 no personal attack is intended here ... I hope you don't mind if I
 rebutt/discuss, I find it a rather interesting topic :-)

Not at all, my original post wasn't meant personally towards you
specifically, just in general.

 did you look at the list of authors? come on be realistic, the guys
 in question are all very successful in their field, to their own
 credit ofcourse :-)

 at the *very least* they can all afford laptops, internet
 connections, webhosting and everthing that goes with it ... unless
 of course they are not eating food and/or sleeping in dustbins in
 order to be able to finance laptop et al ... which is obviously
 rather preposterous

I understand the angle, but I don't believe it justifies anything. Two
guys write a book, one lives hand to mouth eeking out a meagre
existence as best he can, the other is a millionaire without a care in
the world. By your logic the value of the work of the pauper is great
than that of the millionaire. I just don't agree - they are equal.
It's the same logic people apply to software piracy (I'll take this
from Microsoft because they can afford it, but I'll buy this $10
shareware app because they're just the little guy).

It's like some false sense of Robin Hood syndrome or something :)

 1. he chose to write it, the time taken is lost regardless and there
 is no guarantee anyone would buy the book regardless of theft.

Agreed, but what you cannot factor in here is what he had planned to
do with the income from it (perhaps it was his 'retirement' fund? :)

 2. the RAAI-like 'sales lost due to piracy' argument doesn't stand up -

I agree, I wasn't going down that route. I don't believe that if
100,000 people pirated it then they lost 100,000 sales. I agree with
you that argument is flawed totally and utterly. What I don't
disagree with is that it doesn't harm the bottom-line *at all*.

 are always exceptions of course) that 'illegal distribution' of
 copyrighted content serves to drive interest and to an extent sales
 (it's often been cited that people buy music after having been
 introduced to it illegally, had they not been introduced in such a
 way they would never had come into contact with it -

I won't disagree with this, because I'm sure in a lot of cases it is
true. What I will disagree with is the assumption that it happens, and
that it somehow justifies the taking of the item in the first place.

 I believe the same argument holds for books/authors)

I don't really - there are plenty of ways for you to check out a book.
Hell book shops have entire coffee shops and comfy chairs built into
them these days, so you can read pretty much as much of a book as you
like before parting with a penny. Equally sites like Safari make
reading a book online significantly cheaper than buying it (and saves
you some trees in the process ;) - alternatively they can usually read
sample chapters on the publishers web sites, perhaps even articles
published in magazines (php|a as I'm sure you know publish whole
chapters of their nanopress books now and again).

What I'm saying is that there IS a way to experience it without taking
it wholesale. The same could be argued about music (radio, MTV,
borrowing CDs from friends, etc), but let's not go there! :)

 this is backward-assed. you can't make choice's for other people -
 regardless of the right or wrong of it it's still adds up to forcing
 your beliefs upon someone else ... which is something that just
 doesn't work in practice (not for long anyway) ... and being all
 principled is just plain unpragmatic.

It's not forcing anything, it's my right to choose how I want my work
distributed and at what price (if any). You have no right to go
against that I'm afraid, no matter how you slice the cake. If I want
to release the whole thing for free for those that cannot afford the
printed version, then so be it - but that isn't a decision you are
free to make on my behalf.

 I would never be so two-faced as to rant about pirates and 'stealing'
 software, but I hate with a vengeance those who claim what they've done
 *isn't* stealing. 

 isn't it great to be so righteous ... personally I don't get the
 hatred angle. not that I have been attempting to claim it's not
 stealing, as per society's definition, and not that I've been trying
 to suggest that abusing people's creative output is a decent thing
 to do.

 I have been trying to suggest that possibly that the concepts we
 currently hold so dearly (IP, copyright, ownership) maybe aren't the
 bastion of of light they are made out to be ... maybe there are more
 creative ways to share? maybe fear-based protectionism is not
 something we benefit from as a group in the long term?

This falls into so many different levels though. If someone was simply
emailing around a PDF then so be it, no real harm done and as you say,
it could lead to more sales eventually, but nothing you could ever
bank on and it's a risky way to run a 

Re: [PHP] I am lost

2007-07-15 Thread Richard Davey
Hi Grant,

Saturday, July 14, 2007, 8:07:43 PM, you wrote:

 Previously I had PHP on my older computer using IIS 5.1 it worked fine. But
 I'm on my new computer using IIS 7 and features like include or completely
 normal scripts that use to work no longer work. I have try to see if it's
 the web server and some of the times for the exception of the include 
 function  it is. How would I fix my main server IIS 7, is the new PHP 5.2
 fully compatible with it? If not when will a fully functional PHP be 
 available for work with IIS 7. In my php.ini file I began by using the
 recommended file and slightly modifying it enabling gd2, openssl and mysql.

PHP 5.2 works fine on IIS7. You didn't say which version of PHP you
had before you installed 5.2, but given you said that 'normal scripts
no longer work', I'll bet it wasn't 5.2, probably even PHP 4. Meaning
the changes you are seeing are because of the upgrade in PHP, not IIS.
Without you confirming though, who knows.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Php code in html buttons

2007-07-10 Thread Richard Davey
Hi k,

Tuesday, July 10, 2007, 11:59:42 PM, you wrote:

 I'm trying to make a button execute some php code when the button is
 clicked. I'm not sure if it is the button i'm coding wrong or the php code.
 Here is the code I am using.

 ?php
 echo button action='?php
 mysqli_query($connect,$query)?'Click/button;
?

Everything about this approach is wrong.

PHP is a *server side* language, not client-side.

An onclick is a client-side event. The PHP cannot be re-parsed and
acted upon when you hit onclick in the way you are trying to do.

You can either make the page reload (or go to another page) which runs
the results of the button click, or you can perform some Ajax wizardry
in the onclick event to call a remote PHP script and suck the results
back into your current page.

To be honest I'd start by reading any of the stacks of online
PHP beginners tutorials out there before touching another line of code
on this path.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: php security books

2007-07-04 Thread Richard Davey
Hi Andrew,

Wednesday, July 4, 2007, 4:23:38 PM, you wrote:

   Avoid the O'Reilly one as it is flawed.

  In what way?

 Its written by Chris Shiflett, isn't that enough reason?

No, not really. The errata are clearly published online, and while you
could argue that some of them shouldn't have existed in the text in
the first place, security is such a moveable feast that whatever is
written today will almost surely have changed within a very short period
of time, regardless of the author.

If just one person takes something useful away from his book, that
makes them think damn yes, I DO allow that in my scripts!, then it
was a worthwhile purchase. He (along with a number of others) have
done a wonderful job of raising the PROFILE of security (or lack
thereof) in PHP applications and the PHP world in general. Before the
likes of him and Steffan started blogging and writing about all the
issues out there it was a piss-poorly covered area that most
developers (*especially* new ones) ignored or were not even aware of.

Even if some of the techniques in the book are now flawed, the profile
and awareness he has generated did nothing to harm the PHP community,
and does not warrant your shit slinging.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Re: php security books

2007-07-04 Thread Richard Davey
Hi Andrew,

Wednesday, July 4, 2007, 8:29:51 PM, you wrote:

 I have no doubt he is a great bloke and a great public speaker / PR
 for PHP application level security, I apologise if it sounded like
 FUDing (why does that sound dirty?).  I just don't like / agree with
 his book or some of the security articles he wrote (again, I haven't
 read them in quite a while).  I think Ilia's book is a lot better.

Fair enough. This wasn't actually obvious from your one
sentence personally directed comment my reply was based upon.

I actually agree with you about Ilia's book, it is the best of the
three available (the Pro PHP Security one is certainly the worst),
although there are areas where even Ilia basically shrugs his
shoulders in the text and says you can never have it 100% and sort
of gives up on you :)

All three books are now well behind the times though imho.

 I also agree that awareness is no bad thing, but people should also
 be aware he is not the be all and end all of PHP application level
 security, and he has made mistakes (as have I and probably everyone
 else here at some point).

Sure, no-one is perfect :) I remember asking him years ago why he
wanted to concentrate on PHP Security explicitly, and his response was
simply that he wished he didn't have to, but no-one else was, and
ultimately in his ideal world PHP would be secure enough 'out of the
box' that he need not have to focus at all.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] HTML in database

2007-07-04 Thread Richard Davey
Hi Bruce,

Thursday, July 5, 2007, 1:26:01 AM, you wrote:

 Thanks.  Sorry, I should have mentioned I'm using MS Sql Server and
 I don't see a mssql equivalent to that function.

MSSQL treats '' as an escaped ', not \' like MySQL does.

So you can't addslashes it. Perform your own ' to '' conversion.

Also check to see if you've got RUNTIME Magic Quotes on, because that
will auto-escape data (\'), which is pointless for MSSQL.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[3]: [PHP] HTML in database

2007-07-04 Thread Richard Davey
 Thanks.  Sorry, I should have mentioned I'm using MS Sql Server and
 I don't see a mssql equivalent to that function.

 MSSQL treats '' as an escaped ', not \' like MySQL does.

 So you can't addslashes it. Perform your own ' to '' conversion.

And to reply to my own reply :) ...

If you can, use PDO with the PDO MSSQL driver instead.

Then let PDO worry about escaping for you!

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Swear filter ideas

2007-06-27 Thread Richard Davey
Hi all,

Just wanting to pick your collective brains on this one:

How do you go about implementing a swear / bad-word filter in PHP?

Reasons for needing one aside, I'm just wondering if you favour a
regexp, a substr_count, or what? Do you like to *** out the bad words,
or just error back to the user? (I guess that is application
specific).

There are always ways to circumvent them, but I'm still curious to
know how you prefer to handle it.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Counting Capital Letters

2007-06-20 Thread Richard Davey
Hi,

I've written a short regexp which will *count* how many capital letters
are in a given string (the woefully simple: '/[A-Z]/')

Although it's an English language web site, I'm curious how you'd
count capital letters that span beyond just the standard A-Z.

For example characters such as the Latin capital letter S with Acute.
I'm not interested in covering all possible character sets, but I
don't want to piss-off any Europeans who may register on the site and
want to use one of their own capital letters.

Anyone approached this before?

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Larry,

Tuesday, June 19, 2007, 2:55:07 AM, you wrote:

 Perhaps you're looking for in_array()?

If only it was that simple! But pray tell how an in_array search is
going to find:

$userparam = test['bob'][];

within:

Array
(
[test] = Array
(
['bob'] = Array
(
[0] = red
[1] = green
[2] = blue
)
)
)

?

The problem is that $userparam in the example above needs to be
expanded out into a form that $_POST can be searched for it. Or vica
versa.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Stut,

Tuesday, June 19, 2007, 10:16:02 AM, you wrote:

 If you can't control $userparam and it has to look like you have it then
 you're parsing of it is a little more involved, but still fairly simple.

 What are you actually trying to do? Where will $userparam actually come
 from? There is almost certainly a better way to do this, but without 
 knowing all the details I'd be peeing in the wind.

Thank you for your code so far. Here is a more detailed explanation of
what I'm trying to do:

The designers here can create forms with whatever form elements they
like on them. They can name the form elements with any valid name. As
you know sometimes it is useful to give the form elements names which
will convert them into arrays in PHP, i.e.:

input type=checkbox name=test[color][] value=red2red2br
input type=checkbox name=test[color][] value=green2green2br
input type=checkbox name=test[color][] value=blue2blue2br

So $_POST['test']['color'] would contain an array of all the checked
values.

So far so good. The problem comes in that I don't know what the form
elements will be named, but I still need to check to see if they exist
within the $_POST array.

So knowing that $input_name = 'test[color][]' I then need to see if
$_POST['test']['color'] exists and get the value if it does.

To make matters worse it's perfectly legal to have a form element
named like:

input type=checkbox name=test['bob']['jazz'][] value=redred
input type=checkbox name=test['bob']['jazz'][] value=greengreen
input type=checkbox name=test['bob']['jazz'][] value=blueblue

Which when bought back into PHP will come out as:

array(1) {
  [test]=
  array(2) {
['bob']=
array(1) {
  ['jazz']=
  array(3) {
[0]=
string(3) red
[1]=
string(5) green
[2]=
string(4) blue
  }
}

Does that make it any clearer?

I have been playing with the RecursiveIteratorIterator this morning in
an attempt to solve it, but the results from that are less than
useless :(

I'm happy to try and explore the RAW post value instead if that would
be easier. I just figured there must be an easier way?

Here is the complete page you can test with:

 START
pre
?php
var_dump($_POST);

$iterator =  new RecursiveIteratorIterator(new 
RecursiveArrayIterator($_POST));

while($iterator-valid())
{
echo $iterator-key() . ' -- ' . $iterator-current();

echo \n;

$iterator-next();
}

$userparam = test['bob'][jazz][];
//  How to determine if $userparam exists in $_POST
?
/pre

form method=post

input type=checkbox name=test['bob'][jazz][] value=redredbr
input type=checkbox name=test['bob'][jazz][] value=greengreenbr
input type=checkbox name=test['bob'][jazz][] value=bluebluebr
input type=checkbox name=test[sam][] value=red2red2br
input type=checkbox name=test[sam][] value=green2green2br
input type=checkbox name=test[sam][] value=blue2blue2br

input type=submit

/form
 END

Remember the whole crux of this problem is that I have no control over
what the form name will be. It will be *valid*, but that is all. They
could nest the resulting array as deep in $_POST as they like.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Stut,

Tuesday, June 19, 2007, 12:09:12 PM, you wrote:

 If you have no control over what the fields in the form will be, what 
 are you doing with the data? Surely if you're writing logic that 
 requires you to know what the fields are called, you need to have 
 control over it.

Here, this should help expand it further:

$icecream = $form-addSelectList('list', icecream[flavor][], 1, true, 'xml', 
'icecream.xml', '//flavour');

The above code will add a select list into the current form (the
contents of which come from the icecream.xml file, using the xpath
query at the end, but this isn't relevant to the problem)

The 2nd parameter is the form name. In this instance the flavors from
the multi-select list will come into $_POST in: icecream[flavor]

When the form is submitted I take all of these form elements, and if
they exist in the filtered $_POST array, I re-populate them on error.

If the input name is just 'icecream' then you can do a simple:

if (isset($_POST[$input_name]))

.. and get the submitted value back.

If the input name is 'icecream[flavor][]' the above will no longer
work.

The problem is finding a way to expand the input name (which is a
string) into a format that $_POST can be searched for. Or do the
reverse, iterate through $_POST to find a match for the input name and
get that value.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Stut,

Tuesday, June 19, 2007, 1:16:54 PM, you wrote:

 The problem is finding a way to expand the input name (which is a
 string) into a format that $_POST can be searched for. Or do the
 reverse, iterate through $_POST to find a match for the input name and
 get that value.

 Try this overly commented snippet on for size...
 http://dev.stut.net/php/davey.php

Very nice, thank you. I was hoping there would be a way to do it
without resorting to eval(), but if even you can't figure out how, I'm
not going to waste any more time trying to either :)

I loved this part:

// The target - offensive American spelling!

:)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Comparing string to array

2007-06-19 Thread Richard Davey
Hi Al,

Tuesday, June 19, 2007, 1:46:47 PM, you wrote:

 preg_grep() or

 foreach($_POST as $value){

 if(empty($value)) continue;
 $good_stuff[] = $value;
 }

A classic case of not reading the post fully methinks.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Stut,

Tuesday, June 19, 2007, 1:49:53 PM, you wrote:

 Very nice, thank you. I was hoping there would be a way to do it
 without resorting to eval(), but if even you can't figure out how, I'm
 not going to waste any more time trying to either :)

 You probably could by breaking it into each part and then using a loop
 to descend to the right place, but I don't think that's going to be any
 better than using eval.

I was wondering about doing something like this:

Recurse through $_POST, grabbing all of the keys, and then building a
string from them, something like:

icecream_batch2_flavours

and then storing the value of 'flavours' in a new array with the above
as the key.

Then I could manipulate the form input name:

name=icecream[batch2][flavours][]
or
name=icecream['batch2']['flavours'][]

To resemble the above key relatively simply.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Jim,

Tuesday, June 19, 2007, 5:06:47 PM, you wrote:

 DON'T USE SINGLE QUOTES IN YOUR NAME=  ATTRIBUTE

Hate to piss on your bonfire but a single quote is a perfectly valid
(if somewhat stupid choice of) character for inclusion in an array key.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Jim,

Tuesday, June 19, 2007, 5:29:55 PM, you wrote:

 Richard Davey wrote:
 Hi Jim,
 
 Tuesday, June 19, 2007, 5:06:47 PM, you wrote:
 
 DON'T USE SINGLE QUOTES IN YOUR NAME=  ATTRIBUTE
 
 Hate to piss on your bonfire but a single quote is a perfectly valid
 (if somewhat stupid choice of) character for inclusion in an array key.
 
 Cheers,
 
 Rich
 in this case, it isn't a valid char.

 Look at his output, you will see that the single quotes are being included in 
 the actual value of
 the submitted array.

Read the rest of the thread, specifically the code given by Stut, the
single quote makes bugger-all difference to the comparison I'm afraid,
the problem at hand is much deeper than that.

 Look at the output a little closer...

No need, it's *my* output, and I've been looking at it very closely
for hours now, and believe me quotes aren't the issue (if only it was
that simple a solution)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Jim,

Tuesday, June 19, 2007, 5:47:29 PM, you wrote:

 Jim Lucas wrote:
 $userparam = test['sam'][];

 then what you are saying it that this HAS to be your search string?

Heck no, it doesn't *have* to be. Feel free to remove the quotes from
it and then attempt my original question again. It's still not as
simple as an isset() or count() call.

(but boy I wish it was!)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Force zero numbers on a integer

2007-06-19 Thread Richard Davey
Hi,

Tuesday, June 19, 2007, 5:17:29 PM, you wrote:

 I have a integer that is submitted by the user and i need it to always
 contain 5 digits.

 If the user submitted 45, i need it to be 00045.

 If the user submitted 4595, i need it to be 04595.

 How can i do this?

Given PHPs type switching abilities, this would work:

http://uk2.php.net/str_pad

but this would be more elegant:

http://uk2.php.net/manual/en/function.sprintf.php

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Jim,

Tuesday, June 19, 2007, 6:21:25 PM, you wrote:

 let me try this again.

 in the submitted $_POST array, you are looking for a key (test) that contains 
 a given $username
 that may or may not have any values set?

 Correct?

Sorry not even close.

Here, let me try again...

$param = 'test[batch1][colour][]';

(the above being a perfectly valid name for say a range of checkboxes
in a form)

Using just the above $param string, do this:

$values = $_POST['test']['batch1']['colour'];

Of course $param is a totally moving feast, and you don't know
what it may contain, only that what it does contain WILL actually be
in $_POST somewhere.

The problem was turning the string 'test[batch1][colour][]' into a
something from which you can pull the resulting values from the $_POST
array.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Comparing string to array

2007-06-19 Thread Richard Davey
Hi Robin,

Tuesday, June 19, 2007, 8:28:50 PM, you wrote:

 On 19/06/07, Richard Davey [EMAIL PROTECTED] wrote:
 $userparam = test['sam'][];

 //  How to check if $userparam exists in the $_POST array
 //  and get all the values from it?

 full_key_exists(test['sam'][], $_POST) // returns true if key is set

 full_find_key(test['sam'][], $_POST) // returns value of key or undef.

 function full_key_exists ($key, $array) {
   preg_match_all('/[^][]+/', $key, $branch);

   if (!sizeof($branch[0])) false;

   foreach ($branch[0] as $index) {
 if (!(is_array($array)  isset($array[$index]))) return false;
 $array = $array[$index];
   }

   return true;
 }

 function full_find_key ($key, $array) {
   preg_match_all('/[^][]+/', $key, $branch);

   if (!sizeof($branch[0])) return;

   foreach ($branch[0] as $index) {
 if (!(is_array($array)  isset($array[$index]))) return;
 $array = $array[$index];
   }

   return $array;
 }

Now that is one elegant solution. Thank you very much indeed.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Comparing string to array

2007-06-18 Thread Richard Davey
Hi all,

Ok it's 2am, my brain has gone to mush and I am having trouble
figuring out an easy way to do this, can anyone shed some light?

Take a peek at the following code:

// START
pre
?php
print_r($_POST);

$userparam = test['sam'][];

//  How to check if $userparam exists in the $_POST array
//  and get all the values from it?

//  Obviously this won't work, but you get the idea:
if (isset($_POST[$userparam]))
{
echo 'yeah';
$values = $_POST[$userparam];
}
else
{
echo 'nah';
}
?
/pre

form method=post

input type=checkbox name=test['bob'][] value=redredbr
input type=checkbox name=test['bob'][] value=greengreenbr
input type=checkbox name=test['bob'][] value=bluebluebr
input type=checkbox name=test['sam'][] value=red2red2br
input type=checkbox name=test['sam'][] value=green2green2br
input type=checkbox name=test['sam'][] value=blue2blue2br

input type=submit

/form
// END

From the code above I'm trying to figure out how to tell if the
$userparam exists in the $_POST array. PHP automatically expands the
form element name into multi-dim arrays within $_POST, so a simple
'isset' as shown in the code above won't play because it's got a
totally useless array key passed to it.

I need a way to turn the string:

test['sam'][]

into something I can look into $_POST for.

Any ideas? The coffee boost is wearing off, but I want to get this
licked tonight :-\

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[7]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-16 Thread Richard Davey
Hi tedd,

Saturday, June 16, 2007, 1:18:58 PM, you wrote:

 How about?

 switch (1)
 {
 case $allow_fraction:
 $filter['flags'] = FILTER_FLAG_ALLOW_FRACTION;
 break;

 case $allow_thousand:
 $filter['flags'] = FILTER_FLAG_ALLOW_THOUSAND;
 break;

 case  $allow_scientific:
 $filter['flags'] = FILTER_FLAG_ALLOW_SCIENTIFIC;
 break;
 }

 Would that not work?

Sorry but no because it doesn't allow for multiple flags to be set.
It's perfectly valid to have one, two or all three flags active on the
filter_var call. Even if the switch statement was re-run again, it
wouldn't bitwise OR the values together, it'd just replace them.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating 'Previous - Next Buttons' Logic - Novice Question

2007-06-15 Thread Richard Davey
Hi,

Friday, June 15, 2007, 9:53:24 PM, you wrote:

 I know very little about PHP ...  however, I am hoping that there is some
 kind of preset  open source php code that I might be able to use.

There is the Pear pagination package which can do this, although not
quite in the way you want it done in your example. Search pear.php.net
for it if you want.

 - An 'include page' that might store an array of the list of pages such as:

 start array...

 pos1 = page1.htm
 pos2 = page17.htm
 pos3 = page5.htm
 etc.

 stop array...

 - then  a variable could be set for the current page such as:


 thispage = 2  - Place on the array equals position 2 (page17.htm)

Can I take it from this example that your pages should not be in
sequence then? I.e. instead of going page1, page2, page3, instead they
should go page1, page17, page5, etc?

If so, why? :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: outputing image part 2

2007-06-15 Thread Richard Davey
Hi Ross,

Friday, June 15, 2007, 10:00:53 PM, you wrote:

  I have this

 $img_url=http://www.xxx.co.uk/images/ENbb24469/room1.JPG;;
 echo img src=\common/display_image.php?img_url='$img_url'\ width=\200\
height=\100\ /;

 and on the display image page I have:

 $img_url= $_GET['img_url'];
 $image = imagecreatefromjpeg($img_url);
 if ($image === false) { exit; }

 /// rest of the resize code goes here.

 This still does not work but if I plug the url in manually at the top of
 display_image.php it works, this suggests it is not being sent properly.

You are sending a complete URL to your image, not a path. This means
that if your installation of PHP does NOT have the ability to open
files from URLs (allow_url_fopen) then it won't be able to open the
image from the location you gave it.

If you want to load in images from other web sites then make sure
allow_url_fopen is enabled in PHP. If you don't want to do this, then
don't pass in a URL, pass in the *path* to the image instead.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: outputing image part 2

2007-06-15 Thread Richard Davey
Hi Ross,

Friday, June 15, 2007, 10:40:37 PM, you wrote:

 Any ideas how to save the imagecopyresampled() to the folder?

Call imagepng (or imagejpeg or whatever) and pass it a filename to
save the image instead of output it. Check the help files for examples.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] London PHP salaries

2007-06-14 Thread Richard Davey
Hi Javier,

Thursday, June 14, 2007, 9:23:25 AM, you wrote:

 I've received a job offer from a London zone 1 based
 company as Senior PHP developer.
 I'm really interested but I live in Spain an have no
 idea about UK salaries so I wonder if somebody could
 give me a clue.

 How much money is a really good salary (to keep a
 family happy) ? How much could I ask as a senior
 PHP/J2EE developer ?

How much are they offering? Then we can say if it's good or not :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: London PHP salaries

2007-06-14 Thread Richard Davey
Hi Daniel,

Thursday, June 14, 2007, 7:40:52 PM, you wrote:

 I gross ~$2,400 per month.

[snip]

 So, with bills alone, it costs me a minimum of $2,700.  That
 leaves me with about $900 extra which then goes to repaying loans

I'm curious.. how does $2,400 - $2,700 = $900 left over per month?

I'll have some of that bank voodoo magic please :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] London PHP salaries

2007-06-14 Thread Richard Davey
Hi Daevid,

Thursday, June 14, 2007, 9:26:44 PM, you wrote:

 We had an employee (a friend of mine) start a UK office, and due to
 corporate legal reasons, and taxes, etc, he got paid in US DOLLARS.
 Aside from even more legal/tax issues he personally had to face, his
 salary was almost halved, as 1 USD = 1.9696 GBP !! 

No, that would give him a SUPERB salary conversion ;)

It's actually 1 USD = 0.50 GBP.

 The UK is VERY expensive. If I were you, I would do some online
 research at the cost of fuel/petrol/gas/whatever you call it, rent,

Well we call it whatever goes in the car. If you use petrol, we call
it petrol. If you use diesel, we call it diesel. Not too far beyond
your A, B, C's really.

 purchasing homes, taxes (don't they have VAT and GST or something
 like that?), an average lunch meal, dinner meal, utilities, car
 price, etc...

VAT is 17.5%, doesn't apply to all goods (certain items are exempt)
and is in practise no different to your state taxes. Think yourself
lucky it's only 17.5%, some European countries go way higher. It does
however fund our medical services, etc, etc.

The average cost of living over here, while higher than lots of other
countries, isn't out of line with the average salary, which is all
that matters. That doesn't mean consumer spending is in line with
their salaries, but hey - welcome to the mass global issue of being
in debt.

Back to the original question though, I'd not take a job offering less
than £35k/pa, *especially* one in central London. You should add on a
significant extra for that location alone.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] London PHP salaries

2007-06-14 Thread Richard Davey
Hi Tijnema,

Friday, June 15, 2007, 12:10:56 AM, you wrote:

 It's actually 1 USD = 0.50 GBP.

 Ohh nice :)

Yeah, it makes buying software from the US a dream at the moment. Same
goes for domain names, server hosting, etc. Of course it means SELLING
software into the US is a complete bitch, but there we go.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[6]: [PHP] London PHP salaries

2007-06-14 Thread Richard Davey
Hi Crayon,

Friday, June 15, 2007, 2:06:47 AM, you wrote:

 On Friday 15 June 2007 07:39, Richard Davey wrote:

 Yeah, it makes buying software from the US a dream at the moment. 

 Huh? When software comes across the pond they usually markup at 1USD=1GBP

Sure, bastards like Adobe rip us off in that way. But I bought a
couple of excellent shareware apps this week for almost peanuts thanks
to the exchange rate atm.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi all,

Can anyone think of a more elegant way of achieving the following?

?php
$flags = array();

if ($allow_fraction)
{
$flags[] = FILTER_FLAG_ALLOW_FRACTION;
}

if ($allow_thousand)
{
$flags[] = FILTER_FLAG_ALLOW_THOUSAND;
}

if ($allow_scientific)
{
$flags[] = FILTER_FLAG_ALLOW_SCIENTIFIC;
}

if (count($flags)  0)
{
$c = '$c = ' . implode('|', $flags) . ';';
eval($c);
$filter['flags'] = $c;
}
?

The code checks for 3 booleans ($allow_fraction, etc) and if true it
adds the const to the $flags array. At the end each value in the array
is joined together into a string (the implode part), which would give
something like: 4096|8192 - but I then need to return the actual value
from this operation, so I'm eval'ing it.

I don't like using eval, so can anyone think of a better way to do
this? All I need as an end result if the product of the bitwise
operation (i.e. an integer) stored in $filter['flags']

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Zoltán,

Wednesday, June 13, 2007, 2:21:18 PM, you wrote:

 2007. 06. 13, szerda keltezéssel 14.13-kor Richard Davey ezt írta:
 Hi all,
 
 Can anyone think of a more elegant way of achieving the following?
 
 ?php
 $flags = array();
 
 if ($allow_fraction)
 {
 $flags[] = FILTER_FLAG_ALLOW_FRACTION;
 }
 
 if ($allow_thousand)
 {
 $flags[] = FILTER_FLAG_ALLOW_THOUSAND;
 }
 
 if ($allow_scientific)
 {
 $flags[] = FILTER_FLAG_ALLOW_SCIENTIFIC;
 }
 
 if (count($flags)  0)
 {

 $tmp = FALSE;
 foreach ($flags as $flag) {
 $tmp = $tmp | $flag;
 }
 $filter['flags'] = $tmp;

Nice one, thank you. Same amount of code but avoids the eval() which
is all I wanted.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Tijnema,

Wednesday, June 13, 2007, 2:42:28 PM, you wrote:

 Nice one, but you could also do it like this:

 ?php
 $filter['flags'] = FALSE;

 if ($allow_fraction)
 {
$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_FRACTION;
 }

 if ($allow_thousand)
 {
$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_THOUSAND;
 }

 if ($allow_scientific)
 {
$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_SCIENTIFIC;
 }

?

 Little bit simpler huh?

Yup.. even nicer, I'm using that method now :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Zoltán,

Wednesday, June 13, 2007, 3:09:16 PM, you wrote:

 2007. 06. 13, szerda keltezéssel 15.42-kor Tijnema ezt írta:
 On 6/13/07, Richard Davey [EMAIL PROTECTED] wrote:
  Hi Zoltán,
 
  Wednesday, June 13, 2007, 2:21:18 PM, you wrote:
 
   2007. 06. 13, szerda keltezéssel 14.13-kor Richard Davey ezt írta:
   Hi all,
  
   Can anyone think of a more elegant way of achieving the following?
  
   ?php
   $flags = array();
  
   if ($allow_fraction)
   {
   $flags[] = FILTER_FLAG_ALLOW_FRACTION;
   }
  
   if ($allow_thousand)
   {
   $flags[] = FILTER_FLAG_ALLOW_THOUSAND;
   }
  
   if ($allow_scientific)
   {
   $flags[] = FILTER_FLAG_ALLOW_SCIENTIFIC;
   }
  
   if (count($flags)  0)
   {
 
   $tmp = FALSE;
   foreach ($flags as $flag) {
   $tmp = $tmp | $flag;
   }
   $filter['flags'] = $tmp;
 
  Nice one, thank you. Same amount of code but avoids the eval() which
  is all I wanted.
 
  Cheers,
 
  Rich
 Nice one, but you could also do it like this:
 
 ?php
 $filter['flags'] = FALSE;
 
 if ($allow_fraction)
 {
$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_FRACTION;
 }
 
 if ($allow_thousand)
 {
$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_THOUSAND;
 }
 
 if ($allow_scientific)
 {
$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_SCIENTIFIC;
 }
 
 ?
 
 Little bit simpler huh?

 in this case yes.
 but if he wants to use the $flags array to anything else besides
 creating $filter['flags'] from it, then my solution would be better

Your solution was far better than my original, but I'm only ever
setting 1 value ($filter['flags']) at the end of each function, so
using the above technique will work for my requirements. Thank you
both for your suggestions.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Robert,

Wednesday, June 13, 2007, 3:15:39 PM, you wrote:

 It's terribly verbose and inefficient...

 ?php

 $filter['flags'] = 0;

 if( $allow_fraction )
 {
 $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION;
 }

 if( $allow_thousand )
 {
 $filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND;
 }

 if( $allow_scientific )
 {
 $filter['flags'] |= FILTER_FLAG_ALLOW_SCIENTIFIC;
 }

?

I don't think it's *terribly* verbose, as it has good sentence structure
to it, but your version is certainly more efficient, hence I've
swapped to that. Any other takers? ;)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[8]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Robert,

Wednesday, June 13, 2007, 3:37:38 PM, you wrote:

 Personally I hate constants (can't use non-scalar values so why get used
 ot them... also they're just another point for name collision) so if it
 were my own code I'd do something more like the following:

Sure, but the filter extension uses them, which is where they come
from. They aren't of my own creation, and I cannot assume that the
values assigned to them won't change in the future, so can't hardcode
my way around them.

I don't have anything against side-wide constants myself (no worse
than an array shoved into $GLOBALS) but PHP seems to be moving more
and more towards the use of constants within extensions as function
parameters, PDO being another popular culprit that springs to mind.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Richard,

Wednesday, June 13, 2007, 6:44:55 PM, you wrote:

 if ($allow_fraction)

 //Should we warn you that $allow_fraction is not actually defined?...

Should I warn you that to save everyone's sanity I only posted what was
needed from the code? ;) $allow_fraction came from a function
parameter. I'd type hint it to boolean if PHP allowed, but alas ...

 $flags |= FILTER_FLAG_ALLOW_FRACTION;

Yup, Robert showed this already in this thread. Nice short-cut, wasn't
aware it worked with that operator. That's definitely my learnt
something new for today. I wonder what else it works for? (besides
the obvious += -=)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] checking the aspect ratio of an images

2007-06-08 Thread Richard Davey
Hi Crayon,

Friday, June 8, 2007, 6:08:30 PM, you wrote:

 On Friday 08 June 2007 22:17, tedd wrote:

   Wednesday, June 6, 2007, 11:41:19 AM, you wrote:
I want to force users to insert landscape rather portrait images.
I don't want to be too pedantic about it but they do need to have
an
 
 approximate 4x3
 
aspect ratio.
   
You can't really be 'approximate' when coding.
 
 You certainly can be approximate when coding. It's called heuristics
 and it's an absolute necessity in many areas of software development.

 Absolutely, and what about fuzzy logic -- that method is based upon
 approximate calculations.

 But somewhere in the guts of the approximate calculations there are 
 _precisely_ defined limits. Anyhow, please illustrate how you would use
 approximate calculations in determining or defining the aspect ratio of
 an image.

This I'd love to see. Don't hold your breath for a decent code based
response though.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] checking the aspect ratio of an images

2007-06-08 Thread Richard Davey
Hi Robert,

Friday, June 8, 2007, 7:21:39 PM, you wrote:

 Precisely defined limits are not the same as precisely defined values. I
 might precisely define the amount of entropy on a random value as being
 some formula based on the current temperature of my CPU. The formula is
 quite precise, but the value is only precisely known after I take the
 temperature... and even then it probably doesn't serve me to know it
 explicitly unless I'm verifying results. If I then take that random
 value and use it to make other decisions then the end result isn't
 exactly precise.

The end result isn't precise, but it will always exist between some
very real and very price possible values, those controlled by the min
and max temp of your CPU.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] checking the aspect ratio of an images

2007-06-08 Thread Richard Davey
Hi Robert,

Friday, June 8, 2007, 7:47:17 PM, you wrote:

 On Fri, 2007-06-08 at 19:35 +0100, Richard Davey wrote:
 Hi Robert,
 
 Friday, June 8, 2007, 7:21:39 PM, you wrote:
 
  Precisely defined limits are not the same as precisely defined values. I
  might precisely define the amount of entropy on a random value as being
  some formula based on the current temperature of my CPU. The formula is
  quite precise, but the value is only precisely known after I take the
  temperature... and even then it probably doesn't serve me to know it
  explicitly unless I'm verifying results. If I then take that random
  value and use it to make other decisions then the end result isn't
  exactly precise.
 
 The end result isn't precise, but it will always exist between some
 very real and very price possible values, those controlled by the min
 and max temp of your CPU.

 ... and the resolution at which the temperature can be measured. But we
 digress, this is merely a specific example, there are many more metrics
 that can be sampled to give an extremely large range of values.

And I'd wager those values too have precise minimums and maximums. You
can pluck an approximate value from between them however you like,
but I'm still waiting for evidence that that value will never lie
between some very tangible limits, and still be of any kind of
real-world value in your code. Due to the very nature and way in which
CPUs work, and the effect this passes up through to any language that
cares sit on it, at the end of the day if the architecture itself
cannot deal with 'approximate' values, anything that happens on the
higher level will always be reduced to a value that exists between two
very solidly set limits. If you don't impose those in your code, what
happens beneath will impose it for you regardless. I'd be happy to
read some papers or code that you feel demonstrates what you're trying
to get across if you have any links.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Corrupts URLs

2007-06-08 Thread Richard Davey
Hi Nathan,

Friday, June 8, 2007, 9:47:22 PM, you wrote:

 I have a php script that gets a url from a GET query parameter.  I have
 been running this script on PHP 5.2.2 on Ubuntu Linux, and everything 
 works as expected.  I have just installed PHP 5.2.3 on OS X via 
 MacPorts, and the same query parameter url has any single quote 
 characters escaped with a backslash when I retrieve it from $_REQUEST.

[snip]

 As you can see, in OS X the url acquires a the backslashes, which I 
 would like to avoid.

 I am not much of a PHP programmer at this point--it is a brand new 
 language for me, so I don't really now how to investigate this.  Is 
 there a PHP configuration option I can look at?

Sure.. look at the magic_quotes_gpc setting:

http://uk.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] checking the aspect ratio of an images

2007-06-06 Thread Richard Davey
Hi,

Wednesday, June 6, 2007, 11:41:19 AM, you wrote:

 I want to force users to insert landscape rather portrait images. I don't
 want to be too pedantic about it but they do need to have an approximate 4x3
 aspect ratio.

You can't really be 'approximate' when coding. You need to set some
hard values to check against. So work out what your extremes will be
first.

A 4x3 image has an aspect ratio of 1.33

So decide what your max and min ratios will be and then check the
aspect ratio of the image they upload.

If they upload a 320x200 it'll have a ratio of 1.60
If they upload a 200x320 it'll have a ratio of 0.63
If they uploaded a 200x200 the ratio is exactly 1

So if you want the image to be landscape, it'll always have a ratio of
above 1.0. If you don't want it stupidly landscape (i.e. 1600x300)
then just set your maximum ratio to something like 1.6.

Once you've set your boundaries your 'if' statement becomes a whole
lot easier to write.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: customer ids

2007-06-06 Thread Richard Davey
Hi Burn,

Wednesday, June 6, 2007, 3:55:21 PM, you wrote:

 Here's how I do it, for 1 single table though.. you'll have to write
 yourself the mod to check on more tables. If you plan to have  10 
 millions records make sure the maxrand is higher.

 When the do loop exits you have a unique id.

 function generateID() {
 $minrand = 1;
 $maxrand = ;
 $uniqueid[0] = mt_rand($minrand, $maxrand);
 $uniqueid[1] = $uniqueid[0];
 return $uniqueid[1];
 }
 
 do {
 //New ID generation
 $newid = generateID();
 //Database check
 $sqlcheck = SELECT youruniqueidhere FROM yourtablehere WHERE 
 youruniqueidhere = '.$newid.';
 $conn = mysql_connect($db_host, $db_username, $db_password);
 mysql_select_db($db_name, $conn);
 
 $rs = mysql_query($sqlcheck, $conn);
 $rscount = mysql_num_rows($rs);
 } while ($rscount != 0);

Not that it is likely to occur on a low-traffic site, but the above
approach is a race condition waiting to happen I'm afraid. It will
however almost certainly satisfy the needs of the OP as long as his
site stays off digg / slashdot :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Re: customer ids

2007-06-06 Thread Richard Davey
Hi Burn,

Wednesday, June 6, 2007, 4:39:05 PM, you wrote:

 Worst thing that can happen is having mysql throw an error while trying
 to insert an ID that's already present in the database. It gets more 
 complicated and unpredictable if the field isn't required to be unique
 at database design level.

 Wanting to make it perfectly safe the check should include the INSERT 
 statement and continue looping till it's successful as well.

Or just wrap the whole thing in a stored procedure / transaction (it's
what they were invented for after-all :), tasks like this should be
pushed to SQL as much as possible imho.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Parse domain from URL

2007-06-06 Thread Richard Davey
Hi Brad,

Wednesday, June 6, 2007, 5:04:41 PM, you wrote:

 Yes, that's basically what my code already does.

 The problem is that what if the url is http://yahoo.co.uk/; (note the lack
 of a subdomain)

 Your script thinks that the domain is co.uk.  Just like my existing code
 does.

 So we can't count on taking the last 2 segments.  And we can't count on
 ignoring the first segment.  (The subdomain could be anything, not just www)

The complete list of top-level domains is neither very long, nor
changes very often. Perhaps a new country/suffix now and again is added or
renamed, but it doesn't happen that much.

In short, I think it'd be much better for you to obtain a full list
and then just remove that element from your hostname. Then you'll know
for a fact that whatever is left is the pure domain (+ sub-domain).

Of course it won't help if someone gives you the IP of a site (or any
other similar variation) instead of a domain name :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Double checking - I should turn off magic quotes

2007-06-04 Thread Richard Davey
Hi Dave,

Monday, June 4, 2007, 3:25:25 PM, you wrote:

 No, you should check the ini setting in your code and react accordingly.
   
 Sorry, I don't quite follow you here. If I turn magic quotes off on both
 my testing environment and my server, as is preferable according to 
 the manual, then my ini file will conform to that.

 But I don't see how that relates to the portability of the code. As much
 as possible, I'd like to have others be able to run my scripts with 
 minimum hassle.

 If I make my development environment and my own web hosting server 
 conform to the preferable set up, but most servers default to having
 magic quotes on, then won't my code break on most people's servers?

In your code you check to see if magic quotes is enabled or not:

http://uk2.php.net/manual/en/function.get-magic-quotes-runtime.php
http://uk2.php.net/manual/en/function.get-magic-quotes-gpc.php

You can check if magic quotes is on, and if so you can strip the
incoming data accordingly. You cannot disable GPC quoting unless you
have access to set php values (ini file, htaccess, etc), but you *can*
disable runtime quoting (which is what happens when data is fetched
from a database). On the basis that you can't disable GPC quoting you
only need to know what state the data you receive will be in, and
treat it accordingly.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi all,

Just a quick straw-poll really:

What is your take on using 'return' when you end a function, if you
don't actually need to return a value?

If you have to return say a true/false as the result of an operation,
then it's an obvious choice. But what if all the function does is
perform an action and then quit? Do you like to use 'return' at the
end of it anyway, or do you just let it run into the closing } ?

Or do you perhaps do a 'return true' at the end, regardless, even if
the rest of your code never checks that value (on the basis that it
may do in the future)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Dave,

Wednesday, May 30, 2007, 12:20:48 PM, you wrote:

 If there is no need to return a value then I don't do so. However, the
 function is going to process something, and surely you should check that the
 processing has succeeded or failed?

I have exception and error handling dealt with fully in my functions,
by which stage the 'return' at the end becomes redundant because the
return value doesn't need checking as the error handler has already
taken over. However take the following:

$result = $this-calculateSomething($value);

If 'calculateSomething' has all the error handling it requires built
into it, then isn't checking the value of 'result' superfluous to
requirements? Yet even so, I still like to return something at the end
regardless :)

I guess another way to phrase the same question would be where do you
shift all of your error handling - inside the function itself, or in
the code that calls it (i.e. checking the $result in the example
above). Personally I handle it all in the function otherwise I'm
duplicating masses of result checking.

It isn't a case of wrong/right, just trying to gauge preferences here.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Chris,

Wednesday, May 30, 2007, 1:17:39 PM, you wrote:

 If there is no need to return a value then I don't do 
 so. However, the function is going to process something, 
 and surely you should check that the processing has 
 succeeded or failed?

 This is precisely the point I was going to make.  Unless an argument is
 passed in by reference for manipulation within the function, I can't
 think of a reason why you wouldn't want to return a value; true or false
 at the very least.  You call a function to perform, well, a function.  I
 would think that you would want to know whether or not the process
 within the function was successful, yes?

Even the most simple function can have more than one failure point
within it. If you aren't handling the errors yourself within the
function, you're returning false all over the place and then having to
do the same checking from whatever called it - duplicated however many
times you call that function from your code.

It's a hideous example, but it's straight out of the PHP manual, so
run with it and indulge me:

$mysqli = new mysqli(localhost, my_user, my_password, world);

/* check connection */
if (mysqli_connect_errno()) {
printf(Connect failed: %s\n, mysqli_connect_error());
exit();
}

If that was wrapped in a function, sticking 'return false' within the
connect_error check is useful why exactly? Equally the fact the
function didn't 'exit' implies it 'returned true' anyway, so why check
it again in whatever called the function in the first place? it has
performed its task, it didn't raise an error.

(I know most of us would never use 'exit' in production code like the
above, so replace it with whatever error handling mechanism you have,
the question above remains the same.)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Paul,

Wednesday, May 30, 2007, 4:07:00 PM, you wrote:

 I demur at your final point:  If we don't use exit() and the function
 performs non-aborting error handling, it's going to return to the 
 calling function which in most cases will need to know whether its 
 child function succeeded or failed.

  function parent()
  {
  lookUpData();
  displayData();
  }
  function lookUpData()
  {
  set up query;
  execute query;
  handle errors;
  }

 where handle errors might range from returning a failure flag to 
 displaying an error message.

There's a world of difference between those two events though. If all
'handle errors' does is to return an error flag, then the parent
obviously *needs* to check it. Equally all other functions that ever
call lookUpData() need to duplicate those checks too.

 In order that displayData() doesn't fall on its face, I would write
 the parent function in one of these ways:

  if (lookUpData()) displayData();

That's where our approach differs. If lookUpData falls flat on its
face, my error handler will take over completely, finally resulting in
an 'abortive' event, and never pass back to the parent. If an error is
of a critical enough nature the system needs to stop. If it's not
critical then the error handling within displayData() would detect it
has nothing to display and error in its own accord.

 In my programming style, I can't imagine wanting to write this code
 in such a way that lookUpData() didn't return some form of success or 
 error indicator.

That's a *very* specific example though. My question was do people
place a 'return' statement at the end of **ALL** of their functions,
regardless of what that function actually did. In the code you gave
there is a fair argument both ways, but that isn't always the case.

Here's a piss-poor example off the top of my head:

function parent()
{
 display()
}

function display()
{
 echo something random
}

In this instance (albeit gloriously simple / useless), would your
display() return true even though it could have never actually failed?
and if it did, do you then care about checking that value in the
parent?

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Jared,

Wednesday, May 30, 2007, 4:10:45 PM, you wrote:

[snip]
 I think putting return; at the end of every function is probably a healthy
 practice, but is it best practice? If it's poorly written and/or poorly
 factored code, it doesn't make any difference if they have returns on
 everything, it's still junky code.

If you do put a return; at the end of all of your functions, I'm
curious as to why? If a function doesn't actually return a value
(which is highly possible) then it isn't /required/, but that doesn't
stop me from doing it. I *do* put 'return;' at the end of all
functions (my question to the list was - does anyone else?)

That is all my original thread was ever really asking - I was just
curious what other people thought about returning from functions that
don't actually require a return value. So far the responses have been
pretty varied, from the (somewhat blinkered) 'how can a function never
return something?', to 'yes I always return' to 'no I just let it run
out'.

Based on the variety of replies it appears there is no 'standard' for
this. Just as with code structure and studly-caps it's obviously a bit
of a religious debate.

I think perhaps it is a psychological thing actually, as if I don't
consider the function 'finished' until it hits a return;. Almost like
you're issuing an instruction to tell PHP yes, as the programmer I am
now happy for you to return to where-ever you were called from -
perhaps just a way of exerting our control :)

 Should those checks be contained in the codeblock or class BEFORE returning?
 I think so.

I would agree (because it's how I do it ;), but this isn't an approach
everyone takes.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] installing error

2007-05-26 Thread Richard Davey
Hi Rafael,

Saturday, May 26, 2007, 12:38:15 AM, you wrote:

 Hello does anyone know the correct way to install PHP and APACHE (last
 versions both of them) on WinXP???, Im doing it with the installers and I
 cannot even run phpinfo(); script, I see apache's error log and it says that
 i cant find SAM directory

http://wamp.corephp.co.uk

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Include???

2007-05-25 Thread Richard Davey
Hi Tedd,

Friday, May 25, 2007, 2:42:34 PM, you wrote:

 At 3:28 PM +0100 5/23/07, Richard Davey wrote:


if ($_POST['status_code'] == 'C')
   ^^

Read-up on the if/else structure and comparison operators. You'd never
use a single equals sign in this example.

 Rich:

 Read up on different font sizes that people use and you'll never use 
 ^^ to show something. :-)

Font *size* is irrelevant as long as it's monospaced ;)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Include file questions

2007-05-25 Thread Richard Davey
Hi Tijnema,

Friday, May 25, 2007, 5:58:46 PM, you wrote:

 On 5/25/07, Robert Cummings [EMAIL PROTECTED] wrote:
 Very. Each directory contains very specific types of code/content.
 Tracking down where any given function, class, custom tag, behaviour,
 etc is defined is extremely simple.

 Cheers,
 Rob.

 I don't agree with you, i have includes in includes dir inside my
 project, images in images, etc. classes in includes dir start with
 class. configuration files in includes start with config. etc.

Oh to work on such little sized sites again :)

Not that I'm belittling your projects Tijnema, because I'm not - but
I've not worked on a site with a structure that could be that simple
for a long time now, I kinda miss it actually!! Hell even the 'images
folder' had to be split across multiple servers in the code I finished
today.

A lot of Robert's structure makes complete sense. I never keep
libraries inside the webroot that simply don't need to be there.
Infact if a script doesn't output anything 'web related' (image, rss,
html) or process data from the site, it doesn't need to live in the
webroot at all. I use a similar principal for the 'admin' area of the
site too, which I'm sure you'd hate ;) but I always code my admin
areas so that they can run on an entirely different domain name and/or
server if needs be. Only as a last resort do they ever live in /admin,
and never will they share libs that the 'public' site uses, they are
entirely stand-alone entities.

You're right in that it is down to personal preference though :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] ftp root dir?

2007-05-22 Thread Richard Davey
Hi Al,

Tuesday, May 22, 2007, 4:19:22 PM, you wrote:

 I know that; but, I writing a script, that can be used on different
 servers, which creates a directory and I want to 
 make certain it is created on the DOC ROOT.  I don't want the user
 to have to test the ftp connection with a ftp utility 
 program first.


I'd have to say 'impossible'. This value isn't stored in any one
variable or even in a system value you can rely on.

For example you could probably extract the FTP home directory of a
given user on a Unix system with a bit less pain than on a Windows
server, but within IIS which managers FTP on Windows, you'd have to
query the IIS service itself (via its COM object) to find out the home
dir of a user, which will (and can) vary per user, assuming they even
have one set.

That doesn't even begin to cover all the various other FTP Servers out
there, such as ServU, GlobalScape, TitanFTP, FileZilla Server,
SurgeFTP, etc, etc. Each one holds its users root directories in
different ways, and you'd need to know them *all*. Some hold them in
ini files, some in xml, some in the registry, some in custom binary
formats. You get the idea.

Like I said, I think you're heading into 'impossible' territory here.
Find another way to achieve the same end result.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] convert numerical day of week

2007-05-22 Thread Richard Davey
Hi Dave,

Tuesday, May 22, 2007, 5:46:38 PM, you wrote:

 How can I convert the numerical day of week to the string version?
 Example, if the day of the week is 1 I would like to print out 'Sunday'.

$days = array(1 = 'Sunday', 2 = 'Monday', 3 = 'Tuesday', etc ...);

then just

$today = $days[1]; // Sunday
$today = $days[3]; // Tuesday

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] When does PHP free-up memory allocated to it?

2007-05-21 Thread Richard Davey
Hi,

Quick question - does anyone know when PHP actually frees allocated
memory during the process of a script? I'm using 5.2.2. For example I
see the following results when profiling:

Memory: 256 KB
Load a 1024x768 JPEG (via GD)
Memory: 4 MB
Create thumbnail (via GD)
Memory: 5.2 MB
Destroy original image resource (imagedestroy)
Memory: 5.2 MB

I would have expected (or rather, hoped) that the memory use would
have dropped down quite dramatically after destroying the image
resource that was using up nearly 4MB of memory, but it didn't seem to
change.

Is this a limitation of the memory_get_usage(true) function, or does
imagedestroy not actually do what it implies?

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] When does PHP free-up memory allocated to it?

2007-05-21 Thread Richard Davey
Hi Richard,

Tuesday, May 22, 2007, 1:24:35 AM, you wrote:

 I would have expected (or rather, hoped) that the memory use would
 have dropped down quite dramatically after destroying the image
 resource that was using up nearly 4MB of memory, but it didn't seem to
 change.

 How are you measuring this?

memory_get_usage(true)

 What version of PHP?

5.2.2 (I did say :)

 The Memory Manager changed over the course of time.

Sure, but I'm only interested in how it works now :)

 I'm also not at all sure that you *can* measure it as precisely as you
 are trying to do.

I don't think you can measure it *accurately* right down to the byte,
but with big sweeping operations such as image resource deletion you
should see significant changes in value, and in some circumstances you
do (see blog link at the bottom)

 That said:
 PHP doesn't really allocate that 5.2M of RAM.
 GD does.

Horses for courses, surely? PHP asks GD to do it, the end result is
the same, the memory is being used.

 PHP may not be able to tell you accurately about what GD is doing
 internally -- but it's probably not *really* losing that 5.2M or you'd
 hear an awful lot more screaming about it from all quarters. :-)

True :)

Using the 5MB in the first place doesn't bother me, that's just a
simple allowance for each pixel of the image + RGB/Alpha values, which
is how GD works with it. What I found fascinating on further research
was how the memory can still be used depending simply on how you store
the image resource.

After more research I wrote about it here:
http://www.corephp.co.uk/archives/42-Interesting-memory-use-with-GD-images.html

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Uploading Files Should I use MySQL or Server for storage?

2007-05-20 Thread Richard Davey
Hi benc11,

Monday, May 21, 2007, 2:16:19 AM, you wrote:

 I am in the process of adding a part to my website which would include
 pictures, pdf files, txt files, and excel files.  The files sizes
 could be anywhere on average of 100k to 2mb.  Do you think I should be
 uploading the files to a MySQL database or to my server?

 I have head that there are pros and cons to both, but have never
 really received a definitive answer that helps much.  I appreciate all
 your opinions on the pros and cons of both.

This isn't a 'one size fits all' question. The pros and cons are
specific only to your site. How many uploads are you going to be
dealing with, at what frequency, at what growth rate? Are they going
to be massively downloaded too?

There generally are far less 'pros' for storing binary files in MySQL
than you'd think. The only real benefit imho is that they are then
filesystem / platform agnostic.

There are plenty of 'cons' however. Just think of the server overhead
involved in your PHP script talking to MySQL, MySQL sending back the
entire file to PHP (using memory / cpu bandwidth), then you've got to
blast that file out to the end user. Repeat this X however much
traffic you get and you're performing pointless exercises over and
over when the web server could just serve the file directly.

Only you can answer your question really.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] stay logged in for session

2007-05-18 Thread Richard Davey
Hi Edward,

Friday, May 18, 2007, 12:43:43 PM, you wrote:

 Just because some user agents handle non-standard data doesn't make
 it correct.

You mean user agents follow RFCs to the letter? :)
Since when? :)

I do agree with your comment, but it's a LOT more than some user
agents. Every browser in popular use today would be closer to the
mark. Hell, even the old-guard allowed for Location headers without an
absolute URI.

You *should* specify the full URI, and let's face it - it's just lazy
not to - but unlike the myriad of CSS snafu's out there it's not like
you are walking into a pit of doom and hellfire if you don't, because
I'd wager 99.9% of your visitors would never even be affected, and the
.1% that are probably just dusted off a beta build of NCSA Mosaic to
prove their point ;)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi all,

I'm very happy to announce that I've just released my comprehensive
guide to installing, configuring and running Apache 2, PHP 4.4.7 and
PHP 5.2.2 on Windows XP. The guide is broken down into small
manageable sections and contains over 50 screen shots of the entire
process, so you won't go wrong while following it.

It covers everything from installing Apache, to setting up a Virtual
host to switching between PHP 4 and 5. A troubleshooting section and
further advice rounds-off the guide.

You can read the guide here: http://wamp.corephp.co.uk

Please send comments / suggestions / typos to me.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Robert,

Thursday, May 17, 2007, 4:43:14 PM, you wrote:

 Suggestion: get rid of Windows XP and use a real OS

There's always one ;)

   You have previously and the past redundancy since
   previous implies the past and past implies previous.

Fixed :)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Greg,

Thursday, May 17, 2007, 5:01:18 PM, you wrote:

 There's always one ;)

 No, there's more than one.

Sure, but you're in the minority*, so what do I care? :)

* I just took the Zend PHP IDE research poll, and at the end it gives
you the chance to view the stats of everyone else who took the poll.
Interestingly, 70% of them use Windows XP for development.

I actually use a combination of Vista and OS X, which puts me in the
11% and 19% categories respectively.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Jon,

Thursday, May 17, 2007, 5:46:12 PM, you wrote:

 I find it funny that the addition of the numbers above would logically
 put me in the 0% category.

You could select multiple operating systems from the list. 50% of them
used Linux too. It didn't show how the results were mixed though, i.e.
of the 70%+ that used XP, did 10% or 90% of them also use Linux.

I thought it interesting none-the-less.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[6]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Greg,

Thursday, May 17, 2007, 5:49:45 PM, you wrote:

 Sure, but you're in the minority*, so what do I care? :)

 I'm not asking you to care.  Windoze still sucks, no matter how many
 idiots use it.  The virus protection racket alone is enough to make me
 throw up.

Viruses? God, that old bullshit ladened chestnut*. At least come up
with some kind of valid OS argument, please. If you'd gone for
'competent use of the CPU', or 'effective memory management', you'd be
worth taking seriously.

Unless you're not asking me to take you seriously of course.

Cheers,

Rich
* I've not had a virus -infect- a Windows box for over a decade.
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Lester,

Thursday, May 17, 2007, 6:24:44 PM, you wrote:

 How about installation time. Just clocked up 6.5 Hours re-installing XP on a
 machine. To get the last linux machine to the same level - 20 mins.
 Of cause running Eclipse - it does not matter what the OS is :(

Yeah I'd take installation time as a valid reason why XP sucks
sometimes :) I was very pleased to see that Vista installed in next to no
time at all, but let's not go there... one day someone will invent an
OS as powerful as my old Amiga used to have!

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[8]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Robert,

Thursday, May 17, 2007, 7:01:00 PM, you wrote:

 I had 500 things I wanted to change, then I switched from Windows to
 Linux in 2000 and found that they had been addressed. Sure enough
 though, I'm working on a new list. There's only a few things on it
 though ;)

I envy those who's work is specific / targeted enough for them to be
able to only use Linux on their desktop, I really do (and I say that
without a hint of sarcasm, I promise). For the rest of us, the choice
sadly isn't as black and white.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[8]: [PHP] A Guide to running Apache 2, PHP 4 PHP 5 on Windows XP

2007-05-17 Thread Richard Davey
Hi Greg,

Thursday, May 17, 2007, 7:23:47 PM, you wrote:

 Viruses? God, that old bullshit ladened chestnut*. At least come up
 with some kind of valid OS argument, please.

 1. The virus and malware protection racket - M$ spent billions of
 2. Perpetual Upgrading - you can use Ubuntu Linux 6.06 Server Edition
 3. Bloat - 1.5+ hours to install Vista then finally you get to start
 4. Hostile treatment of customers - M$ is currently choosing to not
 5. Predatory Practices - How many companies have been eaten alive by
 6. .NET - proof M$ really wants to be a bank instead of a software
 7. IE7 - My transparent pngs are almost working, almost.  Guess they

Yay, some decent arguments! I don't deny any of them, I only take
exception to being called an 'idiot' by yourself for the OS I have to
use. You have no idea at all what I do for a living, what apps I need
to run, what software I have to develop, and I'm afraid the area in
which I work (games/movie industry) is not a Linux friendly one in
the slightest.

You see for all the upgrading wonders and angelic like behaviour of
your OS creators, it doesn't count for shit if I can't use it for
work, and there - as is probably the case for the vast majority of
people stuck with Windows - is where the buck stops.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   3   4   5   6   7   8   9   10   >