Re: [PHP] Binary data confusion
Well, I'm always trying to make it harder than it needs to be. A few more hours of research yielded this solution: $out = preg_replace(/\%([0-9][0-9])/e, chr(hexdec(\0x$1\)), $buf); Header(Content-type: image/png); echo $out; ... Worked like a charm. If anyone can see any problems with this solution, I would be interested to hear them! Thanks, Clay From: Clay Loveless [EMAIL PROTECTED] Date: Fri, 10 Jan 2003 22:09:03 -0800 To: PHP-General [EMAIL PROTECTED] Subject: [PHP] Binary data confusion Hi, I've got a problem to solve regarding binary data strings, which is an area I don't have a lot of experience in. If anyone can help, I would be grateful. Here's the problem in a nutshell: I am getting a binary string from a third-party server that I need to encode into a PNG image. The string arrives double-quoted, so double quotes which may occur in the binary string have been escaped. I need to parse through the string and extract only the PNG data, and convert whatever has been escaped into usable data. I cannot control the output from the third-party -- I've got to deal with what they're sending. (I would much rather have them send a base64 encoded PNG, but unfortunately I'm not able to influence their methods.) Here's the problem as described by the API I'm working with: The rule for encoding the PNG image in the returned buffer was designed to eliminate certain illegal characters (byte values) by replacing them with an escape sequence. Those values that are not allowed include: * NULL (0x00 hex) * Double Quote (0x22 hex) The percent character '%' (0x25 hex) is used as the escape character, and therefore it must be replaced where it occurs naturally. Whenever a disallowed character or the escape character '%' is encountered, it is replaced by the escape character '%' (0x25 hex) followed by two characters comprising the hexadecimal numeral representing the value of the character. For example, the NULL character (0x00 hex) is replaced by three characters: * '%' (0x25) * '0' (0x30) * '0' (0x30) The percent character 0x25 is replaced by three characters: * '%' (0x25) * '2' (0x32) * '5' (0x35) The algorithm for decoding the PNG image in the returned buffer is as follows. Read bytes from the buffer one at a time. When a byte read is not equal to the '%' character (0x25 hex), pass it through unchanged. When a byte is read that is equal to the '%' character (0x25 hex), read an additional two bytes, which will each take a value from zero (0x30 hex) through nine (0x39 hex) or 'A' (0x41 hex) through 'F' (0x46 hex). These two bytes are interpreted as a character representation of a two-digit hexadecimal numeral ranging from 0x00 through 0xFF. The single byte having the integral value represented by that numeral is appended to your output. For example, when the 3-byte string '%22' is encountered, '' (0x22) - the double quote character - is passed out. When the 3 bytes '%00' are read, the null character is written. In essence, the developer will need to take the data received and store it in a buffer, which has sufficient memory to hold the entire data stream. Once the data has been received, the program must call a function similar to the one described below in order to parse the data in the buffer and extract only the PNG image data. The API then presents an example in C, which I've tried to translate into PHP as best as I can. It's pretty close, I think -- but I'm still not getting a PNG out when I'm done. Here's what I've written, based on the C example: $buf = [binary data received]; $len = strlen($buf); $out = ''; for ($c = 1; $c $len; $c++) { $data = $buf{$c}; if ($data != '%') $out .= $data; if ($data == '%') { for ($e = 0; $e 2; $e++) { $c++; $data = $buf{$c}; if ((($data = 0x30) ($data = 0x39)) || (($data = 0x41) ($data = 0x46))) { if ($e == 1) { $d = $data; $d = $d 0x0f; if (($data = 0x41) ($data = 0x46)) { $d += 9; } $store = $store | $d; } else { $d = $data; $d = $d 0x0f; if (($data = 0x41) ($data = 0x46)) { $d += 9; } $store = $d 4; } } } $out .= $store; } } Header(Content-type: image/png); echo $out; I'm just getting a blank screen at the end here -- not a PNG image
[PHP] Binary data confusion
Hi, I've got a problem to solve regarding binary data strings, which is an area I don't have a lot of experience in. If anyone can help, I would be grateful. Here's the problem in a nutshell: I am getting a binary string from a third-party server that I need to encode into a PNG image. The string arrives double-quoted, so double quotes which may occur in the binary string have been escaped. I need to parse through the string and extract only the PNG data, and convert whatever has been escaped into usable data. I cannot control the output from the third-party -- I've got to deal with what they're sending. (I would much rather have them send a base64 encoded PNG, but unfortunately I'm not able to influence their methods.) Here's the problem as described by the API I'm working with: The rule for encoding the PNG image in the returned buffer was designed to eliminate certain illegal characters (byte values) by replacing them with an escape sequence. Those values that are not allowed include: * NULL (0x00 hex) * Double Quote (0x22 hex) The percent character '%' (0x25 hex) is used as the escape character, and therefore it must be replaced where it occurs naturally. Whenever a disallowed character or the escape character '%' is encountered, it is replaced by the escape character '%' (0x25 hex) followed by two characters comprising the hexadecimal numeral representing the value of the character. For example, the NULL character (0x00 hex) is replaced by three characters: * '%' (0x25) * '0' (0x30) * '0' (0x30) The percent character 0x25 is replaced by three characters: * '%' (0x25) * '2' (0x32) * '5' (0x35) The algorithm for decoding the PNG image in the returned buffer is as follows. Read bytes from the buffer one at a time. When a byte read is not equal to the '%' character (0x25 hex), pass it through unchanged. When a byte is read that is equal to the '%' character (0x25 hex), read an additional two bytes, which will each take a value from zero (0x30 hex) through nine (0x39 hex) or 'A' (0x41 hex) through 'F' (0x46 hex). These two bytes are interpreted as a character representation of a two-digit hexadecimal numeral ranging from 0x00 through 0xFF. The single byte having the integral value represented by that numeral is appended to your output. For example, when the 3-byte string '%22' is encountered, '' (0x22) - the double quote character - is passed out. When the 3 bytes '%00' are read, the null character is written. In essence, the developer will need to take the data received and store it in a buffer, which has sufficient memory to hold the entire data stream. Once the data has been received, the program must call a function similar to the one described below in order to parse the data in the buffer and extract only the PNG image data. The API then presents an example in C, which I've tried to translate into PHP as best as I can. It's pretty close, I think -- but I'm still not getting a PNG out when I'm done. Here's what I've written, based on the C example: $buf = [binary data received]; $len = strlen($buf); $out = ''; for ($c = 1; $c $len; $c++) { $data = $buf{$c}; if ($data != '%') $out .= $data; if ($data == '%') { for ($e = 0; $e 2; $e++) { $c++; $data = $buf{$c}; if ((($data = 0x30) ($data = 0x39)) || (($data = 0x41) ($data = 0x46))) { if ($e == 1) { $d = $data; $d = $d 0x0f; if (($data = 0x41) ($data = 0x46)) { $d += 9; } $store = $store | $d; } else { $d = $data; $d = $d 0x0f; if (($data = 0x41) ($data = 0x46)) { $d += 9; } $store = $d 4; } } } $out .= $store; } } Header(Content-type: image/png); echo $out; I'm just getting a blank screen at the end here -- not a PNG image. Can anyone with more experience dealing with binary data offer any suggestions? I'm at a loss and would appreciate the help! I would be happy to send the example C code from the API if that would be helpful. Thank you! -Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] $this in an XML data handler ... in a class
Here's a brain-bender ... At least it is for me at the moment. : ) When I use an XML parser inside a class, the xml_*_handler functions aren't recognizing $this- variables. I can kind of see why ... But would like it to work anyway. : ) Here's an example: class Blah { var $xmlparser; var $current_element; // ... function _parseXML($data) { $this-xmlparser = xml_parser_create(); xml_set_element_handler( $this-xmlparser, array($this,_xml_start_element), array($this,_xml_end_element)); xml_set_character_data_handler( $this-xmlparser, array($this,_xml_character_data)); xml_parse($this-xmlparser, $data); xml_parser_free($this-xmlparser); } function _xml_start_element($p, $e_name, $e_attributes) { $this-current_element = $e_name; } function _xml_end_element($p, $e_name) { // ... } function _xml_character_data($p, $data) { echo element is: .$this-current_element.\n; echo data is: $data\n; } } // end of class Blah When this XML parser gets called from within the Blah class, the element is: portion of _xml_character_data comes out blank! This sort of makes sense, because the callback functions are children of the xml_parser_create parent ... But should that make the children ignorant of the grandparent variables referred to by $this-varname? I hope this makes sense ... Has anyone else encountered this sort of problem? I'm an old hat at PHP, but am relatively new to both XML parsing and writing my own classes. Thanks, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: $this in an XML data handler ... in a class
Unfortunately, the xml_set_object function does not work to solve this problem. I tried using it, and my results were the same as they were when I was not using it. [I found that the array($this, 'function_name') method instead of 'string function_name' for the xml_set_*_handler functions worked just as well, only without this Warning message one gets from PHP 4.2.1 upon using xml_set_object($this-parser, $this): PHP Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer.] Still searching for an answer on this one ... Thanks, -Clay Peter Clarke [EMAIL PROTECTED] Have a look at: http://www.php.net/manual/en/function.xml-set-object.php xml_set_object($this-parser, $this); Clay Loveless [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Here's a brain-bender ... At least it is for me at the moment. : ) When I use an XML parser inside a class, the xml_*_handler functions aren't recognizing $this- variables. I can kind of see why ... But would like it to work anyway. : ) Here's an example: class Blah { var $xmlparser; var $current_element; // ... function _parseXML($data) { $this-xmlparser = xml_parser_create(); xml_set_element_handler( $this-xmlparser, array($this,_xml_start_element), array($this,_xml_end_element)); xml_set_character_data_handler( $this-xmlparser, array($this,_xml_character_data)); xml_parse($this-xmlparser, $data); xml_parser_free($this-xmlparser); } function _xml_start_element($p, $e_name, $e_attributes) { $this-current_element = $e_name; } function _xml_end_element($p, $e_name) { // ... } function _xml_character_data($p, $data) { echo element is: .$this-current_element.\n; echo data is: $data\n; } } // end of class Blah When this XML parser gets called from within the Blah class, the element is: portion of _xml_character_data comes out blank! This sort of makes sense, because the callback functions are children of the xml_parser_create parent ... But should that make the children ignorant of the grandparent variables referred to by $this-varname? I hope this makes sense ... Has anyone else encountered this sort of problem? I'm an old hat at PHP, but am relatively new to both XML parsing and writing my own classes. Thanks, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $this in an XML data handler ... in a class
Actually, a careful reading of the docs reveals the following at the bottom of each xml_set_*_handler section: Note: Instead of a function name, an array containing an object reference and a method name can also be supplied. -Clay From: Analysis Solutions [EMAIL PROTECTED] Date: Wed, 3 Jul 2002 13:14:34 -0400 To: PHP List [EMAIL PROTECTED] Subject: Re: [PHP] $this in an XML data handler ... in a class Clay: On Wed, Jul 03, 2002 at 02:20:56AM -0700, Clay Loveless wrote: xml_set_element_handler( $this-xmlparser, array($this,_xml_start_element), array($this,_xml_end_element)); xml_set_character_data_handler( $this-xmlparser, array($this,_xml_character_data)); Without getting into all of the other potential issues in your code, allow me to quickly point out that the function name parameters to the set_*_handler() are supposed to be strings. The string is to be the name of the function. So, for example, do this: xml_set_character_data_handler($this-xmlparser, '_xml_character_data'); Now, I'm not guaranteeing this will cause the function to become part of the class, but at least the function will be properly initiated. --Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $this in an XML data handler ... in a class
In a follow up on this, here's something else that's kind of bizzare ... Within this class example, if I add a variable declaration of: var $testval = 'this is a test'; And then add to _xml_character_data(): echo TEST: $this-testval\n; ... I find that within the class structure, _xml_character_data can READ the $this-testval values (set outside of any callback function), but apparently the _xml_start_element() callback function cannot SET $this-current_element. My output is: element is: data is: [valid data] TEST: this is a test Is this a bug? It's beginning to have the feel of one... -Clay Here's a brain-bender ... At least it is for me at the moment. : ) When I use an XML parser inside a class, the xml_*_handler functions aren't recognizing $this- variables. I can kind of see why ... But would like it to work anyway. : ) Here's an example: class Blah { var $xmlparser; var $current_element; // ... function _parseXML($data) { $this-xmlparser = xml_parser_create(); xml_set_element_handler( $this-xmlparser, array($this,_xml_start_element), array($this,_xml_end_element)); xml_set_character_data_handler( $this-xmlparser, array($this,_xml_character_data)); xml_parse($this-xmlparser, $data); xml_parser_free($this-xmlparser); } function _xml_start_element($p, $e_name, $e_attributes) { $this-current_element = $e_name; } function _xml_end_element($p, $e_name) { // ... } function _xml_character_data($p, $data) { echo element is: .$this-current_element.\n; echo data is: $data\n; } } // end of class Blah When this XML parser gets called from within the Blah class, the element is: portion of _xml_character_data comes out blank! This sort of makes sense, because the callback functions are children of the xml_parser_create parent ... But should that make the children ignorant of the grandparent variables referred to by $this-varname? I hope this makes sense ... Has anyone else encountered this sort of problem? I'm an old hat at PHP, but am relatively new to both XML parsing and writing my own classes. Thanks, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $this in an XML data handler ... in a class
Dan, Thanks for your reply ... Glad to be helpful on the one tidbit I uncovered! Looks like your conclusion is the same as mine: the object variables are readable within the handler functions, but they are not writeable. Hence your use of the global variables ... That seems to be the only workaround. I'm convinced this has to be a bug ... Because what good is a contained class if you've got to interact with global variables in order to get the job done? Theoretically speaking, how do you know that you're not stepping on the toes of some other global variable? This solution may be good enough for me and you ... If we're not writing classes for distribution ... But they go against the grain of all the bennies I've read about classes. I'm not normally one to cry 'BUG!' ... But I think this qualifies. Do you agree? -Clay From: Analysis Solutions [EMAIL PROTECTED] Date: Wed, 3 Jul 2002 16:38:38 -0400 To: PHP List [EMAIL PROTECTED] Subject: Re: [PHP] $this in an XML data handler ... in a class Clay: On Wed, Jul 03, 2002 at 11:05:34AM -0700, Clay Loveless wrote: Note: Instead of a function name, an array containing an object reference and a method name can also be supplied. Interesting. Thanks! Anyway, back to your situation. I put together a test. Two counters are running and get displayed each time each function is called. One counter is a regular variable which I bring into each function via a global statement. The other counter is part of the object. Interestingly, in this case, the object variables are not acting as if they are part of the class, rather they're behaving as if their scope is stuck within each function. As far as parsing XML, be aware that the character data handler get's called for each bit of non-tag data, including white spaces in tags and between tags. And, character data can contain multiple lines but they get passed through the character data handler function one line at a time, not all at once. So, performing maneuvers in the character_handler function is tricky. I save my character data in an array and then implode the array in the end handler function. This process is in the test, below, as well. I've got a PHP XML expat parsing tutorial up on the web that may prove helpful: http://www.analysisandsolutions.com/code/phpxml.htm #! /usr/local/bin/php -q ?php class Blah { var $xmlparser; var $current_element; var $count = 0; function _parseXML($data) { global $g; $g = 0; $this-xmlparser = xml_parser_create(); xml_set_element_handler( $this-xmlparser, array($this,_xml_start_element), array($this,_xml_end_element)); xml_set_character_data_handler( $this-xmlparser, array($this,_xml_character_data)); xml_parse($this-xmlparser, $data); xml_parser_free($this-xmlparser); } function _xml_start_element($p, $e_name, $e_attributes) { global $CData, $g; $CData = array(); echo 'g:' . ++$g . ' o:' . ++$this-count . start\n; echo start element: $e_name\n; } function _xml_character_data($p, $data) { global $CData, $g; $CData[] = $data; echo 'g:' . ++$g . ' o:' . ++$this-count . character\n; echo character data: $data\n; } function _xml_end_element($p, $e_name) { global $CData, $g; echo 'g:' . ++$g . ' o:' . ++$this-count . end\n; echo end element: $e_name\n; echo end data array: . trim( implode('', $CData) ) . \n; } } // end of class Blah $XML = ' doc item Some Item Text /item /doc '; echo $XML\n; $Class = new Blah(); $Class-_parseXML($XML); ? Enjoy, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dealing with XML charsets
I haven't tried this myself yet, but will soon be facing a similar need. http://www.php.net/iconv That's probably the way I'll start off on tackling this problem ... Grab your XML document, check to see if it's in windows-1252, and if it is, run it through the iconv functions, then parse the XML data. -Clay From: Peter [EMAIL PROTECTED] Date: Tue, 02 Jul 2002 21:05:28 GMT To: [EMAIL PROTECTED] Subject: [PHP] Dealing with XML charsets Hi, Has anyone any advice as to how to deal with XML documents encoded in windows-1252: a character set that PHP's XML extension won't process? I've got a large number of such documents, and using xml_parse_into_struct() would be the easiest way to handle them - but because of the encoding problem I keep on ending up with ? instead of characters in the document in certain places. Is there any way I could convert the charset? Thanks Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what kind of weird problem is this?
Sounds like you're using Mac OS X, if you got PHP from entropy.ch ... Make sure you do NOT use TextEdit to edit/create your PHP scripts. Grab a copy of BBEdit Lite instead from www.barebones.com. You'll be glad you did! -Clay From: Joshua Alexander [EMAIL PROTECTED] Date: Wed, 19 Jun 2002 02:22:34 -0400 To: [EMAIL PROTECTED] Subject: [PHP] what kind of weird problem is this? I just installed the php 4.2.1 from entropy.ch and when running this script: ?php $test = just about anything; echo this was justa test; ? I get this error: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /Library/WebServer/Documents/west.php on line 3 Anyone know what *that* is about? -Josh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Setting my.cnf [client] values in PHP
[Sorry about replying to my own thread here] I've looked in php_mysql.c in the PHP source distribution, and it looks like the mysql. php.ini variables that are recognized are hard-coded. Okay ... Is there any other way to get PHP to pick up these three values? My understanding of how the MySQL client looks for config files is: 1. /etc/my.cnf (or, if not found ...) 2. MYSQLDATADIR/my.cnf (or, if not found ...) 3. $HOMEDIR/.my.cnf Does anyone know if the PHP Apache module would pick up .my.cnf when Apache switches to its non-root user account? If so, would any values found there be passed along to PHP's internal mysql client? Thanks, Clay From: Clay Loveless [EMAIL PROTECTED] Date: Tue, 18 Jun 2002 22:48:37 -0700 To: PHP-General [EMAIL PROTECTED] Subject: [PHP] Setting my.cnf [client] values in PHP I'm fiddling around with the SSL connection capabilities of MySQL 4.0.1-alpha ... In order for an SSL connection to succeed, the client and server must have some ssl parameters set either in MySQL's my.cnf file, or on the command-line to start the client or server. I've got the server configured okay, and have tested the SSL connection with the command-line mysql client. (It works!) Now the trick is getting PHP's mysql client to be aware of the ssl values. PHP does not seem to be picking them up from /etc/my.cnf ... I've set the appropriate values there, and have restarted Apache ... But connection attempts fail. (Presumably because the required SSL values are not being picked up by PHP's mysql client.) DOES PHP read in /etc/my.cnf? If not, will adding these values to php.ini work, even if undocumented? mysql.ssl-ca=SSL/cacert.pem mysql.ssl-cert=SSL/client-cert.pem mysql.ssl-key=SSL/client-key.pem Thanks in advance to anyone who may be able to shed some light on this ... Regards, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch the client OS user logon from php script
Edy, If you're referring to the OS a visitor to your site is using (not the OS your PHP is running on, which you probably know), you'd want: $_SERVER[HTTP_UA_OS] -Clay From: Brian McGarvie [EMAIL PROTECTED] Date: Wed, 19 Jun 2002 09:54:39 +0100 To: èdy kurniawan [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: RE: [PHP] catch the client OS user logon from php script $_ENV[OS] (see MANUAL for more that you can capture!) -Original Message- From: èdy kurniawan [mailto:[EMAIL PROTECTED]] Sent: 19 June 2002 9:44 AM To: [EMAIL PROTECTED] Subject: [PHP] catch the client OS user logon from php script Dear PHP-ers, How can I capture my client OS user logon via PHP script ? TIA, edyk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch the client OS user logon from php script
This is funny -- I see $_SERVER[HTTP_UA_OS] in the output of phpinfo(), and naturally assumed it was part of the $_SERVER superglobal array. This definitely isn't the first time I've seen a discrepancy between what phpinfo() shows in terms of server/apache/environment variables, and what you can actually USE in a script. I mentioned it in the first place because I didn't see $_ENV[OS] in phpinfo() output, or in the manual. I'd love to be able to use phpinfo() as the guide ... But it usually takes more experimenting than that. I suppose this is one of those times! : ) -Clay From: Brian McGarvie [EMAIL PROTECTED] Date: Wed, 19 Jun 2002 10:29:25 +0100 To: Clay Loveless [EMAIL PROTECTED], PHP-General [EMAIL PROTECTED] Subject: RE: [PHP] catch the client OS user logon from php script does... $_SERVER[HTTP_UA_OS] exist? I can't see that ne where and when I try to use it t's blank... Also... I was using that as an example to put him on the right track... afterall nuthing is learnt if your given it on a plate... if you want the exact OS, you need to extract it from $user_agent = $_SERVER[HTTP_USER_AGENT]; Here is a snippet to do so. $user_os = ltrim(substr($user_agent, strrpos($user_agent, ;)+1, strrpos($user_agent, ))-(strrpos($user_agent, ;)+1))); -Original Message- From: Clay Loveless [mailto:[EMAIL PROTECTED]] Sent: 19 June 2002 10:13 AM To: PHP-General Subject: Re: [PHP] catch the client OS user logon from php script Edy, If you're referring to the OS a visitor to your site is using (not the OS your PHP is running on, which you probably know), you'd want: $_SERVER[HTTP_UA_OS] -Clay From: Brian McGarvie [EMAIL PROTECTED] Date: Wed, 19 Jun 2002 09:54:39 +0100 To: èdy kurniawan [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: RE: [PHP] catch the client OS user logon from php script $_ENV[OS] (see MANUAL for more that you can capture!) -Original Message- From: èdy kurniawan [mailto:[EMAIL PROTECTED]] Sent: 19 June 2002 9:44 AM To: [EMAIL PROTECTED] Subject: [PHP] catch the client OS user logon from php script Dear PHP-ers, How can I capture my client OS user logon via PHP script ? TIA, edyk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Crontabs
He's referring to the script parser executable, ala: #!/bin/sh #!/usr/bin/perl In this case, you'd need the PHP cgi version installed, and do your script like this: #!/usr/bin/php -q ?php // your script ? Set the script to executable, then set up a crontab entry with the path to the script. -Clay From: Matthew Ward [EMAIL PROTECTED] Organization: Inspiration Studios Reply-To: Matthew Ward [EMAIL PROTECTED] Date: Tue, 18 Jun 2002 20:55:54 +0100 To: [EMAIL PROTECTED] Subject: Re: [PHP] Crontabs What do you mean by appropriate #! at the top? Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Matthew: On Tue, Jun 18, 2002 at 08:48:19PM +0100, Matthew Ward wrote: Basically, I want to get a PHP script to run every set amount of time, so what do I have to type in the Command box to get a PHP script to run? If your script has the appropriate #! at the top, you can type in the path and name of the script. Say, /usr/home/username/dir/script.php for example. Make sure the script has it's owner executable permission set (chmod 700, for example). --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] dynamic water marks?
Or, if the watermarks *must* be dynamically generated and visible, use something like ImageMagik to lay something transparent over the image on the fly. Wouldn't be exactly speedy, but would do the job. (I've seen this done on a few sites before -- visible graphic watermark is customized for the logged-in user.) You may be able to pull this off with the GD 2.01 tools also ... I haven't messed around too much with the alpha transparency capabilities the 2.01 library allows. ( http://www.php.net/imagealphablending ) -Clay From: Justin French [EMAIL PROTECTED] Date: Wed, 19 Jun 2002 14:25:05 +1000 To: Peter [EMAIL PROTECTED], Php [EMAIL PROTECTED], php_gen [EMAIL PROTECTED] Subject: Re: [PHP] dynamic water marks? The only ways would be: 1. dynamically add the water mark to the actual image (change the pixels) so that the source file has a watermark. 2. add a css layer on top of the image that contains a watermark Which brings me to the question, why don't you just add a watermark to each image? If a css layer or anything esle that DOESN'T change the source file was employed, it would only act as a very mild deterent. Why not just set-up an action script (macro) in Photoshop to batch process all the images with a watermark... end of story. Justin French on 19/06/02 2:22 PM, Peter ([EMAIL PROTECTED]) wrote: howdy does any one know if it's possible to assign a dynamic watermark to am image or place a watermark effect over a images so it looks like it's on the file when it's not really?...with out going into layers hopefully ... for example... a user up loads a simple image to the site say in jpg format when the image is displayed on any page a watermark is disply over part of the image .. to try and bluff other people into thinking the watermark is part of the image... Cheers Peter the only dumb question is the one that wasn't asked -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Setting my.cnf [client] values in PHP
I'm fiddling around with the SSL connection capabilities of MySQL 4.0.1-alpha ... In order for an SSL connection to succeed, the client and server must have some ssl parameters set either in MySQL's my.cnf file, or on the command-line to start the client or server. I've got the server configured okay, and have tested the SSL connection with the command-line mysql client. (It works!) Now the trick is getting PHP's mysql client to be aware of the ssl values. PHP does not seem to be picking them up from /etc/my.cnf ... I've set the appropriate values there, and have restarted Apache ... But connection attempts fail. (Presumably because the required SSL values are not being picked up by PHP's mysql client.) DOES PHP read in /etc/my.cnf? If not, will adding these values to php.ini work, even if undocumented? mysql.ssl-ca=SSL/cacert.pem mysql.ssl-cert=SSL/client-cert.pem mysql.ssl-key=SSL/client-key.pem Thanks in advance to anyone who may be able to shed some light on this ... Regards, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP with No Web Server?
Here's a cool little PHP app ... Requires PHP to be compiled as a standalone CGI with --enable-pcntl as a config option. http://nanoweb.si.kz/ Nanoweb is a modular http server written in PHP 4.2. Nanoweb's main features are : *Decent performance *HTTP/1.1 compliant *CGI support *Name based virtual hosts *Authentication *Keep-alive connections *Server Side Includes *Apache combined and MySQL logging *gzip compression support Fun code. : ) -Clay From: Stuart Dallas [EMAIL PROTECTED] Organization: SharedServer.net Reply-To: Stuart Dallas [EMAIL PROTECTED] Date: Thu, 13 Jun 2002 17:08:41 +0100 To: Kevin Caporaso [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] PHP with No Web Server? On Thursday, June 13, 2002, 5:00:23 PM, you wrote: In other words.. Can PHP serve as the Web Server or is another web server required to handle the socket connections, etc.? PHP can serve as a web server, but you would need to write (find) the code to do it - I'm sure there is plenty out there. However, to answer the question I think you were asking, PHP does not come with a ready-to-run web server. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Adding zeros in front
Try this: echo str_pad($row[main_group],4,0,STR_PAD_LEFT)./.$row[sub_group]; -Clay From: César L. Aracena [EMAIL PROTECTED] Date: Tue, 11 Jun 2002 00:11:30 -0300 To: PHP General List [EMAIL PROTECTED] Subject: [PHP] Adding zeros in front Hi all, Does anyone remembers how to add zeros in front of a result number given by a query to MySQL and returned as an array, so it always shows a 4 digit number? I have: [snip] echo $row[main_group]./.$row[sub_group]; [snip] but throws out: 1/0 2/0 3/0 instead of: 0001/0 0002/0 0003/0 which it should. Thanks in advance, Cesar Aracena mailto:[EMAIL PROTECTED] CE / MCSE+I Neuquen, Argentina +54.299.6356688 +54.299.4466621 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
FW: [PHP] MacOSX / php.ini newbie question
Verdon, Maybe you didn't see my response to your message yesterday, since I saw a few more posts from you after I replied wondering where you can get a php.ini file. Just go to http://www.php.net/downloads Download the .tar.gz file for the version you're using from entropy.ch Within, you will find php.ini-dist and php.ini-recommended. Move those out of the directory of unpacked PHP source, and delete the rest. (You won't need it, since you have the entropy.ch version.) Look through the two files. Decide which one you like. Edit if necessary. Rename to php.ini Upload to your /usr/lib directory on your server. That's it! -Clay -- Forwarded Message From: Clay Loveless [EMAIL PROTECTED] Date: Mon, 03 Jun 2002 19:11:10 -0700 To: PHP-General [EMAIL PROTECTED] Subject: Re: [PHP] MacOSX / php.ini newbie question Verdon, I'm a fellow PHP'er on Mac OS X (Server) 10.1.4. : ) You need to download the full distribution from php.net/downloads ... In there you will find a php.ini-dist file and php.ini-recommended file. Pick one that you like, edit as needed with BBEdit Lite (NOT TextEdit!), rename to php.ini and upload to /usr/lib. Restart Apache, and the newly installed php.ini file will be read in at that time. Good luck! -Clay From: Verdon Vaillancourt [EMAIL PROTECTED] Date: Mon, 03 Jun 2002 21:15:27 -0400 To: [EMAIL PROTECTED] Subject: [PHP] MacOSX / php.ini newbie question Hi Apologies in advance if this question is simple. I haven't been able to find an answer... Is there no php.ini file in a php 4.1.2 install on MacOSX 10.1.4 (client not server) ? My php info/test page says that the path to the configuration file (php.ini) file is '/usr/lib', but it is not there (or anywhere else according to locate) Is this a file I can create myself or is there an example to be had somewhere? TIA, verdon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- End of Forwarded Message -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Download Script - Newbie Alert
Something else along these lines -- I really, really wish that more sites that use this method would test across multiple browsers and platforms. I agree with everything John is saying regarding testing access/permissions -- I've used this technique many times myself. However, if a user with Internet Explorer on Mac OS X clicks this link: www.domain.dom/file.php?id=23 They'll wind up with a file on their desktop called file.php. Not every browser pays close enough attention to the filename in the Content-Disposition header. Solution? www.domain.com/file.php/23/docname.xls I believe this will run file.php, which can then pull in the $PATH_INFO to determine what file is being requested, check session permissions, etc., can then spit out the right headers as John suggests, AND users will definitely wind up with a downloaded file called docname.xls. If your pages are dynamically generated, you can even do tricks like this to thwart external linking: ?php $bootLeech = date(U) / 2; echo a href=\http://www.domain.com/file.php/23/$bootLeech/docname.xls;download/a ; ? Then in your file.php script, do the following: - explode $PATH_INFO on / - check the $bootLeach array position with the same calculation ... Where you can allow a plus/minus error tolerance of 10 minutes. We use this trick on http://www.imagescentral.com ... Kids frequently want to build Geocities sites that leech all our images. Our image file URLs work *just* long enough for them to build their pages, and test that they look good. 30 hours later, all the leeched images are replaced with Images Central logos. : ) Fun! -Clay From: John Holmes [EMAIL PROTECTED] Organization: U.S. Army Reply-To: [EMAIL PROTECTED] Date: Mon, 3 Jun 2002 20:06:42 -0400 To: 'Philip Hess' [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: RE: [PHP] Download Script - Newbie Alert Store the files above your web root and use a PHP script to control access. Use header to set the appropriate header for the file, header(Content-Type: application/vnd.ms-excel; name='excel'); header(Content-Disposition: attachment; filename= . $filename . .xls); then use passthru() to send the contents of the file. Use a path for passthru that's above the web root. The key to this though, is to do some checking with PHP to make sure the person is authorized to download the file. Simply doing the above will still allow someone to link directly to file.php?id=23 or whatever, and get the contents. Start a session on another page, the one before the download, and then check for the session in this page, before you send the file. If the session doesn't exist (or a certain variable within it) then don't send the file. ---John Holmes... -Original Message- From: Philip Hess [mailto:[EMAIL PROTECTED]] Sent: Monday, June 03, 2002 6:09 PM To: [EMAIL PROTECTED] Subject: [PHP] Download Script - Newbie Alert Hello, I would like to allow visitors to my site to download documents created with MS office and .PDF files as well. In order to prevent linking from other sites I'd like to make or modify a script that hides the actual location of the files. A pointer in the right direction would be most appreciated. Thanks --- Philip Hess - Pittsburgh, PA USA - Computer Teacher E-mail: pjh_at_zoominternet.net Phil's Place (my web site) http://phil.mav.net/ PA School District Database: http://phil.mav.net/district.hts --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MacOSX / php.ini newbie question
Verdon, I'm a fellow PHP'er on Mac OS X (Server) 10.1.4. : ) You need to download the full distribution from php.net/downloads ... In there you will find a php.ini-dist file and php.ini-recommended file. Pick one that you like, edit as needed with BBEdit Lite (NOT TextEdit!), rename to php.ini and upload to /usr/lib. Restart Apache, and the newly installed php.ini file will be read in at that time. Good luck! -Clay From: Verdon Vaillancourt [EMAIL PROTECTED] Date: Mon, 03 Jun 2002 21:15:27 -0400 To: [EMAIL PROTECTED] Subject: [PHP] MacOSX / php.ini newbie question Hi Apologies in advance if this question is simple. I haven't been able to find an answer... Is there no php.ini file in a php 4.1.2 install on MacOSX 10.1.4 (client not server) ? My php info/test page says that the path to the configuration file (php.ini) file is '/usr/lib', but it is not there (or anywhere else according to locate) Is this a file I can create myself or is there an example to be had somewhere? TIA, verdon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: email attachments and PHP
Another really good one: http://phpmailer.sourceforge.net/ -Clay From: Jason Morehouse [EMAIL PROTECTED] Organization: Netconcepts LTD Date: Tue, 04 Jun 2002 17:15:58 +1200 To: [EMAIL PROTECTED] Subject: [PHP] Re: email attachments and PHP Check out: http://www.phpguru.org/mime.mail.html Works well... some good examples included. -J On Tue, 04 Jun 2002 17:09:12 +1200, Brad Wright wrote: Hi all, I was wondering if there is a way to attach files to emails sent via a PHP script. I just checked the 'mail functions' chapter of the php manual, but it doesn't seem to mention attachments. The attached files will come from the same server that php is running on BTW. Thanks in advance. Brad Nel vino la verità, nella birra la forza, nell'acqua i bacilli -- In wine there is truth, in beer there is strenght, in water there are bacteria -- Jason Morehouse ([EMAIL PROTECTED]) Netconcepts LTD - Auckland, New Zealand * Linux: Because rebooting is for adding hardware. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl functions for task manager - comments?
After playing around with this further, here is more functional pseudo-code ... Primary change in the placement and method of the waidpid routine. I'm still open to comments on this ... Otherwise, I hope this snippet is useful to someone! : ) // run forever if necessary set_time_limit(0); // detatch from the controlling terminal if (!posix_setsid()) { die('could not detach from terminal'); } // setup signal handlers pcntl_signal(SIGTERM, sig_handler); pcntl_signal(SIGHUP, sig_handler); // loop forever waiting on jobs while(1) { // check queue for pending jobs // (db lookup omitted, let's assume jobs are waiting) $jobs_waiting = true; if($jobs_waiting) { $pid = pcntl_fork(); if($pid == -1) { die('could not fork'); } else if ($pid) { // parent } else { // child // perform task on jobs waiting // when job(s) complete, quit exit(); } } // call waitpid to collect children that // have already terminated $tpid = pcntl_waitpid(-1,$status,WNOHANG); //verbose output //if($tpid 0) echo Parent collected child $tpid\n; // wait two seconds before checking queue again sleep(2); unset($jobs_waiting); } function sig_handler($signo) { // blah blah } -Clay From: Clay Loveless [EMAIL PROTECTED] Date: Sat, 01 Jun 2002 12:38:18 -0700 To: PHP-General [EMAIL PROTECTED] Subject: [PHP] pcntl functions for task manager - comments? I'm experimenting with PHP's pcntl_* functions using the PHP cgi ... I've never written a daemon before, and there doesn't seem to be a lot of information out there about how to do this with the pcntl functions. So, I've read what I can find on the subject as it deals with UNIX programming. The goal is a script that will run forever, checking a job queue ... If jobs are waiting, use pcntl_fork() to handle the jobs. To this end, I've come up with this pseudo-code ... Before going WAY off in this direction, I'd like to submit this for comments by those who've had more experience with this sort of thing. -- // run forever if necessary set_time_limit(0); // detatch from the controlling terminal if (!posix_setsid()) { die('could not detach from terminal'); } // setup signal handlers pcntl_signal(SIGTERM, sig_handler); pcntl_signal(SIGHUP, sig_handler); // loop forever waiting on jobs while(1) { // check queue for pending jobs // (db lookup omitted, let's assume jobs are waiting) $jobs_waiting = true; if($jobs_waiting) { $pid = pcntl_fork(); if($pid == -1) { die('could not fork'); } else if ($pid) { // parent // call waitpid to reap children that // have already terminated do { $tpid = pcntl_waitpid(-1,$status,WNOHANG); if($tpid == -1) die('error occurred while waiting for child'); } while (!$tpid); } else { // child // perform task on jobs waiting // when job(s) complete, quit exit(); } } // wait two seconds before checking queue again sleep(2); unset($jobs_waiting); } function sig_handler($signo) { // blah blah } I am open to suggestions or comments on this approach! Please let me know if you think this looks nuts. Thanks, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl functions for task manager - comments?
I'm experimenting with PHP's pcntl_* functions using the PHP cgi ... I've never written a daemon before, and there doesn't seem to be a lot of information out there about how to do this with the pcntl functions. So, I've read what I can find on the subject as it deals with UNIX programming. The goal is a script that will run forever, checking a job queue ... If jobs are waiting, use pcntl_fork() to handle the jobs. To this end, I've come up with this pseudo-code ... Before going WAY off in this direction, I'd like to submit this for comments by those who've had more experience with this sort of thing. -- // run forever if necessary set_time_limit(0); // detatch from the controlling terminal if (!posix_setsid()) { die('could not detach from terminal'); } // setup signal handlers pcntl_signal(SIGTERM, sig_handler); pcntl_signal(SIGHUP, sig_handler); // loop forever waiting on jobs while(1) { // check queue for pending jobs // (db lookup omitted, let's assume jobs are waiting) $jobs_waiting = true; if($jobs_waiting) { $pid = pcntl_fork(); if($pid == -1) { die('could not fork'); } else if ($pid) { // parent // call waitpid to reap children that // have already terminated do { $tpid = pcntl_waitpid(-1,$status,WNOHANG); if($tpid == -1) die('error occurred while waiting for child'); } while (!$tpid); } else { // child // perform task on jobs waiting // when job(s) complete, quit exit(); } } // wait two seconds before checking queue again sleep(2); unset($jobs_waiting); } function sig_handler($signo) { // blah blah } I am open to suggestions or comments on this approach! Please let me know if you think this looks nuts. Thanks, Clay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple email validation ereg
Maybe I'm biased, but if you grab validateEmailFormat.php from www.killersoft.com, you'd be able to do something as simple as this: ?php include(/path/to/validateEmailFormat.php); $email = [EMAIL PROTECTED]; $isValid = validateEmailFormat($email); if($isValid) { // do whatever you need to do } else { echo sorry, that address isn't formatted properly.; } ? validateEmailFormat.php is a translation of the Perl regular expression that's widely considered to be the defintive test of a valid RFC822 address. Can't go wrong with that. : ) -Clay From: Justin French [EMAIL PROTECTED] Date: Sun, 02 Jun 2002 14:13:40 +1000 To: php [EMAIL PROTECTED] Subject: [PHP] simple email validation ereg Hi, I know that there are more complex functions and classes out there for validating email address', but some of them do return invalid on *technically* valid, although uncommon email address', so all I want is a simple test for: (anything)@(anything) followed by 1 or more (.anything) ie foo@foo : invalid [EMAIL PROTECTED] : valid [EMAIL PROTECTED] : valid i wish to allow ANYTHING really -- not just a-z,A-z,0-9,_,- technically spaces, brackets, and all sorts of crap are valid in the user portion of the email address :) this will return true for [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] etc etc... i'm aware that the results will not necessarily BE valid email address', but at least they'll *look* like valid email address'. it's for a simple guestbook/message board where some creative people have put in lalaland or myplace as an email address, rather than entering something that at least LOOKS like a valid address, or optionally leaving the field blank. my aim will be to strip out anything that doesn't at least LOOK like like an email address. regards, justin french -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ANNOUNCE: validateEmail 2.0 validateEmailFormat 1.0
Announcing a couple of PHP scripts that I think have been a long time in coming ... validateEmail - 2.0 A much needed updating of the validateEmail function created in '98 by Jon S. Stevens, and updated by Shane Gibson, berber, and Frank Vogel over time. Several new features have been added, including an improved wait routine for sluggish hosts, and RFC 2821-compliant SMTP command formatting to eliminate hang problems caused by attempts to validate on certain hosts. I realize there is quite a bit of controversy over the validation methods used by this script -- therefore, some people may not favor it. However, I feel it's an effective first line of defense against the [EMAIL PROTECTED] sort of garbage, etc. Those who use validateEmail now will find this to be a useful upgrade. validateEmailFormat - 1.0 The PHP online docs say the following in the add a note section: (And if you're posting an example of validating email addresses, please don't bother. Your example is almost certainly wrong for some small subset of cases. See this information from O'Reilly Mastering Regular Expressions book for the gory details.) Good advice, I think. So good, in fact, that I figured it was time someone just went ahead and translated that regex into PHP. This code is distributed in accordance with O'Reilly's policy on re-use of code examples from their books. (http://www.oreilly.com/ask_tim/codepolicy_1101.html) # # # I fully recognize that there is no foolproof way to validate an e-mail address (either its functionality or formatting) without actually sending a message and requiring the user to respond. In the cases where that tactic is not considered acceptable, I believe the combination of these two functions is the next best thing. validateEmail and validateEmailFormat are freely available at: http://www.killersoft.com/contrib/index.html Comments, suggestions and questions encouraged. Enjoy! Regards, -Clay __ Clay Loveless KillerSoft - http://www.killersoft.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php