Re: [PHP] question about corrupt db?
On Tue, 2008-12-02 at 01:14 +, Nathan Rixham wrote: Ashley Sheridan wrote: On Mon, 2008-12-01 at 16:29 -0600, Terion Miller wrote: On Mon, Dec 1, 2008 at 4:20 PM, Ashley Sheridan [EMAIL PROTECTED] wrote: On Mon, 2008-12-01 at 15:53 -0600, Terion Miller wrote: On Mon, Dec 1, 2008 at 3:40 PM, Wolf [EMAIL PROTECTED] wrote: -Original Message- From: Terion Miller [EMAIL PROTECTED] Sent: Monday, December 01, 2008 4:23 PM To: Micah Gersten [EMAIL PROTECTED] Cc: PHP General php-general@lists.php.net Subject: Re: [PHP] question about corrupt db? On Mon, Dec 1, 2008 at 3:12 PM, Micah Gersten [EMAIL PROTECTED] wrote: Terion Miller wrote: could a corrupt db make php pages stop functioning? My pages no longer go anywhere, I went back found the original scripts and still it didn't fix the problem (thought I had messed the code up) so it has to be something external of the code its doing this locally on my box and on the live server. thanks terion Have you checked the PHP error logs? Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com I put this: ini_set('error_reporting', E_ALL); ini_set('display_errors', true); in the top of the pages but no errors are showing -- Then that answer would be no You need to actually look at your error logs as if the server is set up right it won,'t allow ini bypasses. Wolf I can't find any error logs, I've looked in the inetpub folder, the php folder the IIS services admin IIS has an option that lets you view the websites you have set up (I believe you can get to it from right-clicking My Computer and selecting Manage.) Select the site you are having problems with, and view the properties for it. One of the tabs (I forget which exactly) tells you where the error logs are for this site. Ash www.ashleysheridan.co.uk wow not there either, is it possible the person in this job before me just removed the logs and the servers capability to log? like there is no usr/bin/log file or anything like that (went to the apache site) and in the IIS install I went thru everything and can't find a thing about error logs...OMG pulling out my hair. Well, /usr/bin/log is for Apache on Linux, so won't be of any use to you with IIS on Windows! Stupid question, but have you searched for all *.log files? As far as I know, you can't stop the server logging, and I think IIS locks the logs to prevent accidental deletion. Generally speaking, the logs will be pretty large files (depending on how busy your website is) if that helps you narrow down your search. Ash www.ashleysheridan.co.uk just turn display errors on and set reporting to E_ALL ? save mucking around (although it is normally a good idea to know where you're log files are) :p If you read the thread, you'd know he's already tried that, and there's some information you just don't get with E_ALL that you need to look at the logs for. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Countries and Timezones
franzemmanuel wrote: Hi everybody, For those who are interested in Countries and timezones. I needed to have the list of all the countries in the world and the timezones by country without redundancy. Couldn't you just have use the timezone info from mysql? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] category and sub category traversal
I need some help in figuring out this logic. I have two tables one for category and other for category_hierarchy. category_hirerarchy has a column to determine the parent. So the query I have to retrieve tree of one specific category is: SELECT t.tid, t.*, parent FROM term_data t INNER JOIN term_hierarchy h ON t.tid = h.tid WHERE t.vid = 16 ORDER BY weight, name; The ones with parent = 0 is the top category Now I need to prepare an associative array with parent child relation. So bascially I need to retrieve [parentID] = array('childID', 'chidName') Can anyone shed some light on the logic involved in preparation of this array with out using multiple sql queries? The structure you've highlighted is very common (that's not to say bad at all). You might be interested in this: http://www.phpguru.org/downloads/Tree_array/Tree.phps Which looks at the same structure and creates a tree object from it. Using this you will be able to manage it. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org (Updated November 29th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Short circuit evaluation and include
Hello everyone, I'm posting this as a warning when using include() or include_once() and checking their return values. I'm refactoring someone else's code at the moment and got a short circuit evaluation problem that made some problems .. Here's the code: FILE some_file.php: ?php function some_function($file) { $obj = false; if ( !isset($file) || !is_string($file) || !is_readable($file) || !include_once($file) || !class_exists('some_class') || !is_a(($obj = new some_class()), 'some_class') || !method_exists($obj, 'some_method') || !$obj-some_method() ) return false; // line 14 return $obj; } $file = 'some_class.php'; some_function($file); ? FILE some_class.php: ?php class some_class { function some_method() { return true; } } ? ERRORS PRODUCED: Warning: some_function(1) [function.some-function]: failed to open stream: No such file or directory in */some_file.php on line 14 Warning: some_function() [function.include]: Failed opening '1' for inclusion (include_path='.;*/php/pear/') in */some_file.php on line 14 Note: I ran this code in PHP 4.4.9 It seemed to me like include_once() was not fully executed or something when short circuited, because this code worked just fine ... FILE some_file.php: ?php function some_function($file) { $obj = false; if ( !isset($file) || !is_string($file) || !is_readable($file) || !include_once($file) ) return false; if ( !class_exists('some_class') || !is_a(($obj = new some_class()), 'some_class') || !method_exists($obj, 'some_method') || !$obj-some_method() ) return false; return $obj; } $file = 'some_class.php'; var_dump(some_function($file)); ? OUTPUT: object(some_class)(0) { } So I was wondering how include() or include_once() are actually being executed. I know they both return int(1) if no return specified in the included file. That's why I had a glance at the manual [1], where I saw this .. Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value. Example #4 Comparing return value of include ?php // won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('') if (include('vars.php') == 'OK') { echo 'OK'; } // works if ((include 'vars.php') == 'OK') { echo 'OK'; } ? So when I added the paranthesis it worked ... FILE some_file.php: ?php function some_function($file) { $obj = false; if ( !isset($file) || !is_string($file) || !is_readable($file) || !(include_once($file)) // --- added paranthesis || !class_exists('some_class') || !is_a(($obj = new some_class()), 'some_class') || !method_exists($obj, 'some_method') || !$obj-some_method() ) return false; return $obj; } $file = 'some_class.php'; var_dump(some_function($file)); ? Me, after an hour of coding without a line of code. [1] http://in.php.net/manual/en/function.include.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_intersect question
I know there must be a more elegant way with array_reduce or something, but I would simply write a function called function array_intersect_m($m_array) { $intersection = $m_array[0]; for ($i=1; $i count($m_array); $i++) { $intersection = array_intersect($m_array[$i], $intersection); } return $intersection; } and put that into my library. O and while i'm at it, the array_reduce way would prob be: $m_array = array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow)); array_reduce($m_array, 'array_intersect'); but this could be wrong, havent done much with these 'meta' functions. Regards, Tim On Tue, Dec 2, 2008 at 10:24 PM, Andrej Kastrin [EMAIL PROTECTED]wrote: Dear all, I have to perform an intersection on array of arrays. The fact is that php does not support intersection on multidimensional arrays. So, the first simple example using only one dimensional arrays works well: $array1 = array(green, red, blue); $array2 = array(green, yellow, red); $array3 = array(green, red, purple); $array4 = array(green,red,yellow); $result = array_intersect($array1,$array2,$array3,$array4); print_r($result); And the result is: Array ( [0] = green [1] = red ) The question is how to perform intersection on the following structure: $products = array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow)); Thanks in advance for any suggestions. Best, Andrej -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
[PHP] category and sub category traversal
Google for SELF JOIN You also may want to just put the parent_id in the category table, rather than a second table. Your query would then look like this: select parent.tid, child.tid from term_data as parent, term_data as child where child.parent_id = parent.tid and child.vid = 16 order by weight, name WARNING: If term_data is a LARGE table, this query could become problematic. You'll need an index on (tid, vid, weight, name), I think. Follow-up with more questions to the MySQL (or other SQL) mailing list please, as there's no actual PHP in this question. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] array_intersect question
Dear all, I have to perform an intersection on array of arrays. The fact is that php does not support intersection on multidimensional arrays. So, the first simple example using only one dimensional arrays works well: $array1 = array(green, red, blue); $array2 = array(green, yellow, red); $array3 = array(green, red, purple); $array4 = array(green,red,yellow); $result = array_intersect($array1,$array2,$array3,$array4); print_r($result); And the result is: Array ( [0] = green [1] = red ) The question is how to perform intersection on the following structure: $products = array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow)); Thanks in advance for any suggestions. Best, Andrej -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to hide MySQL password in connection string in PHP script?
On a shared server, you rarely can really protect your MySQL user/pass from other users on the same server. The problem is that your PHP process is probably an Apache module, and you probably don't have your own separate pool of Apache User processes. So, by definition, if YOUR script can read the .php file and load it and get the user/pass to use them, then ANY .php file can load the file and get the user/pass to abuse them. You have to weigh this risk with the value/secrecy/privacy of the data, and decide what to do. You might have to move to a dedicated server. You might not. You might just add a barrier for the absolutely crucial fields of 2-way encrypting them in PHP. Of course, the bad person can then read your other .php file to find the 2-way de-cryption, but it's more steps for them to go through, and if the data isn't THAT interesting, they won't. You would NOT want to do this for: credit card info (which probably doesn't need storing anyway) SSN medical info But you might not care all THAT much for yet another shopping cart or a blog etc. Keep backups though, just in case a rogue user does mess you up! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML RSS installation
htdocs -- This the document root of your website pear + HTML + Mail + Net If you're going to set your include path properly, you might as well not put PEAR in htdocs, since none of those files are front-facing URLs that should be visited by an end user. They belong in a non web root directory somewhere else to insure that there is NO WAY EVER that they could be visited directly by a malicious user. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to hide MySQL password in connection string in PHP script?
Robert Dodier robert_dodier AT yahoo.com wrote on 12-21-2003 Hello, I am experimenting with a wiki system (PhpWiki) which uses a MySQL database to store pages. It seems like a great system. The MySQL connection string is specified in a PHP script in the form mysql://FOO:[EMAIL PROTECTED]/baz. If I'm not mistaken the script has to be world-readable. But then, can't any other user (logged in to the host) just read the password? I share the host with other users, and the script has to be in my home directory, so I don't think I can guarantee that no other user can see it. Thanks for any advice, Robert Dodier I recently had the same problem on a shared host. The only solution I could think of was to have the server admin set an environment variable in an httpd.conf include file owned by root (chmod 600) [1]. EXAMPLE (mysql_pw.conf): SetEnv mysql_pw password SetEnv mysql_user username In PHP the variables then should end up in the $_SERVER array ... EXAMPLE (PHP): ?php var_dump($_SERVER['mysql_pw'], $_SERVER['mysql_user']); ? If this is impossible I can't think of another secure way on shared host systems, since other hosts usually are able to read your files. Maybe (if supported) one could SetEnv in .htaccess, so an attacker would at least have to glance into the PHP source code to find out where the password is stored. Still most people have it inside an include file and it works, I think. [1] http://httpd.apache.org/docs/1.3/mod/mod_env.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Short circuit evaluation and include
include and require are not functions. They are language constructs. They probably don't return values nor short-circuit in the usual way. Ditto for echo If you can strip the parens and have it still work, it's for sure not a function. ?php include_once $file; echo $file; ? is perfectly valid code. PS All those disk calls are going to get pretty expensive if your site gets heavy traffic... You may want to just write a custom error_handler and use include_once which will let you trap the error and do something intelligent with it... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_intersect question
It works like a charm. Thanks, Andrej Tim | iHostNZ wrote: I know there must be a more elegant way with array_reduce or something, but I would simply write a function called function array_intersect_m($m_array) { $intersection = $m_array[0]; for ($i=1; $i count($m_array); $i++) { $intersection = array_intersect($m_array[$i], $intersection); } return $intersection; } and put that into my library. O and while i'm at it, the array_reduce way would prob be: $m_array = array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow)); array_reduce($m_array, 'array_intersect'); but this could be wrong, havent done much with these 'meta' functions. Regards, Tim On Tue, Dec 2, 2008 at 10:24 PM, Andrej Kastrin [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Dear all, I have to perform an intersection on array of arrays. The fact is that php does not support intersection on multidimensional arrays. So, the first simple example using only one dimensional arrays works well: $array1 = array(green, red, blue); $array2 = array(green, yellow, red); $array3 = array(green, red, purple); $array4 = array(green,red,yellow); $result = array_intersect($array1,$array2,$array3,$array4); print_r($result); And the result is: Array ( [0] = green [1] = red ) The question is how to perform intersection on the following structure: $products = array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow)); Thanks in advance for any suggestions. Best, Andrej -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML RSS installation
What do you mean by replicating the directory structure? PEAR has a directory structure. Duplicate it and set you include_path accordingly. Have a look at the application structure on article my website ( http://www.phpguru.org ) - it may be of some help. Eg: htdocs -- This the document root of your website pear + HTML + Mail + Net -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org (Updated November 29th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Voting methodology
Shawn McKenzie wrote: tedd wrote: Hi gang: What methodology would be the best for online voting? I have a client who is a Union and they want members to vote online, but don't want someone to stuff the voting box. I have some ideas of my own, but would like to hear what you people would recommend. Cheers, tedd Being a union I would expect that they want some way to control the stuffing to their advantage. :-) Also, don't forget to insure the is NO audit trail. e.g., all champaign contributions less than $200, even for some credit cards that post $199 1000 times. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_intersect question
The question is how to perform intersection on the following structure: $products = array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow)); If I understood you correctly .. ?php $arr = array(); $arr[] = array(green, red, blue); $arr[] = array(green, yellow, red); $arr[] = array(green, red, purple); $arr[] = array(green,red,yellow); var_dump($arr); // you could also .. $arr = array(); array_push( $arr, array(green, red, blue), array(green, yellow, red), array(green, red, purple), array(green,red,yellow) ); var_dump($arr); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML RSS installation
htdocs -- This the document root of your website pear + HTML + Mail + Net That's not what I wrote: htdocs -- This the document root of your website pear + HTML + Mail + Net -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org (Updated November 29th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] question about corrupt db?
To view the logs in IIS you must go to the root web site in the IIS Snap in, virtual folders, folders and applications don't have a separate log file. In the left panel in the snap in, right click in the site, probably default web site, click on properties, look for a tab called 'Web Site', in the bottom of the tab look for a checkbox labeled Enable Logs, mark it to enable logs, Click the properties button and select the folder to store logs. Fallow the same path to see where the logs are stored. Hope it helps. Uaca 2008/12/2 Ashley Sheridan [EMAIL PROTECTED]: On Tue, 2008-12-02 at 01:14 +, Nathan Rixham wrote: Ashley Sheridan wrote: On Mon, 2008-12-01 at 16:29 -0600, Terion Miller wrote: On Mon, Dec 1, 2008 at 4:20 PM, Ashley Sheridan [EMAIL PROTECTED] wrote: On Mon, 2008-12-01 at 15:53 -0600, Terion Miller wrote: On Mon, Dec 1, 2008 at 3:40 PM, Wolf [EMAIL PROTECTED] wrote: -Original Message- From: Terion Miller [EMAIL PROTECTED] Sent: Monday, December 01, 2008 4:23 PM To: Micah Gersten [EMAIL PROTECTED] Cc: PHP General php-general@lists.php.net Subject: Re: [PHP] question about corrupt db? On Mon, Dec 1, 2008 at 3:12 PM, Micah Gersten [EMAIL PROTECTED] wrote: Terion Miller wrote: could a corrupt db make php pages stop functioning? My pages no longer go anywhere, I went back found the original scripts and still it didn't fix the problem (thought I had messed the code up) so it has to be something external of the code its doing this locally on my box and on the live server. thanks terion Have you checked the PHP error logs? Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com I put this: ini_set('error_reporting', E_ALL); ini_set('display_errors', true); in the top of the pages but no errors are showing -- Then that answer would be no You need to actually look at your error logs as if the server is set up right it won,'t allow ini bypasses. Wolf I can't find any error logs, I've looked in the inetpub folder, the php folder the IIS services admin IIS has an option that lets you view the websites you have set up (I believe you can get to it from right-clicking My Computer and selecting Manage.) Select the site you are having problems with, and view the properties for it. One of the tabs (I forget which exactly) tells you where the error logs are for this site. Ash www.ashleysheridan.co.uk wow not there either, is it possible the person in this job before me just removed the logs and the servers capability to log? like there is no usr/bin/log file or anything like that (went to the apache site) and in the IIS install I went thru everything and can't find a thing about error logs...OMG pulling out my hair. Well, /usr/bin/log is for Apache on Linux, so won't be of any use to you with IIS on Windows! Stupid question, but have you searched for all *.log files? As far as I know, you can't stop the server logging, and I think IIS locks the logs to prevent accidental deletion. Generally speaking, the logs will be pretty large files (depending on how busy your website is) if that helps you narrow down your search. Ash www.ashleysheridan.co.uk just turn display errors on and set reporting to E_ALL ? save mucking around (although it is normally a good idea to know where you're log files are) :p If you read the thread, you'd know he's already tried that, and there's some information you just don't get with E_ALL that you need to look at the logs for. Ash www.ashleysheridan.co.uk -- 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] How to type arguments
Hello, I'm a french student, sorry for my mail : I want to know how can I type my functions' arguments ? It is heavy to do : function post($id) { $id=(int)$id; //... or tu put (int) before each use... Thank you for your help _ Email envoyé avec Windows Live Hotmail. Dites adieux aux spam et virus, passez à Hotmail ! C'est gratuit ! http://www.windowslive.fr/hotmail/default.asp
Re: [PHP] XML RSS installation
I apologize for the misunderstanding. That's OK, I forgive you my child. :-) -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org (Updated November 29th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML RSS installation
htdocs -- This the document root of your website pear + HTML + Mail + Net That's not what I wrote: htdocs -- This the document root of your website pear + HTML + Mail + Net I apologize for the misunderstanding. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to type arguments
I'm a french student, sorry for my mail : I want to know how can I type my functions' arguments ? It is heavy to do : function post($id) { $id=(int)$id; //... PHP is loosely typed so strictly (...) speaking, that would be fine. However, you're best off making sure that what you've been given is what you think it is. Ergo, what you've written, is what I would do. or tu put (int) before each use... Not necessary to put it there for each use, just the first. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org (Updated November 29th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Slow file download
I'm using a PHP cron job to constantly download files from a remote server. Client and server both have abundant unused bandwidth, and the sysads have already eliminated switches, interface cards, etc. as the source of the slowdown. I'm looking at the script to see why file downloads are taking so long and going so much slower than if I were to simply manually download them with a browser on the same machine. The script says: $ctx = stream_context_create(array('http' = array('timeout' = 1200))); // 20 minutes per file $contents = file_get_contents($full_url, 0, $ctx); $fp = fopen('D:\\DocShare\\'.$filename, w); $bytes_written = fwrite($fp, $contents); fclose($fp); Yes, it's on Windows. Any idea whether my PHP code might be introducing a slowdown? The files range from 500K to 50MB. I often launch multiple instances of the script but it doesn't seem to help much. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Slow file download
On Tue, 2008-12-02 at 11:55 -0800, Brian Dunning wrote: I'm using a PHP cron job to constantly download files from a remote server. Client and server both have abundant unused bandwidth, and the sysads have already eliminated switches, interface cards, etc. as the source of the slowdown. I'm looking at the script to see why file downloads are taking so long and going so much slower than if I were to simply manually download them with a browser on the same machine. The script says: $ctx = stream_context_create(array('http' = array('timeout' = 1200))); // 20 minutes per file $contents = file_get_contents($full_url, 0, $ctx); $fp = fopen('D:\\DocShare\\'.$filename, w); $bytes_written = fwrite($fp, $contents); fclose($fp); Yes, it's on Windows. Any idea whether my PHP code might be introducing a slowdown? The files range from 500K to 50MB. I often launch multiple instances of the script but it doesn't seem to help much. Instead of using PHP for this, why not have a look at WGET for Windows. This is pretty much the standard way on *nix machines to grab files over the Internet using the command line, and if the Windows version is half as versatile as the Linux version, you'll find it has a lot of useful features too, like support for dropped connections, etc. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Slow file download
I'm open to something like that - we're in the middle of the holiday crunch and can't afford any downtime, so a significant change is out of the question. This is part of much larger and more involved scripting, so it would need to be a plug-n-play replacement and also be able to return information to the script calling it - bytes, success or failure. We're grabbing filenames and credentials out of MySQL, marking them in progress, attempting the download, and then updating the MySQL record with the results. On Dec 2, 2008, at 12:04 PM, Ashley Sheridan wrote: Instead of using PHP for this, why not have a look at WGET for Windows. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Slow file download
On Tue, 2008-12-02 at 12:14 -0800, Brian Dunning wrote: I'm open to something like that - we're in the middle of the holiday crunch and can't afford any downtime, so a significant change is out of the question. This is part of much larger and more involved scripting, so it would need to be a plug-n-play replacement and also be able to return information to the script calling it - bytes, success or failure. We're grabbing filenames and credentials out of MySQL, marking them in progress, attempting the download, and then updating the MySQL record with the results. On Dec 2, 2008, at 12:04 PM, Ashley Sheridan wrote: Instead of using PHP for this, why not have a look at WGET for Windows. Well you could always replace your CURL request with an exec() call to WGET, which will be able to return the HTTP request codes (200 for success, 404 for file not found, etc) and other information. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] why this code needs mysql.sock instead of mysqld.sock
Hi all ?php $link=mysql_connect('localhost','usrname','password'); if(!$link) echo fail; else echo success; mysql_close(); ? Thank you __ Connect with friends from any web browser - no download required. Try the new Yahoo! Canada Messenger for the Web BETA at http://ca.messenger..yahoo.com/webmessengerpromo.php
[PHP] Re: Slow file download
Brian Dunning wrote: I'm using a PHP cron job to constantly download files from a remote server. Client and server both have abundant unused bandwidth, and the sysads have already eliminated switches, interface cards, etc. as the source of the slowdown. I'm looking at the script to see why file downloads are taking so long and going so much slower than if I were to simply manually download them with a browser on the same machine. The script says: $ctx = stream_context_create(array('http' = array('timeout' = 1200))); // 20 minutes per file $contents = file_get_contents($full_url, 0, $ctx); $fp = fopen('D:\\DocShare\\'.$filename, w); $bytes_written = fwrite($fp, $contents); fclose($fp); Yes, it's on Windows. Any idea whether my PHP code might be introducing a slowdown? The files range from 500K to 50MB. I often launch multiple instances of the script but it doesn't seem to help much. what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] why this code needs mysql.sock instead of mysqld.sock
On 2 Dec 2008, at 20:15, ann kok wrote: ?php $link=mysql_connect('localhost','usrname','password'); if(!$link) echo fail; else echo success; mysql_close(); ? The location of the socket is compiled into the mysql lib. I believe it can be changed from php.ini - check the manual for details. If not then your easiest option is to create a symlink, or alternatively recompile the extension. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to type arguments
Richard Heyes wrote: I'm a french student, sorry for my mail : I want to know how can I type my functions' arguments ? It is heavy to do : function post($id) { $id=(int)$id; //... PHP is loosely typed so strictly (...) speaking, that would be fine. However, you're best off making sure that what you've been given is what you think it is. Ergo, what you've written, is what I would do. or tu put (int) before each use... Not necessary to put it there for each use, just the first. also worth noting that you can type-hint as long as the type you're hinting is an object and not a primitive: function post(SomeObject $obj) { // php will effectively throw a catchable fatal error if // $obj is not an instance of SomeObject } sadly you can't: function post(int $number) { // doesn't work for primitives // but then php has limited primitive types :( } so safest bet is as you mentioned but with at least some scalar checking first function post( $id ) { if( is_scalar($id) ) { return (int)$id; } // if you get here you're id is an object, resource // or array and can't be cast to scalar type. } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow file download
IIS, Windows PHP 5.2.6, and unfortunately the downloads are https. On Dec 2, 2008, at 12:32 PM, Nathan Rixham wrote: what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Slow file download
If the files are LARGE, file_get_contents is a Bad Idea (tm). You're trying to suck the whole thing into RAM, which it can't, which swaps and thrashes the bleep out of your RAM/swap space... Use fopen and an fread loop instead, and you'll probably see much better performance. Also, consider going old school and getting rid of the stream_context stuff. It's new and untested :-) You can use ini_set and the parameter or even fall back to fsockopen with a timeout. Note that those time-outs are for any given packet to arrive (or the socket to open) not the whole enchilada to download. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow file download
Brian Dunning wrote: IIS, Windows PHP 5.2.6, and unfortunately the downloads are https. On Dec 2, 2008, at 12:32 PM, Nathan Rixham wrote: what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? now I may be wrong but I'm rather sure that IIS has a bug where it doesn't close http connections properly, thus you're connection isn't closing until it times out (even though download finished ages ago). There's some notes on the php site about it but can't seem to spot them at the minute.. if memory serves me correctly lowering that timeout to something like 5 seconds will do the trick / or using a manual conenction like.. ?php $protocol = 'ssl://'; $server = 'yoursite.com'; $port = 443; // ssl port? $context = // your context here $rawHttpResponse = ''; $rawHttpRequest = GET /file.ext HTTP/1.1\r\nHost: . $server . \r\n; $rawHttpRequest .= Connection: Close\r\n\r\n'; if( $fp = stream_socket_client($protocol.$server.':'.$port], $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context) ) { fwrite($fp, $rawHttpRequest); stream_set_timeout($fp, 10); while (!feof($fp)) { $a = stream_get_meta_data($fp); if($a['timed_out']) { return false; //timed out } $rawHttpResponse .= fgets($fp, 2); } fclose($fp); } echo $rawHttpResponse . PHP_EOL; ? totally untested :p best of luck! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow file download
Nathan Rixham wrote: Brian Dunning wrote: IIS, Windows PHP 5.2.6, and unfortunately the downloads are https. On Dec 2, 2008, at 12:32 PM, Nathan Rixham wrote: what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? now I may be wrong but I'm rather sure that IIS has a bug where it doesn't close http connections properly, thus you're connection isn't closing until it times out (even though download finished ages ago). doesn't close HTTPS/SSL connections properly - key typo there! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow file download
On Tue, 2008-12-02 at 21:10 +, Nathan Rixham wrote: Brian Dunning wrote: IIS, Windows PHP 5.2.6, and unfortunately the downloads are https. On Dec 2, 2008, at 12:32 PM, Nathan Rixham wrote: what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? now I may be wrong but I'm rather sure that IIS has a bug where it doesn't close http connections properly, thus you're connection isn't closing until it times out (even though download finished ages ago). There's some notes on the php site about it but can't seem to spot them at the minute.. if memory serves me correctly lowering that timeout to something like 5 seconds will do the trick / or using a manual conenction like.. ?php $protocol = 'ssl://'; $server = 'yoursite.com'; $port = 443; // ssl port? $context = // your context here $rawHttpResponse = ''; $rawHttpRequest = GET /file.ext HTTP/1.1\r\nHost: . $server . \r\n; $rawHttpRequest .= Connection: Close\r\n\r\n'; if( $fp = stream_socket_client($protocol.$server.':'.$port], $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context) ) { fwrite($fp, $rawHttpRequest); stream_set_timeout($fp, 10); while (!feof($fp)) { $a = stream_get_meta_data($fp); if($a['timed_out']) { return false; //timed out } $rawHttpResponse .= fgets($fp, 2); } fclose($fp); } echo $rawHttpResponse . PHP_EOL; ? totally untested :p best of luck! I'm fair sure I hear of more bugs in IIS than I've ever heard of with Apache... *insert obvious troll disclaimer here* Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow file download
On Tue, 2008-12-02 at 21:13 +, Nathan Rixham wrote: Nathan Rixham wrote: Brian Dunning wrote: IIS, Windows PHP 5.2.6, and unfortunately the downloads are https. On Dec 2, 2008, at 12:32 PM, Nathan Rixham wrote: what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? now I may be wrong but I'm rather sure that IIS has a bug where it doesn't close http connections properly, thus you're connection isn't closing until it times out (even though download finished ages ago). doesn't close HTTPS/SSL connections properly - key typo there! I did hear something about that too, and also, not too sure, but think it might have been fixed in later versions of IIS, but, don't quote me on that! Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow file download
Ashley Sheridan wrote: On Tue, 2008-12-02 at 21:13 +, Nathan Rixham wrote: Nathan Rixham wrote: Brian Dunning wrote: IIS, Windows PHP 5.2.6, and unfortunately the downloads are https. On Dec 2, 2008, at 12:32 PM, Nathan Rixham wrote: what's the server running? iis/apache, win/linux version of php (as accurate as you can) oh and via http or https/ssl? now I may be wrong but I'm rather sure that IIS has a bug where it doesn't close http connections properly, thus you're connection isn't closing until it times out (even though download finished ages ago). doesn't close HTTPS/SSL connections properly - key typo there! I did hear something about that too, and also, not too sure, but think it might have been fixed in later versions of IIS, but, don't quote me on that! Ash www.ashleysheridan.co.uk they might have, either way I'm pretty sure this isn't a download speed but rather a connection not getting closed / eof not being detected type error so the timeout of 20mins+download time is being hit; hopefully a drop in timeout to 5/10 seconds will sort it. will be interested to hear if this is the cause or not! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple MySQL INSERT
ddg2sailor wrote: chris smith-9 wrote: ddg2sailor wrote: $row = mysql_fetch_array($res); $res = mysql_query(SELECT passhash, editsecret, status FROM users WHERE id = $id); $row = mysql_fetch_array($res); I hope this is a copy/paste error or are you running the same thing twice? I diddnt see that right away. In fact Im combining 2 pieces of code. The owner of this site dosent want to use a mail server and dosent want to do a manual confirm. So I added part of the confirm.php to the takesignup.php file mysql_query(UPDATE users SET status='confirmed', uploaded = $giveupload ); This updates *every* user to have a confirmed status. Probably not what you want. Add a WHERE id='X'; clause Believe me I agree with you... but this is how he wants it. It took me a while to realize that the new user cant call up the confirm.php without the mail with the link and the user name and secret word. It's still wrong regardless. User A signs up User B signs up User A clicks the confirm link User B does not, but is confirmed anyway. //send pm to new user { $msg = sqlesc(Hello and welcome to Cyber Drive In you have been given a 1gb head start to help your ratio. .we are a strict but fair site and our warning are based on the torrent ratio not the global just because you have a good ratio dont mean you can hit and run if you do hit and run your downloads maybe disabled even if your global ratio is fine..so enjoy our free 1gb gift rules are seed what you take or for 72 hours..plz read the rules and facts now you have joined our friendly community); $added = sqlesc(get_date_time()); $subject = sqlesc(Welcome to Cyber Drive In); mysql_query(INSERT INTO messages (sender, receiver, subject, msg, added) VALUES (0, $id, $subject, $msg, $added)); What is the sqlesc function? This is the way the code is when I got it. I think that this is how it reads from the array. I can see where a table might be more use here. Eh? I asked about what the sqlesc function does - it is not a native php function. You need quotes around your values: $sql = insert into table(f1, f2, f3) values (' . mysql_real_escape_string($value_1) . ', ' . mysql_real_escape_string($value_2) . '); Im guessing that the preceding line got a bit chopped in the sending at least it dosent look quite right as it is. If I cut and paste this back together I should be able to follow your convention. No, I was just too lazy to use your code and instead I gave an example. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] stream_socket_accept() on an SSL socket
I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stream_socket_accept() on an SSL socket
On Tue, 2008-12-02 at 23:48 +, Darren wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren I believe this shares something in common with another thread [Slow File Download]. Sockets on IIS using SSL has some problems. It's possible that the one you're suffering here is where IIS closes the connection prematurely. I have no idea how to solve this, but there are a number of answers to something similar on the PHP manual pages as far as I know. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stream_socket_accept() on an SSL socket
When you talk to an SSL server directly with sockets, I believe you need to implement the SSL protocol yourself, which would probably be overkill. There must be a PHP library which does or a native function. You should probably look at this page: http://nz.php.net/manual/en/wrappers.http.php and use fopen instead. On Wed, Dec 3, 2008 at 12:48 PM, Darren [EMAIL PROTECTED] wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
Re: [PHP] stream_socket_accept() on an SSL socket
When you talk to an SSL server directly with sockets, I believe you need to implement the SSL protocol yourself, which would probably be overkill. There must be a PHP library which does or a native function. You should probably look at this page: http://nz.php.net/manual/en/wrappers.http.php and use fopen instead. On Wed, Dec 3, 2008 at 12:57 PM, Ashley Sheridan [EMAIL PROTECTED]wrote: On Tue, 2008-12-02 at 23:48 +, Darren wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren I believe this shares something in common with another thread [Slow File Download]. Sockets on IIS using SSL has some problems. It's possible that the one you're suffering here is where IIS closes the connection prematurely. I have no idea how to solve this, but there are a number of answers to something similar on the PHP manual pages as far as I know. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
[PHP] Re: stream_socket_accept() on an SSL socket
Darren wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren you are calling ssl://server.com:port and not https://server.com ya? you've got openssl installed ya? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: stream_socket_accept() on an SSL socket
Darren wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren after more looking in to it the only thing I can see it possibly being is a broken ssl certificate on the webserver. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: stream_socket_accept() on an SSL socket
Nathan Rixham wrote: Darren wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren after more looking in to it the only thing I can see it possibly being is a broken ssl certificate on the webserver. last one, an interesting discussion back in 2005 on the openssl mailing lists, everything pointed to not authenticating - (using HTTP request when a SSL handshake is required) I'm going to drop this one now; best of luck! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Accessing the 'media' attribute in php
Is it possible to access the 'media' attribute from php, so (for example) you can tailor a page for printing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing the 'media' attribute in php
PHP is a server side language... On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote: Is it possible to access the 'media' attribute from php, so (for example) you can tailor a page for printing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
[PHP] Objects and Arrays Conversion
Hello All, I was stuck with this issue. So just felt the need to reach out to other strugglers. May be people might enjoy this: Here is the code for object to array and array to object conversion: function object_2_array($data) { if(is_array($data) || is_object($data)) { $result = array(); foreach ($data as $key = $value) { $result[$key] = object_2_array($value); } return $result; } return $data; } function array_2_object($array) { $object = new stdClass(); if (is_array($array) count($array) 0) { foreach ($array as $name=$value) { $name = strtolower(trim($name)); if (!empty($name)) { $object-$name = $value; } } } return $object; } have fun ! Thanks
Re: [PHP] stream_socket_accept() on an SSL socket
First thing I would check is ?php phpinfo();? and make sure you have OpenSSL compiled in. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing the 'media' attribute in php
I think you just want to have a CSS sheet for print media and be done with it. You could, in theory, add some kind of listener with JS, that would detect the 'media' attribute and then Ajax back to the server to do something, but that's an awful Rube Goldberg compared to just one more tag with a print stylesheet. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing the 'media' attribute in php
Oh? Unfortunately I have had great difficulty trying to find out how things really work, as all the books I have seen are recipe books, which tell you how to achieve particular results, but not what is going on behind the scenes. I had assumed that when you hit the 'print' button the browser sent a new request to the server, with a different set of parameters, but I gather from your reply that the browser issues the new (printer) page without reference to the server. Is this what actually happens? If so I fear I will have to work out how to achieve the results I want with CSS styles. It would have been far simpler if I could have done it in php. Thank you for your help. On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek) wrote: PHP is a server side language... On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote: Is it possible to access the 'media' attribute from php, so (for example) you can tailor a page for printing? -- 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] Accessing the 'media' attribute in php
You can do things on the client side with Javascript ;) Sorry, what was the result you are after? On Wed, Dec 3, 2008 at 3:22 PM, Clancy [EMAIL PROTECTED] wrote: Oh? Unfortunately I have had great difficulty trying to find out how things really work, as all the books I have seen are recipe books, which tell you how to achieve particular results, but not what is going on behind the scenes. I had assumed that when you hit the 'print' button the browser sent a new request to the server, with a different set of parameters, but I gather from your reply that the browser issues the new (printer) page without reference to the server. Is this what actually happens? If so I fear I will have to work out how to achieve the results I want with CSS styles. It would have been far simpler if I could have done it in php. Thank you for your help. On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek) wrote: PHP is a server side language... On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote: Is it possible to access the 'media' attribute from php, so (for example) you can tailor a page for printing? -- 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 -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
Re: [PHP] How to type arguments
On Tue, Dec 2, 2008 at 1:49 PM, Nathan Rixham [EMAIL PROTECTED] wrote: Richard Heyes wrote: I'm a french student, sorry for my mail : I want to know how can I type my functions' arguments ? It is heavy to do : function post($id) { $id=(int)$id; //... PHP is loosely typed so strictly (...) speaking, that would be fine. However, you're best off making sure that what you've been given is what you think it is. Ergo, what you've written, is what I would do. or tu put (int) before each use... Not necessary to put it there for each use, just the first. also worth noting that you can type-hint as long as the type you're hinting is an object and not a primitive: function post(SomeObject $obj) { // php will effectively throw a catchable fatal error if // $obj is not an instance of SomeObject } sadly you can't: function post(int $number) { // doesn't work for primitives // but then php has limited primitive types :( } however, type-hinting does support arrays function alterArr(array $a) { #.. } -nathan
Re: [PHP] Objects and Arrays Conversion
VamVan wrote: Hello All, I was stuck with this issue. So just felt the need to reach out to other strugglers. May be people might enjoy this: Here is the code for object to array and array to object conversion: function object_2_array($data) { if(is_array($data) || is_object($data)) { $result = array(); foreach ($data as $key = $value) { $result[$key] = object_2_array($value); } return $result; } return $data; } function array_2_object($array) { $object = new stdClass(); if (is_array($array) count($array) 0) { foreach ($array as $name=$value) { $name = strtolower(trim($name)); if (!empty($name)) { $object-$name = $value; } } } return $object; } have fun ! Thanks This page at the bottom describes your array_2_object function as a simple typecast: http://us2.php.net/manual/en/language.types.object.php $object = (object) $array; As for the object to array, the same thing applies: http://us2.php.net/manual/en/language.types.array.php $array = (array) $object; Not sure if these are PHP 5 only or not. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple MySQL INSERT
chris smith-9 wrote: ddg2sailor wrote: It's still wrong regardless. I dont run the system , However the code I didnt post checks to make sure the user name or email isnt already in use or in fact was in use but removed. Diddnt have to bother with that part , it works fine. User A signs up User B signs up User A clicks the confirm link User B does not, but is confirmed anyway. reads from the array. I can see where a table might be more use here. Eh? I asked about what the sqlesc function does - it is not a native php function. I wish I could tell you more... but this isnt my code. now it no doubt looks sloppy but It does work on anther system and sends the pm. My thinking is more along the lines of getting the value for $id comming out to = ' ' (null) instead of the Username... I havent been able yet to test the last edit of this code yet... It may even work. It runs on windows 2003 server sqlserver if this helps any. You need quotes around your values: $sql = insert into table(f1, f2, f3) values (' . mysql_real_escape_string($value_1) . ', ' . mysql_real_escape_string($value_2) . '); Im guessing that the preceding line got a bit chopped in the sending at least it dosent look quite right as it is. If I cut and paste this back together I should be able to follow your convention. No, I was just too lazy to use your code and instead I gave an example. I diddnt expect you to do my work for me :) But thanks for the tip. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- View this message in context: http://www.nabble.com/Multiple-MySQL-INSERT-tp20786333p20805879.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: stream_socket_accept() on an SSL socket
Darren wrote: I'm trying to connect to an SSL server, but I keep on getting these errors: - PHP Warning: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): Failed to enable crypto in C:\scripts\bouncer.php on line 273 PHP Warning: stream_socket_accept(): accept failed: The operation completed successfully. in C:\scripts\bouncer.php on line 273 - Line 273: while ($client = stream_socket_accept($srv_socket)) { Over the past few days of searching I've found a lot of people asking a similar thing but without any answers. I've tried the latest PHP snapshot too. Can anyone here give any insight to these errors?? Thanks for any help Darren Ok thanks guys. Turns out the SSL server was messing up, so PHP wasn't at fault here. (It's a bespoke server app, not apache). Thanks for your help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to type arguments
Date: Tue, 2 Dec 2008 19:39:53 -0700 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] CC: [EMAIL PROTECTED]; [EMAIL PROTECTED]; php-general@lists.php.net Subject: Re: [PHP] How to type arguments On Tue, Dec 2, 2008 at 1:49 PM, Nathan Rixham [EMAIL PROTECTED] wrote: Richard Heyes wrote: I'm a french student, sorry for my mail : I want to know how can I type my functions' arguments ? It is heavy to do : function post($id) { $id=(int)$id; //... PHP is loosely typed so strictly (...) speaking, that would be fine. However, you're best off making sure that what you've been given is what you think it is. Ergo, what you've written, is what I would do. or tu put (int) before each use...Not necessary to put it there for each use, just the first.also worth noting that you can type-hint as long as the type you're hinting is an object and not a primitive: function post(SomeObject $obj) { // php will effectively throw a catchable fatal error if // $obj is not an instance of SomeObject } sadly you can't: function post(int $number) { // doesn't work for primitives // but then php has limited primitive types :( } however, type-hinting does support arrays function alterArr(array $a) { #.. } -nathan Ok, thank you, type-hint as long as the type you're hinting is an object and not a primitive: yes, but it is heavyer than doint $v=(int)$v; It is all right thank you _ Email envoyé avec Windows Live Hotmail. Dites adieux aux spam et virus, passez à Hotmail ! C'est gratuit ! http://www.windowslive.fr/hotmail/default.asp
[PHP] SELECT into array of arrays
Dear all, I have a MySQL table 'test' which includes two columns: 'study' and 'symbol': study symbol a2008 A a2008 B a2008 C a2008 D b2005 A b2005 B b2005 E Using POST variable I passed 'study' values into $myArray: // $myArray is variable length; used only two values in example $myArray = array(a2008,b2005); Then I try to produce the following structure (array of arrays): $combinedArray = array(array('A','B','C','D'),array('A','B','E')); Below is my php script. In the present solution the $combinedArray includes only 'symbol' values for last iteration (where $myArray = b2005). How should I proceed? Thanks in advance for any suggestions. Best, Andrej $combinedArray = array(); for ($i=0;$icount($myArray);$i++) { $sql = SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]'); $result = mysql_query($sql); if(mysql_num_rows($result) 0) { while ($myrow = mysql_fetch_array($result)) { $combinedArray[] = $myrow['symbol']; } } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing the 'media' attribute in php
Clancy wrote: Oh? Unfortunately I have had great difficulty trying to find out how things really work, as all the books I have seen are recipe books, which tell you how to achieve particular results, but not what is going on behind the scenes. I had assumed that when you hit the 'print' button the browser sent a new request to the server, with a different set of parameters, but I gather from your reply that the browser issues the new (printer) page without reference to the server. Is this what actually happens? If so I fear I will have to work out how to achieve the results I want with CSS styles. It would have been far simpler if I could have done it in php. Thank you for your help. On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek) wrote: PHP is a server side language... On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote: Is it possible to access the 'media' attribute from php, so (for example) you can tailor a page for printing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Rule #1 on this list: don't top post. That is how it works indeed, you request the page, the server runs the php script, collects the output and sends it to the browser. You view the page in the browser, press print, the browser sends the page data to the printer spooler which sends it to the printer. No PHP involved after it was sent from the server back to the browser. You basically have 2 options now: 1. change the looks trough a different stylesheet (the pretty option) 2. add a print button/link on your page which, when clicked, will redirect to a new page in print format. Then use the javascript print function to call up the browser's print dialog. As for books, most PHP books aren't recipe books, so you've been looking at the wrong ones :) I can recommend O'Reilly's books, they're pretty good. Especially Programming PHP [1]. But that's just my general liking of those books ;) - Tul [1] http://oreilly.com/catalog/9780596006815/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing the 'media' attribute in php
On Wed, 3 Dec 2008 15:28:17 +1300, [EMAIL PROTECTED] (German Geek) wrote: You can do things on the client side with Javascript ;) Sorry, what was the result you are after? I have enough trouble getting my rather ancient brain around PHP, and was hoping that I could avoid getting involved with JavaScript. However it seems that it, or CSS, are the only possibilities for this case. Bother! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php