[PHP] Re: If statement question
Alex Major wrote: Hi list. Basically, I'm still learning new things about php and I was wondering if things inside an if statement get 'looked at' by a script if the condition is false. For example, would this mysql query get executed if $number = 0 ? If ($number == 1) { mysql_query($blah) } I know that's not really valid php, but hope it gets my point across. I was just wondering from an optimisation perspective, as I don't want sql commands being executed when they don't need to be (unnecessary server usage). Thanks in advance for your responses. Alex. Stuff inside an if statement will be compiled (So it has to be free of syntax errors and such), but it won't be executed unless the condition is true. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP 5, Windows, and MySQL
Beauford wrote: Aside from my previous gd problems, here's another problem. It appears that PHP5 (for Windows anyways) does not support MySQL (which in itself is riduculous), but here's my problem. I have a script I just downloaded that works perfectly on Linux/Apche/MySQL/PHP5, but when I run it on Windows 2000 with PHP 4.4 I get a page full of errors. Lets forget about the errors, does anyone have any idea how to get PHP5 and MySQL to work on Windows. I have already tried 100 different variations of things from information I found searching out this problem, but maybe someone has a new idea. If it were me I'd just run this site on Linux, but this is for a friend who wants to use IIS. If your curious the errors are below. Thanks B Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in G:\Websites\Webtest\caalogin\include\database.php on line 207 Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in G:\Websites\Webtest\caalogin\include\database.php on line 218 Warning: session_start(): Cannot send session cookie - headers already sent by (output started at G:\Websites\Webtest\caalogin\include\database.php:207) in G:\Websites\Webtest\caalogin\include\session.php on line 46 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at G:\Websites\Webtest\caalogin\include\database.php:207) in G:\Websites\Webtest\caalogin\include\session.php on line 46 Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in G:\Websites\Webtest\caalogin\include\database.php on line 218 Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in G:\Websites\Webtest\caalogin\include\database.php on line 207 Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in G:\Websites\Webtest\caalogin\include\database.php on line 218 While it probably has nothing to do with your errors, mysql_numrows() is a deprecated alias to mysql_num_rows(), which should be used instead. As for your problem, have you checked the PHP docs on how to install MySQL support for PHP5 on Windows? http://www.php.net/manual/en/ref.mysql.php Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Strip outgoing whitespace in html
Christopher J. Bottaro wrote: Opps, we just found mod_tidy. :) Christopher J. Bottaro wrote: I'm wondering if there's a convenient way to globally add a final step for apache w/php that will remove unnecessary whitespace from text/html before it gets sent to the client. Some sort of global config like thing would be ideal. For what it's worth we're using the smarty template engine too, but I suppose I'd prefer a solution that doesn't depend on it. Maybe something like another AddHandler? Also consider mod_gzip (or mod_deflate), they will get you a LOT more space savings than mod_tidy will, and should still work with every browser made in the past decade or so ;) From what I've seen, the CPU load induced by compression is quite small, at least on my test site that had about a quarter million pageviews (hence compressed documents) per day. Definitely worth the enormous bandwidth savings! Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mail() returns false but e-mail is sent ?
Leonidas Safran wrote: Hello, Show us the full context of the code. The example you give us will work fine but that doesn't tell us what's really going on in your code. Here is the function I use to allow french special characters in the subject line (copied from german university tutorial http://www-cgi.uni-regensburg.de/~mim09509/PHP/list.phtml//www-cgi/home/mim09509/public_html/PHP/mail-quote.phtml?datei=%2Fwww-cgi%2Fhome%2Fmim09509%2Fpublic_html%2FPHP%2Fmail-quote.phtml%2Crfc822-syntax.txt): function quote_printable($text, $max=75){ /* $text ist ein String (mit neue Zeilen drin), $max ist die max. Zielenlaenge Ergebnis ist auch ein String, der nach rfc1521 als Content-Transfer-Encoding: quoted-printable verschluesselt ist.*/ $t = explode("\n", ($text=str_replace("\r", "", $text))); for ($i = 0; $i < sizeof($t); $i++){ $t1 = ""; for ($j = 0; $j < strlen($t[$i]); $j++){ $c = ord($t[$i][$j]); if ( $c < 0x20 || $c > 0x7e || $c == ord("=")) $t1 .= sprintf("=%02X", $c); else $t1 .= chr($c); } while (strlen($t1) > $max+ 1){ $tt[] = substr($t1, 0, $max)."="; $t1 = substr($t1, $max); } $tt[] = $t1; } return join("\r\n", $tt); } function qp_header($text){ $quote = quote_printable($text, 255); if ($quote != $text) $quote = str_replace(" ", "_","=?ISO-8859-1?Q?" . $quote . "?="); return $quote; } So, before I enter: $sent = mail($destination, $subject, $content, $headers); I have: $subject = qp_header($subject); That's all... As said before, the e-mail is sent, but the mail() function returns false ! Thank you for your help LS And what code is checking the return value of mail()? Trust me, we've all made stupid mistakes, they're nasty little buggers that can sneak in and ruin anyone's day; best to include it since it might be relevant. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: rss feeds from db
Dan McCullough wrote: I'm having some problems where some undefined entity are getting in, these entities are usually html entities. sad thing is"¦bringing in these large chains is putting the xml doc points to the & in ";¦" as the problem. what do I need to do to get this stuff cleaned up? Not quite. That first ; is part of the previous entity, """. You want to do a search/replace for "¦" And ¦ is a perfectly valid entity. It represents a pipe character ("¦"), so it is NOT an undefined entity. If you really don't want it there, do a search-replace for "¦" and either replace it with an alternative character (perhaps a ¦ directly), or an empty string to remove it entirely. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Equivelant to mysql_fetch_row for normal array
Dave M G wrote: Jochem, Tul, Nicolas, Thank you for your help. I must be doing something wrong with how my array is generated. It's actually just a MySQL result, but because it is returned from a function, it does not seem to behave as I would expect a MySQL result should. I'm trying the foreach function and key values, but I'm clearly not quite getting it right. Perhaps there is something about my code which is wrong. So I'm presenting what I hope is all the relevant parts: public function getData($row, $type, $column, $match) { $query = "SELECT " . $row . " FROM " . $type . " WHERE " .$column . " = " . $match; echo "query = " . $query . ""; $result = mysql_query($query); $data = mysql_fetch_array($result); return $data; } foreach($elements as $key => $val){ echo "val[type] = " . $val[type] . ""; echo "val[resource] = " . $val[resource] . ""; } What I'm getting back doesn't make sense. I can't go all the way into my code, but $val[type] should be a string value containing the words "Article" or "Text". But instead, I get: val[type] = 2 val[resource] = 2 Am I still not doing the foreach correctly? -- Dave M G First of all, you're using invalid syntax. You should have $val['type'] rather than $val[type]. Second of all, mysql_fetch_array returns only a single row, $elements. This is an array. From there, you're asking foreach to return each element of the array as $val. So each time through the foreach loop, $val will have the contents of that element. The element isn't an array, it's a scalar. So you're taking a scalar and trying to treat it like an array. You really should read the manual, the pages for all these functions describe EXACTLY what they do. Remember that mysql_fetch_array returns an associative array. You can refer to the SQL fields by their names. So if your select query was "SELECT foo, bar FROM mytable", after doing a mysql_fetch_array you could do this: echo $row['foo'] . ""; echo $row['bar'] . ""; Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [MailServer Notification]Content Filtering Notification
[EMAIL PROTECTED] wrote: Content Filter @ AIT Batam has detect violation of the PROFANITY rule, and Quarantine entire message has been taken on 21-Jun-2006 22:49:25. Message details: Server:BTMAIL Sender: [EMAIL PROTECTED]; Recipient:[EMAIL PROTECTED];php-general@lists.php.net; Subject:Re: [PHP] helping people... OK, this is just amusing. Somebody over at "AIT Batam" is obviously an idiot. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: comparing a string
Rafael wrote: (inline) Adam Zey wrote: Rafael wrote: A single "=" it's an assignment, not a comparison; and though it sometimes work, you shouldn't compare strings with "==", but using string functions, such as strcmp()... or similar_text(), etc. This is PHP, not C. Operators such as == support strings for a reason, people should use them as such. You shouldn't rely on what other languages do, but the one you're working with; PHP has no explicit data-types and manages strings as PERL does. Just as you say there's a reason why "==" supports strings, there's also a reason (or more) for strcmp() to exists --it's just safer to use strcmp() instead of "==", e.g: 24 == "24/7" Safer, yes. And it'd be even better to do 24 === "24/7", in which case you don't need a function call, it's probably faster (I'd imagine that comparing equality is faster than finding out HOW close it is like strcmp does), and as I mentioned, easier to read. If you need to ensure type, (so that 0 == "foo" doesn't return true), then you can use ===. Using a function call that does more than you need when there is an operator to achieve the same goal is bad advice. I think you haven't encounter a "special case" to make you understand "==" does NOT have the same behaviour as strcmp() It's just like the (stranger) case of the loop for ( $c = 'a'; $c <= 'z'; $c ++ ) echo $c; I didn't say that it had the same behaviour, only the same goal; finding out if two strings are equal. strcmp does MORE than that, it also finds out how CLOSE they are. You almost never need that information, in which case you're wasting processing time with a function call that does something that you don't need. Come on, face it, how many times have done anything with strcmp's return value OTHER than checking that it's zero? I bet the cases are fairly rare. Not to mention the fact that it leads to harder to read code. Which of these has a more readily apparent meaning? if ( strcmp($foo,$bar) == 0 ) if ( $foo === $bar ) That might be true, either way you need to know the language to understand what the first line does and that the second isn't a typo. === is a basic operator. One has to assume that somebody writing code is at least familiar with the basic operators. If not, well, asking them to know what the function strcmp does and what it means when it returns zero is just as onerous. If not more so. And again, strcmp wastes time calculating information we don't NEED. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] helping people...
Rob W. wrote: No that wasnt a ddos threat you idiot, i dont play them games. And when you keep sending spam is when it starts to piss people off. - Original Message - From: "Jochem Maas" <[EMAIL PROTECTED]> To: "[php] PHP General List" Sent: Wednesday, June 21, 2006 1:55 AM Subject: [PHP] helping people... helping some people will get you no end of trouble. and so it seems as though I'm going to be DoSSed by someone who uses Outlook Express as their mail client. I guess it's monday somewhere. Original Message From: - Wed Jun 21 01:47:39 2006 X-Mozilla-Status: 0001 X-Mozilla-Status2: Return-Path: <[EMAIL PROTECTED]> X-Original-To: [EMAIL PROTECTED] Delivered-To: [EMAIL PROTECTED] Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id EECE119EB29 for <[EMAIL PROTECTED]>; Wed, 21 Jun 2006 01:47:00 +0200 (CEST) Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01046-16 for <[EMAIL PROTECTED]>; Wed, 21 Jun 2006 01:46:57 +0200 (CEST) Received: from mail.fiberuplink.com (newyork.hardlink.com [140.186.181.161]) by mx1.moulin.nl (Postfix) with SMTP id A4FBB19EAF0 for <[EMAIL PROTECTED]>; Wed, 21 Jun 2006 01:46:56 +0200 (CEST) Received: (qmail 86220 invoked by uid 1013); 20 Jun 2006 23:46:57 - Received: from 208.107.101.135 by eclipse.fiberuplink.com (envelope-from <[EMAIL PROTECTED]>, uid 1011) with qmail-scanner-1.25-st-qms (clamdscan: 0.87/1102. spamassassin: 3.0.1. perlscan: 1.25-st-qms. Clear:RC:0(208.107.101.135):SA:0(-1.9/4.5):. Processed in 3.519899 secs); 20 Jun 2006 23:46:57 - X-Antivirus-INetKing-Mail-From: [EMAIL PROTECTED] via eclipse.fiberuplink.com X-Antivirus-INetKing: 1.25-st-qms (Clear:RC:0(208.107.101.135):SA:0(-1.9/4.5):. Processed in 3.519899 secs Process 86212) Received: from host-135-101-107-208.midco.net (HELO rob) ([EMAIL PROTECTED]@208.107.101.135) by mail.fiberuplink.com with SMTP; 20 Jun 2006 23:46:52 - Message-ID: <[EMAIL PROTECTED]> From: Rob W. <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Subject: Date: Tue, 20 Jun 2006 19:18:02 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_NextPart_000_003E_01C6949E.403D9880" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Virus-Scanned: amavisd-new at moulin.nl Unless you wanna keep your server up, I suggest you quit sending me shit. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If somebody is sending you spam from one address over and over, USE A FILTER TO BLOCK THEM. Don't be an asshole and threaten to DDoS/attack their server. At that point you've just gone from being a victim to the bad guy, and you don't get any sympathy from people on this list. So, screw off. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
Ray Hauge wrote: On Tuesday 20 June 2006 15:14, Albert Padley wrote: I have a regular for loop - for($i=1; $i<100; $i++) Within the loop I need to create variables named: $p1name; $p2name; $p3name; etc. The integer portion of each variable name needs to be the value of $i. I can't seem to get my syntax correct? Can someone point me in the right direction? Thanks. Albert Padley If you really want to keep the p?name syntax, I would suggest throwing them in an array with keys. $arr["p1name"] $arr["p2name"] Then that way you can create the key dynamically: $arr["p".$i."name"] Not pretty, but it works. Thanks, I haven't checked this, but couldn't you reference it as $arr["p$iname"] ? Is there a reason why variable expansion wouldn't work in this circumstance? If it does, you could make it easier to read by doing $arr["p{$i}name"] even though the {} aren't required. It'd be a lot easier to read than concatenations :) Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: shutting down a web app for maintenance
Shutting down Apache would do the trick ;) But if you're in a shared hosting environment that may not be possible. As for sessions, it depends how you track them. You can't kill all PHP sessions in one go, but you could have your web app nuke the sessions of users after they come back after maintenance. Something like first_login_after_maint in the database, that if set to true, mandates that any existing session data be destroyed before continuing. I assume that the reason you want to kill session data is because the data and how it is used would be different after the maintenance? Because otherwise, if you've denied all access to ANY of your webapp's php scripts, it shouldn't matter if the user has session data. If you physically move the web app's PHP scripts (Or set up a redirect, etc), they can't do anything with it. Regards, Adam Ben Liu wrote: Thanks Adam, What you say makes good sense to me. Is there some method to run a script that kills all active sessions on a host? It could become part of the maintenance script I suppose: 1) Kill all active sessions 2) Put up generic maintenance screen 3) Deny further login attempts - Ben On 6/20/06, Adam Zey <[EMAIL PROTECTED]> wrote: Ben Liu wrote: > Hello All, > > I'm not sure this is strictly a PHP related question or perhaps a > server admin question as well. What do you do when you are trying to > shutdown a web application for maintenance (like a membership or > registration-required system)? I understand that you can temporarily > upload or activate a holding page that prevents users from continuing > to login/use the system, but how can you insure that there are no > ongoing sessions or users still in the process of doing something? > What's the best method for handling this, especially if you don't have > full control of the server hosting the web app? > > Thanks for any advice, > > - Ben I normally do what you say; activate a holding page. The question comes to mind, does it really matter if a user's session is interrupted? Is the web application dealing with data that is critical enough (or non-critical data in a possibly destructive manner) that you can't just cut them off for a while? You have to consider that users could just as easily be cut off by a server crash, packetloss/network issues (on your end OR theirs, or anywhere in between), or just might hit the stop button while a script is running (Which, IIRC, ordinarily terminates the script the next time you try to send something). If your web app works in a way such that you can't just pull the plug and everything is fine, you're running some pretty big risks that your app will get into unrecoverable states from everyday issues. If you wanted to get fancy, you could code your system to prevent new logins, expire normal logins much faster (Say, after 15 minutes instead of hours or days), and then wait for all users to be logged out before continuing. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: shutting down a web app for maintenance
Ben Liu wrote: Hello All, I'm not sure this is strictly a PHP related question or perhaps a server admin question as well. What do you do when you are trying to shutdown a web application for maintenance (like a membership or registration-required system)? I understand that you can temporarily upload or activate a holding page that prevents users from continuing to login/use the system, but how can you insure that there are no ongoing sessions or users still in the process of doing something? What's the best method for handling this, especially if you don't have full control of the server hosting the web app? Thanks for any advice, - Ben I normally do what you say; activate a holding page. The question comes to mind, does it really matter if a user's session is interrupted? Is the web application dealing with data that is critical enough (or non-critical data in a possibly destructive manner) that you can't just cut them off for a while? You have to consider that users could just as easily be cut off by a server crash, packetloss/network issues (on your end OR theirs, or anywhere in between), or just might hit the stop button while a script is running (Which, IIRC, ordinarily terminates the script the next time you try to send something). If your web app works in a way such that you can't just pull the plug and everything is fine, you're running some pretty big risks that your app will get into unrecoverable states from everyday issues. If you wanted to get fancy, you could code your system to prevent new logins, expire normal logins much faster (Say, after 15 minutes instead of hours or days), and then wait for all users to be logged out before continuing. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Paging Help
Andrei wrote: Since you query all enregs from table why not query all first and the do mysql_data_seek on result? // Query to show $query_rsData = "SELECT * FROM {table} ORDER BY {Whatever field}"; $rsData = mysql_query($query_rsData, $DB_CONECTION); $num_total_records = mysql_num_rows( $rsData ); $total_pag = ceil($num_total_records / $NUM_RECORDS); if( $pag < 1 ) $pag = 1; elseif( $pag > $total_pag ) $pag = $total_pag; $start_enreg = ($pag-1) * $NUM_RECORDS; @mysql_data_seek( $rsData, $start_enreg ); while( ($result = mysql_fetch_object( $rsData )) ) { // display data... } Querying all data in the first place is a waste, and the practice of seeking through a dataset seems silly when MySQL has the "LIMIT" feature to specify which data you want to return. I believe the proper way to do this would be something like this (Simplified example, of course): $query = "SELECT SQL_CALC_FOUND_FOWS * FROM foo LIMIT 30, 10"; $result = mysql_query($query); $query = "SELECT found_rows()"; $num_rows = mysql_result(mysql_query($query), 0); That should be much faster than the methods used by either of you guys. As a comment, it would have been better to do "SELECT COUNT(*) FROM foo" and reading the result rather than doing "SELECT * FROM foo" and then mysql_num_rows(). Don't ask MySQL to collect data if you're not going to use it! That actually applies to why you shouldn't use mysql_data_seek either. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: comparing a string
Rafael wrote: A single "=" it's an assignment, not a comparison; and though it sometimes work, you shouldn't compare strings with "==", but using string functions, such as strcmp()... or similar_text(), etc. This is PHP, not C. Operators such as == support strings for a reason, people should use them as such. If you need to ensure type, (so that 0 == "foo" doesn't return true), then you can use ===. Using a function call that does more than you need when there is an operator to achieve the same goal is bad advice. Not to mention the fact that it leads to harder to read code. Which of these has a more readily apparent meaning? if ( strcmp($foo,$bar) == 0 ) if ( $foo === $bar ) Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: running conditions while looping through arrays....
IG wrote: I want to run filters on an pop3 inbox. I have the following arrays which I'll get from the database- $subject $email $body $subject_like $email_like $body_like I then go through each email in turn using this loop- $popy = "{".$pop3."/pop3:110}INBOX"; $mailbox = imap_open($popy, $un, $pw); $num_messages = imap_num_msg($mailbox); if ($num_messages <= $no_srch) {$rrt = 0;} else {$rrt = $num_messages-$no_srch;} for($i=$num_messages; $i>($rrt); $i--) { What I want to do is to check if the email address or subject or body of each email is exactly like any of the details stored in the arrays $subject, $email, $body and to check if the email address or subject or body contains a word or phrase from the arrays $subject_like, $email_like, $body_like. For example- $subject[0] = "SPAM"; $email[0]= ""; $body[0] = ""; $subject_like[0] = ""; $email_like[0] = ""; $body_like[0] = ""; // If the subject of the email = "spam" $subject[1] = ""; $email[1]= "[EMAIL PROTECTED]"; $body[1] = ""; $subject_like[1] = ""; $email_like[1] = ""; $body_like[1] = ""; // if the email address of the email = "[EMAIL PROTECTED]" $subject[2] = ""; $email[2]= ""; $body[2] = "spam body text"; $subject_like[2] = ""; $email_like[2] = ""; $body_like[2] = ""; // if the body of the email = "spam body text" $subject[3] = "SPAM"; $email[3]= "[EMAIL PROTECTED]"; $body[3] = ""; $subject_like[3] = ""; $email_like[3] = ""; $body_like[3] = ""; // if the subject of the email = "SPAM" AND the email address = "[EMAIL PROTECTED]" $subject[4] = "SPAM"; $email[4]= ""; $body[4] = ""; $subject_like[4] = ""; $email_like[4] = ""; $body_like[4] = "spam text"; // if the subject of the email = "SPAM" AND the body contains "spam text" If any of the above conditions are met then the email message is then stored in a database and deleted of the POP3 server. Is there a quick way of doing the above? The only way I can think of is by looping through each array for every email. This is really really slow. I'd be grateful for some help here Ian Unless I'm mistaken, for ( $x = 0; $x < count($subject); $x++ ) { if ( $subject[$x] == "SPAM" || $email[$x] == "[EMAIL PROTECTED]" || $body[$x] == "spam body text") { # Mail is spam! Do something. } } Or something like that. I'm not exactly sure what your criteria are. What I'm doing above is looping through the mail messages one at a time, and checking all aspects of that email in each loop iteration. If you're doing complex analysis on each message, then that is probably the fastest way. If you're simply searching for things, you could always do array searches. So, search through $email with array_search or perhaps array_intersect. Then you don't need to loop at all. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Replacing text with criteria
Jeff Lewis wrote: I have been working on a script to parse a CSV file and in the process I clean out a lot of the garbage not needed but I am a bit stumped on one aspect of this file. It's a list of over 3000 contacts and I'm trying to mask a lot of the information with *. So as I loop through this list I am checking the array elements as if I find a phone number (555) 555-1212 (I was searching for the (555)) I want to convert it to (555) ***- For fields not containing an area code, I wanted any text to be replaced by an * except for the first and last letter in the element. I'm stumped and was hoping that this may be something horribly simple I'm overlooking that someone can point out for me. This will take a string and replace everything but the first and last characters. $string = substr_replace($string, str_repeat("*", strlen($string)-2), 1, -1); It seems like you want to do it based on letters though, so "Hello, World!" would become "H**d!", not ""H***!" (which the above would do). To do this you'll need to get the positions of the first and last letters in the string and use those instead of 1 and -1. Off the top of my head I don't recall any functions that can do this, strpos and strrpos don't take arrays as parameters. You may be better off with regular expressions for the actual replacement unless somebody knows of a function to get the positions. BTW, in functions like substr, specifying "-1" for length means keep going until the second to last character. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to run one php app from another?
tedd wrote: Hi gang: This seems like so obvious a question, I am reluctant to ask. In any event, I simply want my php application to run another, like so: switch (option) { case a: run a.php; exit; break; case b: run b.php; exit; break; case c: run c.php; exit; break; } I know that from within an application I can run another php application via a user click (.e., button), or from javascript event (onclick), or even from cron. But, what if you want to run another application from the results of a calculation inside your main application without a "user trigger". How do you do that? I have tried header("Location: http://www.example.com/";); ob_start(), ob_flush() and such, but I can't get anything to work. Is there a way? Thanks. tedd See the documentation for include(), include_once(), require(), and require_once(). Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: serving video files with php
Andras Kende wrote: Hello, Is there any drawback servings video files through php downloader script on high load site? Or just straight link to the videos are more efficient? Thank you, Andras Kende http://www.kende.com Yes, there is. The PHP downloader script will have to stay resident in memory for the entire duration of the download, plus it's going to take up more CPU power than apache's own functionality (even if only marginally). If you intend to have multiple simultaneous downloads for this, it's going to be a rather large resource drain compared to just letting Apache handle the download itself. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: trapping fatal errors...?
Christopher J. Bottaro wrote: Hello, How can I trap a fatal error (like calling a non existant method, requiring a non existant file, etc) and go to a user defined error handler? I tried set_error_handler(), but it seems to skip over the errors I care about. Thanks for the help. It is always safer to handle errors before they happen by checking that you're in a good state before you try to do something. For example, nonexistent files can be handled by file_exists(). Undefined functions can be checked with function_exists(). Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to tell if a socket is connected
Michael W. wrote: Hello, Can any of you tell me how to tell whether a socket (from fsockopen()) is connected or not? Specifically, whether the remote server has closed the connection? Stream_get_meta_data() does not do it; in my tests, its output does not change even when the server closes the stream. Thank you, Michael W. If it is a network socket, and the remote end disconnected unexpectedly (which you MUST assume is a possibility), then the only way to find out if the connection is still open is by SENDING data. Just trying to read it won't cut it. The thing to understand is that when a remote client/server disconnects, it normally safely closes the socket and notifies you. But an abrupt disconnection (Something crashes, loses connectivity, etc) sends no such thing. The only way to find out that a connection is really lost is to write some data and see if it times out or not. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server sending notifications to clients
kartikay malhotra wrote: Dear Adam, "You can do it without polling. I've seen web applications that open a neverending GET request in order to get updates to the browser instantaneously. Regards, Adam." Kindly elaborate on "neverending GET request". Shall I call the script from within itself? Regards KM On 6/8/06, Adam Zey <[EMAIL PROTECTED]> wrote: Barry wrote: > Angelo Zanetti schrieb: >> kartikay malhotra wrote: >>> Hi All, >>> >>> Is there a way for the server to notify the client about an event, >>> provided >>> the client was online in the past X minutes? >>> >>> To elaborate: >>> >>> A client comes online. A script PHP executes (serves the client), and >>> terminates. Now if a new event occurs, how can the server notify the >>> client >>> about that event? >>> >>> Thanks >>> KM >>> >> >> >> what kind of event?? > > Server bored and fooling around with the neighbor servers hardware :P > > But Ajax would be the best method using. > > Anyway else isn't possible (well refreshing would be one way) > > But since you don't want php files to execute forever you will have to > stick to AJAX. > You can do it without polling. I've seen web applications that open a neverending GET request in order to get updates to the browser instantaneously. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I refer to having the javascript code open a GET request that never ends and streaming data from the server back to the client. The server-side PHP process, which stays running, streams back data whenever it becomes available. This of course uses a lot of memory. I have never done this myself in a web application, so I suggest you google for examples of other people who have actually implemented it. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server sending notifications to clients
Barry wrote: Angelo Zanetti schrieb: kartikay malhotra wrote: Hi All, Is there a way for the server to notify the client about an event, provided the client was online in the past X minutes? To elaborate: A client comes online. A script PHP executes (serves the client), and terminates. Now if a new event occurs, how can the server notify the client about that event? Thanks KM what kind of event?? Server bored and fooling around with the neighbor servers hardware :P But Ajax would be the best method using. Anyway else isn't possible (well refreshing would be one way) But since you don't want php files to execute forever you will have to stick to AJAX. You can do it without polling. I've seen web applications that open a neverending GET request in order to get updates to the browser instantaneously. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: running php method in the background
Nic Appleby wrote: Hi there I have a php web script which communicates with a server using sockets. There is a method in which the client listens for messages from the server, and this blocks the client. I need a way to 'fork' a process or to get this method to run in the background so that i can process user input while not interrupting the protocol. I have searched all over the web with no luck, can anyone point me in the right direction? thanks nic All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm You may be able to do this with asynchronous sockets without forking. With them, you can poll the sockets for new data in between processing user input requests. It might not be quite as fast, but it'll be a lot easier to work with. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: file( ) function
Mayank Maheshwary wrote: Hi, I am facing some trouble with the file( ) function. I understand that it returns the contents of the file in an array. Also, I am able to print the lines using the echo function. However, whenever I try to compare the contents of an array using strcmp, or ==, the page simply keeps 'loading', instead of printing results. The following is the code that I try: $name = $_POST["filename"]; $lines = file($name); $i = 0; $len = sizeof($lines); //echo $i; while($i < $len) { //echo $lines[$i]; $temp = $lines[$i]; $temp = trim($temp); //echo $temp; if($temp1 == '--') { echo $i; return $i; } else $i++; } I think that the way the lines of the file are stored in the array may be the problem, but I do not know what I am supposed to change. Any help would be appreciated. Thanks. MM. You might want to reexamine the need for your code. It appears that all your code does is searches through a file for a certain line. Do you need to do this manually? array_search() will replace your entire for loop with a single function call, and it'll almost certainly be faster to boot. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] When is "z" != "z" ?
tedd wrote: for I can't get it to stop when it passes "z" -- which I think it should. But, people have posted code solutions for you to do exactly what you want. So have I. Here it is again: foreach (range('a', 'z') as $char) { echo $char; } I don't mean to sound harsh, but why are you still complaining about it? You've been shown to do exactly what you want, why is it still a problem? Heck, if you still really want to do < and > with strings, you can easily write your own functions to compare two strings using your own requirements. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot read variables
William Stokes wrote: Yess! Wrong ini file... There seems to be 3 of them on the same PC for some reason? -W "David Otton" <[EMAIL PROTECTED]> kirjoitti viestissä:[EMAIL PROTECTED] On Tue, 6 Jun 2006 10:36:12 +0300, you wrote: I just set up a test box for PHP/MySQL on a WinXP box and now I'm having trouble with variables passed to browser from a link. For example I have a link that outputs this: http://localhost/index.php?team=CF10b. Now the CF10b cannot be user in the code like it should. I turned to Register Globals on in the php.ini but that didn't help. Any ideas? Most likely you didn't turn RG on (typo? wrong php.ini?), or didn't restart. Try: print_r ($_POST); print_r ($_GET); print_r ($_REQUEST); to see if your variable is being passed. If it is, PHP isn't set up as you want it. If it isn't, there's something more fundamental wrong. -- http://www.otton.org/ Turn off register globals. Now. It is a HUGE security hole. You do NOT need it turned on to use $_GET or the other superglobals, and there is in fact no reason at all to EVER turn it on. The only conceivable reason that someone would enable it is for an old badly written script, and in that case one has to question why they are running an old badly written script :) Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] If value is odd or not
Richard Lynch wrote: On Fri, June 2, 2006 8:32 am, Jonas Rosling wrote: is there any easy why to check if a value is odd or not? $parity = $variable % 2 ? 'even' : 'odd'; echo "$variable is $parity\n"; Let's make it even more compact and confusing :) echo "$variable is ".($variable % 2 ?'even':'odd')."\n"; I'm not sure if you can nuke the whitespace in the modulus area or not. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] When is "z" != "z" ?
tedd wrote: -TG: Thanks for your explanation and time. Normally, I don't alpha++ anything -- not to criticize others, but to me it doesn't make much sense to add a number to a character. But considering the php language is so string aware, as compared to other languages, I just tried it on a lark just to see what would happen. Okay, so I found out it's limitations and quirks. But, you must admit that it is confusing to have a loop that goes from "a" to "z" and considers "aa" but not "aaa". Now, if the loop just went from a to z, then I would think that would be logical. But I fail to see the logic behind considering "aa" but not "aaa" in the evaluation. But then again, I'm not that informed. Enough said. tedd At 12:21 PM -0400 6/5/06, <[EMAIL PROTECTED]> wrote: I know this discussion doesn't need to continue any further..hah.. but I think the biggest confusion people are having is that they're looking at two things and assuming that PHP operates the same on both and these two things serve different purposes. 1. Incrementing strings: Best example giving was "File1"++ == "File2" or "FileA"++ == "FileB". In that case, wouldn't you want it to go from FileZ to FileAA? Makes sense right? 2. Comparing "greatness" of strings: Rasmus mentioned this earlier, but I wante to illustrate it a little more because I think it was overlooked. If you have a list of names, for instance, and you alphabetize them, you'd get something like this: Bob Brendan Burt Frank Fred Just become a name is longer doesn't mean it comes after the rest of the names in the list. So in that vane, anything starting in "A" will never be > something starting with a "Z". a < z aa < z aaa < z because: a aa aaa z When using interation and a for loop and " <= z" it gets to "y" and it's true, gets to "z" and it's still true, then increments to "az" and yup.. still < "z". As mentioned, it's not until you get to something starting in "z" with something after it that you're > "z". So hopefully that makes a little more sense. -TG = = = Original message = = = tedd wrote: At 1:09 PM -0700 6/4/06, Rasmus Lerdorf wrote: I agree with [1] and [2], but [3] is where we part company. You see, if you are right, then "aaa" would also be less than "z", but that doesn't appear so. Of course it is. php -r 'echo "aaa" < "z";' 1 You missed the point, why does -- for ($i="a"; $i<="z"; $i++) echo($i); -- not continue past "aaa"? Clearly, if "aaa" is less than "z" then why does the loop stop at "yz"? I thought I explained that a few times. The sequence is: a b c ... x y z aa ab ac ... yx yy yz za zb zc ... zy zx zz aaa aab Your loop stops at yz and doesn't get anywhere near aaa because za > z -Rasmus ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php As mentioned before, discussion aside, you can do what you want with range and a foreach: foreach (range('a', 'z') as $char) { echo $char; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: i have a problem inserting blob data larger than 1 mb
sunaram patir wrote: hi list, i am facing a problem inserting binary data into a blob field.this is my /etc/my.cnf file. [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock connect_timeout=60 [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid please help me. and this is what i get after running the comand mysql --help ... ... ... Possible variables for option --set-variable (-O) are: connect_timeout current value: 0 max_allowed_packetcurrent value: 16777216 net_buffer_length current value: 16384 select_limit current value: 1000 max_join_size current value: 100 i guess there is some problem with connect_timeout. Blobs have a max size like every other variable. Have you tried mediumblob and longblob yet? They both have more capacity. I suggest you refer to the MySQL manual. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: SPL Iterator and Associative Array
Jason Karns wrote: -Original Message- From: Greg Beaver [mailto:[EMAIL PROTECTED] Sent: Friday, June 02, 2006 10:39 PM To: Jason Karns Cc: php-general@lists.php.net Subject: Re: SPL Iterator and Associative Array Jason Karns wrote: I'm going to try my best to explain what I'm trying to do. I have my own class that has an array member. This class itself implements Iterator. One of the fields in the array is itself an array that I would like to iterate over. Here's some code: Hi Jason, The code you pasted is littered with fatal errors and bugs (I marked one example with "^^" above). Please paste a real batch of code that you've tested and reproduces the error and that will be much more helpful. The PHP version would be helpful to know as well. Greg -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.8.1/354 - Release Date: 6/1/2006 load($file); } public function load($file){ ... $keys = array(); $values = array(); foreach ($projects as $project) { $small = array(); $big = array(); foreach ($xpath->query('showcase/images/screenshot/thumbnail',$project) as $img){ $small[] = $img->nodeValue;} foreach ($xpath->query('showcase/images/screenshot/src',$project) as $img){ $big[] = $img->nodeValue;} $keys[] = $xpath->query('@id',$project)->item(0)->nodeValue; $values[] = array( 'title'=>$xpath->query('showcase/title',$project)->item(0)->nodeValue, 'href'=>$xpath->query('livesite',$project)->item(0)->nodeValue, 'clip'=>$xpath->query('showcase/images/feature/thumbnail',$project)->item(0) ->nodeValue, 'big'=>$big, 'small'=>$small, 'text'=>$xpath->query('showcase/description',$project)->item(0)->nodeValue); } $this->projects = array_combine($keys,$values); } function &smalls($x=null){ if(is_null($x) or !key_exists($x,$this->projects)) $x = $this->key(); return $this->projects[$x]['small']; } function small_src($x=null){ if(is_null($x) or !key_exists($x,$this->projects)) $x = $this->key(); return current($this->projects[$x]['small']); } function small($x=null){ if(is_null($x) or !key_exists($x,$this->projects)) $x = $this->key(); return ''.$this->small_img($x).''; } } ?> smalls()); while($s = current($folio->smalls())){ echo $folio->small(); next($folio->smalls()); } foreach($folio->smalls() as $s){ echo $folio->small(); } ?> Production server will be PHP 5.1.2, developing on 5.0.5 I am also considering making my own 'project' object and having Folio have an array of 'projects' rather than using the array of associative arrays. Would this provide a solution? Thanks, Jason If you're going to be using 5.1.2 in production, develop on 5.1.2. PHP doesn't guarantee backwards compatibility, especially in such a big change as 5.0.x -> 5.1.x. Better to develop on 5.1.2 from the start than to develop on 5.0.5, put the code on 5.1.2, get a bunch of errors, and then have to develop again on 5.1.2 to fix the bugs. Not to mention that any testing done with 5.0.5 is invalid since you can't be sure that things will behave the same with the different production version. You may even waste time working around bugs in 5.0.5 that don't exist in 5.1.2. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Retrieving Content
chris smith wrote: On 6/3/06, Adam Zey <[EMAIL PROTECTED]> wrote: Rodrigo de Oliveira Costa wrote: > I just discovered the problem I have to retrieve the output of the > site and not the url since its dynamic. Ca I do it like retrieve the > output of this url: > > www.tryout.com/1/2/ > > And of course store it on a variable? How to do it? I founr the func > below but couldnt understand how to make it work with a url. > > Thanks guys, > Rodrigo > > > ob_start(); > include('file.php'); // Could be a site here? What should I do to > retrieve it from an url? > $output = ob_get_contents(); > ob_end_clean(); Umm. As I said, just use file_get_contents(): $file = file_get_contents("http://www.tryout.com/1/2/";); Assuming allow_url_fopen is on. If not, you could try using curl - see http://www.php.net/curl allow_url_fopen is on by default, and curl requires custom compile-time options. Considering that, it is logical that if the user can't enable allow_url_fopen, they're not going to be allowed to recompile PHP. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Retrieving Content
Rodrigo de Oliveira Costa wrote: I just discovered the problem I have to retrieve the output of the site and not the url since its dynamic. Ca I do it like retrieve the output of this url: www.tryout.com/1/2/ And of course store it on a variable? How to do it? I founr the func below but couldnt understand how to make it work with a url. Thanks guys, Rodrigo ob_start(); include('file.php'); // Could be a site here? What should I do to retrieve it from an url? $output = ob_get_contents(); ob_end_clean(); Umm. As I said, just use file_get_contents(): $file = file_get_contents("http://www.tryout.com/1/2/";); Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Retrieving Content
Rodrigo de Oliveira Costa wrote: Actualy I went a slightly diffent way, I tried to use the file() like on the script below and I get the content of the whole page but when I try to get a single line from the array it all goes sideways. Here goes the script with the correct urls, remembering that I'm using it on the local server thats why I save it on the file to see if its getting the right content: $fc = file('http://www.fanfiction.net/s/979216/1/'); $f=fopen("some.txt","w"); foreach($fc as $line) { if ($line[85]) { //look for $key in each line fputs($f,$line[85]); } //place $line back in file echo "$line"; } It shows the whole page but saves on the file something grambled that I cant identify what it is. Iknow that when opening the html result of the page that I need to get the content its the second SELECT, and its actually on line 86, but since the PHPEd dont use line 0 it should be right. Or I'm missing something... Thanks, Rodrigo HTML can't be parsed line-by-line since even a single tag can be broken up onto multiple lines. And also, "if ($line[85])" simply checks if there is a character in position 85 of the line. It looks like your code is reading in a file, checking if each line is at least 85 characters long, and then writing it out again. I suggest you read in the whole file using file_get_contents(), and then do the regex matching or strpos matching that I described in my previous message. Also keep in mind that as of PHP 5 there is a file_put_contents() function that lets you dump out a file in one go (with higher performance than doing it yourself). php_compat also has a copy of that function for other versions of PHP, although of course they do it in PHP code so the performance benefits are slightly less. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Retrieving Content
Rodrigo de Oliveira Costa wrote: Hi guys, I'm trying to retrieve a certain variable from a site. Here it goes: The site has a SELECT box that is dynamicaly updated, I need to put a script running that will retrieve the specified SELECT with its contents, that are labels and values. Is there a way to retrieve the page and then select just one line of the code, discard the rest and then retrieve from this line the values? Here goes the SELECT : 1. Name2. Name I need to get something like this: $select = navigating; $label1 = "1.Name"; $value1 = 1; $label2 = "2.Name"; $value2 = 2; Remmembering that the SELECT is dynamic so I need also to check how many labels and values there are and store them into variables. I getting a really hard time doing this. I thank any imput you guys can give me. Thanx, Rodrigo First, get the file using file_get_contents(). Now, do two nested regular expression matches. As in, do a regular expression match to get all the blocks, and then for each match do another regular expression match to grab all the blocks. Alternatively, you could do this with strpos(), since it lets you specify where to START searching from. It might be faster, but it would probably end up being less flexible. Alternatively, if you need a super robust solution, you might want to look into actual HTML parsing libraries, like tidy (which has a PHP module). Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] If value is odd or not
IG wrote: Jochem Maas wrote: Jonas Rosling wrote: Hi all, is there any easy why to check if a value is odd or not? ignore every answer that doesn't use the % operator. Thanks // Jonas ie my answer! I think the % operator is the best way, but there was nothing wrong with the answer I gave in that it would let you know whether the value is odd or not. But, I guess being not as clever as the other guys means I better go... sob sob But there was something wrong with it. You're using string operations on a number to find out if it is odd. That means that it is many TIMES slower, and if he needs to do this in a loop, using string functions is going to be horribly slow compared to a simple modulus. Just because code "works" doesn't mean that it is acceptable. Spending a thousand times more computational time to solve a problem than is needed is a recipe for disaster. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading an XML outputting PHP file as XML
Jochem Maas wrote: IG wrote: Hi. I have a PHP file that outputs as XML from a database. i have used the header() function to output the correct header but when I use the simplexml function it is trying to parse the php file itself and not the output of the php file. I can't get my head round this. Can anyone help me? your running the simplexml function on the php file and not its output. You are doing (something like) this: $xml = simplexml_load_string(file_get_contents("/www/html/foo.php"); You need to do something like this: $xml = simplexml_load_string(file_get_contents("http://ba.com/foo.php";); Alternatively, if you don't want the PHP script to be visible on the web server, make it executable (with a shebang) and then execute it and pass the output to simplexml_load_string(). You know, using shell_exec() or the backticks operator. Note that simplexml_load_string() doesn't care about what type of file you reported it as (with Content-Type or something). It only cares that the string you pass it is XML. So if your script is the ONLY one that will ever get this XML, you don't need to bother with the content type. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ob_flush() problems
Brad Bonkoski wrote: cajbecu wrote: Hello, for ($i=0; $i < 10; $i++) { $output = "ccc2"; print ""; echo $output; print ""; ob_flush(); flush(); sleep(1); } I want to show on the browser, "ccc2" (example) every 1 second, but it shows all the text when the for stops... any ideea? i tried all the examples from php.net, all the examples on the net, bot no succes. cheers, PHP is a server side scripting language, so the information would not be sent to the browser( aka client) until the server side script has completed its execution. -Brad That is incorrect. There is nothing stopping a PHP script from doing exactly what he says, and being a server-side script doesn't imply that the data will be buffered. I suggest that both of you examine the contents of http://www.php.net/manual/en/function.flush.php for more information on obstacles to getting data to the client as it is generated. As an unrelated note, there is no point in using "print" for some things and "echo" for others. For your uses, you might as well just use "echo" for everything. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Executing functions or scripts in parallel
Phil Martin wrote: Many parts of this script were found at the following site: http://www.sitepoint.com/article/udp-portscanning-php This script isn't totally mine. I've just adapted it to my needs and it is working quite well, telling me when a service is up or down ... read the article for further details. Anyway, my question was about concurrent script running. My script is working the way I needed it to and all I need now is a way to fasten it. I still think it's a little bit slow by many aspects, maybe because I'm not a programmer and I've written a code that is not so good or fast, or there is no way to have all my servers services checked in parallel. Thanks in advance. Felipe Martins On 5/30/06, Jochem Maas <[EMAIL PROTECTED]> wrote: Phil Martin wrote: > Sure, sorry about that. I have a function that tells me if the host is DOWN > or UP. I want to run this function in parallel for each host I monitor. The > function is the following: > > function servstatus($remote_ip, $remote_ip_port, $remote_ip_proto) { > > if ($remote_ip_proto == "tcp") { >$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); > >// Turning Off Warning Messages >$i_error_old=error_reporting(); >error_reporting($i_error_old & ~ (E_WARNING)); > >if ($connect = socket_connect($socket, "$remote_ip", "" . > $remote_ip_port . "")) { >return true; the following 3 statements will never be run. >socket_set_block($socket); >socket_close($socket); >unset($connect); >} else { >return false; the following 3 statements will never be run. >socket_set_nonblock($socket); >socket_close($socket); >unset($connect);} my guess is you know even less about sockets, especially blocking/non-blocking than I do! > > } else { why are you making the distinction between udp and tcp in this way? > >// Turning off Warning Messages >$i_error_old=error_reporting(); >error_reporting($i_error_old & ~ (E_WARNING)); > >$socket = fsockopen("udp://$remote_ip", "$remote_ip_port", &$errno, > &$errstr, 2); >$timeout = 1; > >if (!$socket) { if you don't get the socket why does that mean the service is up? >return true; >} > >socket_set_timeout ($socket, $timeout); >$write = fwrite($socket,"\x00"); >if (!$write) { again if you can't write why does that mean the service is up? >return true; >} > >$startTime = time(); >$header = fread($socket, 1); >$endTime = time(); >$timeDiff = $endTime - $startTime; > >if ($timeDiff >= $timeout) { why does a time measurement mean the service is up? >fclose($socket); >return true; >} else { >fclose($socket); >return false; >} >} > } > > > Thanks in advance > > Felipe Martins > > On 5/30/06, Dave Goodchild <[EMAIL PROTECTED]> wrote: > >> >> >> >> On 30/05/06, Phil Martin <[EMAIL PROTECTED]> wrote: >> > >> > Hi everyone, >> > >> > I've made a very basic and small function to suit my needs in >> > monitoring some hosts services. I've noticed that the script is a >> little >> > bit >> > slow because of the number of hosts and services to monitor. Is there a >> > way >> > to execute my function servstatus(); in parallel with every hosts to >> > increase the speed ? >> > Thanks in advance. >> > >> > []'s >> > Felipe Martins >> > >> > >> Can you show us the function? >> >> -- >> http://www.web-buddha.co.uk >> >> dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css) >> >> look out for project karma, our new venture, coming soon! >> > This is all in the manual... Essentially you want pcntl_fork(), although you might want to use something like stream_socket_pair() to do interprocess communication. You should be able to find all the documentation and examples you need in the manual in the pcntl and stream sections. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using 'header' as redirect
Philip Thompson wrote: On May 30, 2006, at 12:52 PM, Stut wrote: Philip Thompson wrote: Ok, I have modified my code a little bit. Stut, yes, output buffering was on by default (4096). I *think* this will work. It appears to be the same as before - still redirecting appropriately: ... The subpage does not change any, only index.php. I am basically "holding off" on displaying the stuff between ob_start() and ob_end_flush(), unless it's header information. That way, if the subpage needs to redirect, it can without errors. Correct? Indeed. Output buffering does exactly what it says on the tin - it buffers the output until the page execution finishes or it's explicitly flushed. Your ob_end_flush call is technically not needed unless you have a reason to end the buffering at that point. -Stut I was under the impression that if ob_end_flush() was not called, then there would be a memory leak. Is this not the case? From http://us3.php.net/ob_start : "Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order." Also 4096k... I wonder if that's enough buffering to include all the stuff that I want to show? As of right now, it is. Is there another standard level of buffering to specify? ~PT Browsers usually choke on that kind of volume of HTML (Well, choke as in take forever to load a page while sucking up massive amounts of system memory)... Not to mention there are very few situations where you actually need to output 4MB of HTML in a single page load. I'd say that if you're worried about overrunning PHP's output buffers, you have more serious design issues with your script. In itself, it isn't a memory leak; PHP always flushes all buffers when a script terminates. AFAIK this is the default behavior with output buffering enabled; PHP buffers all script output and then flushes it when the script terminates. I have no idea if PHP is smart enough to flush the buffer if it fills up. But seriously, this shouldn't be an issue; break your data up into more manageable chunks so that you aren't trying to cram 4MB of HTML into some poor user's browser. If you're getting this data from a database, set a limit to how many records can be shown, and give the user a form to control the parameters of what data is returned. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Better method than stristr
Steven Osborn wrote: Can someone please advise a faster solution to do what I'm doing below? All I need to be able to do is determine if any of the strings in the array are contained in $q. The method I have works, but I'm sure its not the most efficient way to do it. $dirtyWord = array("UNION","LOAD_FILE","LOAD DATA INFILE","LOAD FILE","BENCHMARK","INTO OUTFILE"); foreach($dirtyWord as $injection) { if(stristr($q,$injection)) { //Do Something to remove injection and log it } } Thank you. --Steven Would it not a much safer and WAY faster method simply be to use mysql_escape_string()? What are you doing that allows users to give raw SQL to the server that you need to deny certain things? It seems like you're on very dangerous ground, letting users throw arbitrary SQL at your script. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pop-up window in php???
[EMAIL PROTECTED] wrote: ok, maybe I didn't make my question too clear. I was mostly wondering if there is a way to do it in PHP rather than Javascript. I would prefer only using php. and from the answers I got, I take it that there is no way of doing it in PHP. thanks, Siavash Quoting Andrei <[EMAIL PROTECTED]>: Not related to PHP, but u hava javascript confirm function or prompt (if you need input also). Andy [EMAIL PROTECTED] wrote: Hi all, Is there anyway to have a pop-up window to ask "are you sure? yes / no" in php? I know you can do it in Javascript, but I'm not sure what's the best way to implement it in php. I want the page to do nothing if "no" is pressed. any help would be appreciated. thanks, Siavash -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php PHP is a server-side language. It cannot directly influence anything on the client-side. That is why you need to have your PHP script output a client-side scripting language such as JavaScript. You are still only executing PHP code on the server. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: pop-up window in php???
[EMAIL PROTECTED] wrote: Hi all, Is there anyway to have a pop-up window to ask "are you sure? yes / no" in php? I know you can do it in Javascript, but I'm not sure what's the best way to implement it in php. I want the page to do nothing if "no" is pressed. any help would be appreciated. thanks, Siavash This has nothing to do with PHP, this is a javascript matter. You PHP script merely prints out the javascript code. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems with regex
Merlin wrote: thank you, that worked excellent! Merlin Dave Goodchild schrieb: On 27/05/06, Merlin <[EMAIL PROTECTED]> wrote: Hi there, I am somehow lost when it comes to regex. I am trying to remove ! and ? characters from a string. Could somebody please help me to get a working regex running for that? I tried: $str = preg_replace('/\!\?\./', ' ', $str); How about $str = preg_replace('/(\!|\?)+/', $str); **NEVER** use regular expressions for simple search/replace operations!!! They are MUCH slower than a simple string replace, and should be avoided if at all possible. What you are doing is a very simple string replace, and you should not use regular expressions for that. I am assuming you want to remove the ! and ? and not replace them with a space. In this case: $str = str_replace(array("!". "?"), "", $str); Or if you did want to replace them with a space: $str = str_replace(array("!". "?"), " ", $str); This is especially important if you're doing the string replace in a loop, but even if you aren't, it is very bad style to use regular expressions for such a simple replacement. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace learning resources? Regex tuts? Tips? (and yes, I have been rtfm)
Eric Butera wrote: On 5/25/06, Micky Hulse <[EMAIL PROTECTED]> wrote: Kevin Waterson wrote: > Try this quicky > http://phpro.org/tutorials/Introduction-to-PHP-Regular-Expressions.html Sweet, good links all. Thanks for sharing! :) Have a great day. Cheers, Micky -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I built something similar to the situation that you are describing. One difference though is I used preg_replace_callback (http://us2.php.net/preg_replace_callback) so that I can do custom scripting with the matched string to be replaced. I know I'm entering this discussion a bit late, but one tool that I've found indispensible in writing regular expressions (even after knowing how to write them) is The Regex Coach (http://www.weitz.de/regex-coach) (Free, and runs on Windows and Linux). Essentially, you paste the text to search into the bottom textbox, and then start typing your regular expression into the top one. As you type, it shows you what it is matching in the bottom one. It can also show you what individual submatches are matching, and all sorts of neat stuff. So, if I have an HTML web page and I want to suck some specific information out of it, I'll paste the information in, write up a regex, and make sure it's matching what it's supposed to. But the feedback AS you're typing it is super handy. For example, if I have a regex, and I add a "[a-z]", then the indicator will show it matching the next character, then if I add "*", the text selection will expand to show it matching the rest of the letters, and so on. Anyhow, I find the feedback as I write a regex to be addictively useful. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: str_replace(), and correctly positioned HTML tags
Dave M G wrote: PHP list, This may be a simple matter. Please feel free to tell me to RTFM if you can direct me to exactly where in the FM to R. Or, alternately, please use simple explanations, as I'm not an experienced PHP coder. I'm building a simple content management system, where users can enter text into a web form. The text is stored in a MySQL database. The text should be plain text. When the text is retrieved from the database for display, I want to add some HTML tags so I can control the format with an external CSS. I'm assuming the best way to do this is with str_replace(). But there are some complications which make me unsure of its usage. First, here is the code I initially made: $content = "" . str_replace("\r\n", "\n", $text) . "\n"; echo $content; The problem is that I want to give the users the ability to add text that will be converted to tags. I figure the best and easiest way to do this is give them some text markers, like "--++" and "++--" that can be converted to and respectively. So I guess I do: $content = str_replace("--++", "", $text); $content1 = str_replace("++--", "", $content); $content2 = "" . str_replace("\r\n", "\n", $content1) . "\n"; echo $content2; But of course a user is likely to put their heading at the beginning of their text. Which would generate: Headingtext text text That's not good. What I need is: Headingtext text text And figuring out how to do that was where my brain stopped. I need to be able to account for circumstances where it may not be appropriate to arbitrarily put a tag at the beginning. As well as tags, there may also be things such as images and lines, but they are all similar in that they will take some text code and convert into an HTML entity. I need to be able to separate those out and then be able to place opening and closing tags at the right place before and after paragraphs. Is there a way to do this? Is there a good tutorial available? Any advice appreciated. Thank you for taking the time to read this. -- Dave M G It seems like your life would be a lot easier with break takes instead of paragraph tags. Break tags behave like newlines, so work rather well for a 1 to 1 correspondance when turning \r\n into . This way, you don't have to worry about the opening tags. The fastest way to do this may be the function nl2br(), which takes only one parameter, your string, and returns your string with the newlines replaced by break tags. Another piece of advice is that you are creating a lot of strings. Do you need the string $text to be unmodified? Why don't you do this: $text = str_replace("--++", "", $text); $text = str_replace("++--", "", $text); $text = "" . str_replace("\r\n", "\n", $text) . "\n"; echo $text; Remember that PHP works by value, not by reference. So what happens in that first line is that it makes a copy of $text, does the replacement on that copy, and then overwrites $text with that copy. With your method you are creating a bunch of strings that I would imagine go unused later in your script. Since you seem to want to maintain a newline in the HTML source, nl2br might not be exactly perfect for you. Here is your original code modified to work with break tags: $text = str_replace("--++", "", $text); $text = str_replace("++--", "", $text); $text = str_replace("\r\n", "\n", $text); echo $text; And here is the same code using arrays and one single replace instruction to do it, since replacement order doesn't matter: $text = str_replace(array("--++", "++--", "\r\n"), array("", "", "\n"), $text); echo $text; And of course, if you never do anything with your formatted string except echoing it out, don't store it, just echo it: echo str_replace(array("--++", "++--", "\r\n"), array("", "", "\n"), $text); So, to sum up my advice: 1) Don't create extra variables that you will never use 2) Consider using break tags instead of paragraph tags, they're easier to deal with in your situation. 3) Use arrays for replacement when appropriate 4) Don't store data if you're only ever going to echo it out right away and never use it again. I think that's it, unless I missed something. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Curt Zirzow wrote: On Tue, May 23, 2006 at 06:37:27PM -0400, Adam Zey wrote: The data going from client->server needs to be sent over an HTTP connection, which seems to limit me to PUT and POST requests, since they're the only ones that allow significant quantities of data to be sent by the client. Ideally, there should be no delay between the client wanting to send data and the data being sent over the connection; it should be as simple as wrapping the data and sending. So, I need some way to send data to a PHP script that lives on a webserver without any buffering going on. My backup approach, as I described in another mail, involves client-side buffering and multiple POST requests. But that induces quite a bit of latency, which is quite undesirable. How much data are you sending? A POST shouldn't cause that much delay unless your talking about a lot of POST data Curt. Please see my more recent messages on the subject for the reasoning behind this. It's interactive data being sent that may require an immediate response. If a user is tunneling a telnet session, they expect a response within a matter of milliseconds, not seconds. POST holds onto the data until the client is done uploading, which with a persistant POST request never happens, which is why I spoke of multiple POST requests above and in more recent messages. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Embedding PHP 5 in a C application
D. Dante Lorenso wrote: All, Can anybody give me a pointer on where I might start to learn how to embed Zend2/PHP 5 inside a stand-alone C application? I realize that by asking a question like this it might imply I am not prepared enough to do handle the answer, but ignoring that, is there a document out there? I guess I could start hacking Apache or something, but I was hoping for more of a tutorial/hand-holding article on the basics. Dante Are you sure that you can't get away with just calling the PHP executable from your C program to do any PHP related activity? Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Stut wrote: Adam Zey wrote: Tunelling arbitrary TCP packets. Similar idea to SSH port forwarding, except tunneling over HTTP instead of SSH. A good example might be encapsulating an IRC (or telnet, or pop3, or ssh, etc) connection inside of an HTTP connection such that incomming IRC traffic goes over a GET to the client, and outgoing IRC traffic goes over a POST request. So, the traffic is bounced: [mIRC] ---> [client.php] -internet-> [apache ---> server.php] -internet-> [irc server] And the same in reverse. The connection between client.php and server.php is taking the IRC traffic and encapsulating it inside an HTTP connection, where it is unpacked by server.php before being sent on to the final destination. The idea is to get TCP tunneling working, once you do that you can rely on other programs to use that TCP tunnel for more complex things, like SOCKS. You're trying to get a square peg through a round hole. The HTTP protocol was not designed to do anything like this, so the standard implementation by most web servers and PHP does not allow what you are trying to do. That's the fun of it, making things like PHP and HTTP do things they weren't supposed to. I'm curious about your 'lots of POSTs' solution. How are you keeping the connection open on the server-side? It's certainly not possible to maintain that connection between requests without using a process outside the web server that maintains the connections. I've implemented a system in the past to proxy IRC, MSN and AIM connections in this way, but it only worked because the requests that came into PHP got passed to this other process which held all the connections and managed the traffic. And yes, it did generate a huge amount of traffic even when it wasn't doing anything due to the need to poll the server for new incoming messages. With the lots-of-posts, the connection is a regular keepalive, which any webserver happily keeps open. When this keepalive connection closes, you open a new one. At least this way, while I still need to send lots of posts (Say, one every 100ms, or 250ms, something like that), I can limit the new connections to once every minute or two. While 4 messages per second may seem like a lot, I would imagine that an application such as Google Maps would generate a LOT more than that while a user is scrolling around; google maps would have to load in dozens of images per second as the user scrolled. Polling for incomming messages isn't a problem, as there is no incomming data for the POSTs. A seperate GET request handles incomming data, and I can simply do something like select, or even something as mundane as polling the socket myself. But I don't need to poll the server. And, the 4-per-second POST transactions don't need to be sent unless there is actually data to be sent. As long as a keepalive request is sent to make sure the remote server doesn't sever connection (My tests show apache 2 with a 15 second timeout on a keepalive connection), there doesn't need to be any POSTs unless there is data waiting to be sent. Of course, this solution has high latency (up to 250ms delay), and generates a fair number of POST requests, so it still isn't ideal. But it should work, since it doesn't do anything out-of-spec as far as HTTP is concerned. This demonstrates a point at which you need to reconsider whether a shared hosting environment (which I assume you're using given the restrictions you've mentioned) is enough for your purposes. If you had a dedicated server you could add another IP and run a custom server on it that would be capable of doing exactly what you want. In fact there are lots of nice free proxies that will happily sit on port 80. However, it's worth nothing that a lot of firewalls block traffic that doesn't look like HTTP, in which case you'll need to use SSL on port 443 to get past those checks. I wasn't targetting shared hosting environments. I imagine most of them use safe mode anyhow. I was thinking more along the lines of somebody with a dedicated server, or perhaps just a linux box in their closet. The thing is, I'm not writing a web proxy. I'm writing a tunneling solution. And, the idea is that firewalls won't block the traffic, because it doesn't just look like HTTP traffic, it really IS HTTP traffic. Is a firewall really going to block a download because the data being downloaded doesn't "look" legitimate? As far as the firewall is concerned, it just sees regular HTTP traffic. And of course, a bit of obuscation of the data being sent wouldn't be too hard. The idea here is that no matter what sort of proxy or firewall the user is behind, they will be able to get a TCP/IP connection for any protocol out to the outside world. Even if th
Re: [PHP] How to disable PHP's POST caching?
jekillen wrote: On May 23, 2006, at 3:37 PM, Adam Zey wrote: Essentially, I'm looking to write something in the same vein as GNU httptunnel, but in PHP, and running on port 80 serverside. The server->client part is easy, since a never-ending GET request can stream the data and be consumed by the client instantly. The thing I'm having trouble with is the other direction. Getting data from the client to the server. Allow me to interject a suggestion/question. As far as I understand it AJAX or asyincronous connections sound like what youmr afterno(?) JK AJAX implies javascript, which means a browser. My situation doesn't involve a browser. Unless I'm mistaken, AJAX makes many GET requests to send data, which would have the same problem as sending many POST requests, except you can send less data. Regards, Adam ey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: how include works?
Mindaugas L wrote: Hi can anybody explain how require works, and what's the difference between _once and regular? What's going on when php file is processed? In manual is written just, that it's readed once if include_once. What does to mean "readed"? Thank You The difference between include and require is that if include() can't find a file, it produces a warning, and the script continues. If require() can't find a file, the script dies with a fatal error. The difference between include()/require() and include_once()/require_once() is that if you do, say, require_once() twice, it ignores the second one. This is useful if your script might include the same file in different places (perhaps your main script includes two other scripts which both themselves include "functions.php") Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Mindaugas L wrote: I'm still new in php:) what about using cookies? nobody mentioned anything? store info in client cookie, and read it from server the same time? :)) On 5/24/06, *Adam Zey* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote: *snip* Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Mindaugas Cookie data is sent to the server as an HTTP header. That sort of puts the kibosh on that. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Formatting of a.m. and p.m.
Kevin Murphy wrote: date("a"); > output = AM Is there any easy way to change the formatting of the output of above from "am" to "a.m." in order to conform to AP style? Something like this below would work, but I'm wondering if there is something I could do differently in the date() fuction to make it work: $date = date("a"); if ($date == "am") { echo "a.m."} elseif ($date == "pm") { echo "p.m."} The date function itself doesn't support it, but you don't need IFs. To replace your example: echo str_replace(array("am", "pm), array("a.m.", "p.m."), date("a")); And to do the replacement on a full data/time: echo str_replace(array("am", "pm), array("a.m.", "p.m."), date("g:i a")); which would output something like "12:52 p.m." Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Jay Blanchard wrote: [snip] Essentially, I'm looking to write something in the same vein as GNU httptunnel, but in PHP, and running on port 80 serverside. [/snip] All of that was nice, but still does not explain what you are trying to accomplish other than maintaining a connection state between client and server. What kind of process are you running that would require this? That is what I am looking for. What is the real issue? What would you do that would require a stated connection? Tunelling arbitrary TCP packets. Similar idea to SSH port forwarding, except tunneling over HTTP instead of SSH. A good example might be encapsulating an IRC (or telnet, or pop3, or ssh, etc) connection inside of an HTTP connection such that incomming IRC traffic goes over a GET to the client, and outgoing IRC traffic goes over a POST request. So, the traffic is bounced: [mIRC] ---> [client.php] -internet-> [apache ---> server.php] -internet-> [irc server] And the same in reverse. The connection between client.php and server.php is taking the IRC traffic and encapsulating it inside an HTTP connection, where it is unpacked by server.php before being sent on to the final destination. The idea is to get TCP tunneling working, once you do that you can rely on other programs to use that TCP tunnel for more complex things, like SOCKS. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Going through 2 arrays at once
Pavleck, Jeremy D. wrote: Greetings, PHP Rookie here with a quick question - how do I go through 2 arrays at once with different keys? I'd like to combine these 2 arrays into one: for ( $i = 0; $i < sizeof($logicalDrive); $i++) { echo "$arrLogDrive[$i]\n"; } for (reset($logicalDrive); $i = key($logicalDrive); next($logicalDrive)) { echo "$i: $logicalDrive[$i]\n"; } The first array returns things that the OID in the second array represent. I.E. $array = array( 1=> 'Controller Index:', 'Drive Index:', Fault Tolerant Mode:', etc, etc); While the second has the MIB name as the key, then the return value of the snmpget: CPQIDA-MIB::cpqDaLogDrvCntlrIndex.0.1: 0 CPQIDA-MIB::cpqDaLogDrvIndex.0.1: 1 CPQIDA-MIB::cpqDaLogDrvFaultTol.0.1: mirroring What I'd like to do it replace CPQIDA-MIB::cpqDaLogDrvCntlrIndex.0.1 that gets displayed into the "Controller Index:" in the other array. I hope this makes sense. Sorry if it's super simple to solve, but I tried a few things, and googled a few things, but I must have not found the right thing I was looking for, as I still can't figure it out. Thank you very much! JDP Jeremy Pavleck Network Engineer - Systems Management IT Networks and Infrastructure Direct Line: 612-977-5881 Toll Free: 1-888-CAPELLA ext. 5881 Fax: 612-977-5053 E-mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> Capella University 225 South 6th Street, 9th Floor Minneapolis, MN 55402 www.capella.edu <http://www.capella.edu/> It sounds like you want to use a while loop and then iterate manually through both arrays, iterating both arrays once per loop iteration. Sorry if I've misunderstood the problem. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Jay Blanchard wrote: [snip] As I mentioned in my more recent mail, this unfortunately isn't an option since I need to run on port 80 without disturbing the existing webserver, which requirse that the script be running through the webserver :( [/snip] I have been reading this thread with much interest and think that perhaps a different approach may be needed. What, exactly, are you trying to accomplish? Skip past the persistency, etc. and describe the problem for which you are seeking a solution. I have the feeling that there may be a way to do what you want with PHP if you will describe the process. Essentially, I'm looking to write something in the same vein as GNU httptunnel, but in PHP, and running on port 80 serverside. The server->client part is easy, since a never-ending GET request can stream the data and be consumed by the client instantly. The thing I'm having trouble with is the other direction. Getting data from the client to the server. The data going from client->server needs to be sent over an HTTP connection, which seems to limit me to PUT and POST requests, since they're the only ones that allow significant quantities of data to be sent by the client. Ideally, there should be no delay between the client wanting to send data and the data being sent over the connection; it should be as simple as wrapping the data and sending. So, I need some way to send data to a PHP script that lives on a webserver without any buffering going on. My backup approach, as I described in another mail, involves client-side buffering and multiple POST requests. But that induces quite a bit of latency, which is quite undesirable. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Jochem Maas wrote: why is port 80 a requirement - HTTP can technically over any port. It must be accessible to any client, no matter what sort of firewall or proxy they go through. The only way to absolutely assure that is, as far as I know, to use port 80. It is the only port that you can count on with a fair degree of certainty, if the user is proxied or firewalled. I'd just as soon write my own simple webserver, but then it'd run into conflicts with existing webservers on port 80. My current solution is to buffer data on the client-side, and send a fresh POST request every so many milliseconds (Say, 250) over a keepalive connection with the latest buffered data. The downside of this is that it introduces up to 250ms of latency on top of the existing network latency, and it produces a lot of POST requests. I would really like to eliminate that by streaming the data rather than splitting it up like that. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Jochem Maas wrote:. ... Richard's suggestion is most likely the best option (assuming you want to use php) otherwise you'll probably end up hacking webserver and/or php sources (painful, time consuming and a probable maintainance nightmare) ... which also comes with the risk of breaking lots http protocols 'rules' while your at it. Regards, Adam Zey. As I mentioned in my more recent mail, this unfortunately isn't an option since I need to run on port 80 without disturbing the existing webserver, which requirse that the script be running through the webserver :( I've considered the possibility of looking into Perl or C (via CGI) to try to get the desired functionality, but they have their own issues (namely more complicated installation than just sticking a script anywhere in the web tree as you can with a default PHP installation). Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Richard Lynch wrote: On Tue, May 23, 2006 4:39 pm, Adam Zey wrote: The only other approach I can figure out is to send periodic POST requests with the latest data, the downside of which is a huge increase in latency between data production and consumption. Sounds like you maybe want to run your own "server"... http://php.net/sockets Unfortunately, the requirement is that the script be able to accept data on port 80, and co-exist with an existing webserver at the same time. As far as I can tell, this requirement can only be fulfilled by running the script through a webserver. Also, sockets are not compiled into PHP by default, and stream sockets aren't included in versions below PHP 5.0.0, as far as I can tell. That sort of puts a hamper on socket usage. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to disable PHP's POST caching?
Jochem Maas wrote: Adam Zey wrote: PHP seems to cache POST data, and waits for the entire POST to finish sending before it makes it available to php://input. I'd like to be able to read the post data from php://input while the client is still uploading it. How can I cause PHP to make the POST data available right away instead of after the client finishes sending? Regards, Adam Zey. PS: As far as I can tell, PHP caches the entire POST in memory as it is being sent, but just doesn't make it available to php://input until after the client is done. Since PHP already has it in memory, why isn't it accessible? are you sure it's php that is holding it in memory? $_POST is fully filled on the first line of the script which gives me the impression that the webserver is caching the response until it all been uploaded before even starting up php. or am I missing something here? You're correct, of course. I was a bit confused, it seems. PUT behaves as I described above. If you do a PUT request for the PHP script directly, the PHP script is called right away, and any attempt to fread from php://input blocks until either the client is done sending, or some sort of buffer is filled (the fread occasionally returns with lots of data if you keep sending). So, might I amend my question to, is it possible to disable PHP buffering PUTs, or Apache buffering POST? (Or is it PHP that just buffers the POST before actually executing the script, but post Apache?) Essentially what I want is a persistant HTTP connection over which I can stream data and have the server-side PHP script process the data as it arrives, rather than when all the data is sent. The only other approach I can figure out is to send periodic POST requests with the latest data, the downside of which is a huge increase in latency between data production and consumption. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How to disable PHP's POST caching?
PHP seems to cache POST data, and waits for the entire POST to finish sending before it makes it available to php://input. I'd like to be able to read the post data from php://input while the client is still uploading it. How can I cause PHP to make the POST data available right away instead of after the client finishes sending? Regards, Adam Zey. PS: As far as I can tell, PHP caches the entire POST in memory as it is being sent, but just doesn't make it available to php://input until after the client is done. Since PHP already has it in memory, why isn't it accessible? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo'ing a variable and cat'ing text
got it! i had to have my block of code look like this: if ( $file = file ( $filename ) ) { foreach ( $file as $line ) { if ( $line != "" ) { $line = trim($line); echo ( $line . "@mdah.state.ms.us" ); echo "\n"; } } } else { echo ( "Couldn't open $filename" ); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo'ing a variable and cat'ing text
John Nichel wrote: Well, you're not telling fgets how much to read for one, and I'd do this a different way to begin with... if ( $file = file ( $filename ) ) { foreach ( $file as $line ) { if ( $file != "" ) { echo ( $line . "@mdah.state.ms.us" ); } } } else { echo ( "Couldn't open $filename" ); } When I do that, I get: userabc @mdah.state.ms.ususerdef @mdah.state.ms.ususerxyz @mdah.state.ms.us so looks like I need to strip out the end-of-line (EOL) character somehow. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo'ing a variable and cat'ing text
Hi, I just tried that, didn't make a difference, still not getting my expected output. [EMAIL PROTECTED] wrote: [snip] echo "$thedata"."@mdah.state.ms.us"; [/snip] Try echo "$thedata".'@mdah.state.ms.us'; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] echo'ing a variable and cat'ing text
I have a file called userlist. I'm trying to read the file, and then echo their name and add @mdah.state.ms.us with it. In the file userlist, it looks like: userabc userdef userxyz and I have the following code: But when I run it, I get: @mdah.state.ms.ususerabc @mdah.state.ms.ususerdef @mdah.state.ms.ususerxyz and I am expecting to get: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] So can someone look at my code and let me know why I'm not getting my expected output? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] working with ini files
On Tue, 2006-02-28 at 13:32 -0500, Benjamin Adams wrote: > I have created my own ini file. I can read the values into an array > fine. but What I want to do is change a value in the ini file. Example > > file.ini > dog = 3 > cat = 4 > fish = 7 > > altered file.ini > dog = 3 > cat = 5 > fish = 7 > > how can I do this, I tried using ini_set but its not working. > help would be great, Thanks!! > Ben As has been mentioned ini_set is for php.ini values. You can do what you want with fopen and all that manually or check out http://pear.php.net/package/Config all the hard work has been done for you. Adam Ashley signature.asc Description: This is a digitally signed message part
Re: [PHP] Limitation on PEAR : Spreadsheet_Excel_Writer
On Fri, 2006-02-10 at 05:47 +0700, Bagus Nugroho wrote: > Hello Everyone, > > I'm succesfully generate report from mysql table using PEAR : > Spreadsheet_Excel_Writer, but I have problem to generate from table > which contain long text, the text is not download completely. > such as blablabla. > it only contain blab > > How can manipulate PEAR, to get full text on excel sheet. > Next time direct your question to the PEAR General List ([EMAIL PROTECTED]) to get a much more useful answer. This is due to the default mode of Spreadsheet_Excel_Writer creating an Excel 7 (or maybe 6) compatible spreadsheet which has these string limitations. If you change the version of spreadsheet it is creating you will not have these problems. I don't know the exact commands or versions to set it to but check the documentation or search the archives of pear-general. I know for sure it is in the pear-general archives as this question has been asked and answered many times. Adam Ashley signature.asc Description: This is a digitally signed message part
Re: [PHP] XML and htmlentities conditionally?
Brian V Bonini wrote: On Sun, 2006-01-29 at 02:01, Adam Hubscher wrote: I have a block of XML that looks as follows: <*_~_*> Røyken VGS <*_~_*> My question is, can I in any way efficiently (i -stress- efficiently, if anyone read my previous XML and special characters post its a rather large XMl file (breaking 18mb now) and speed is of the essence) cause html_entity_decode to not decode those tags? What's the end results your looking for? If you are trying to pass that data straight through the parser try wrapping it in CDATA. The information is used to keep a database up to date for a service that was created in order to provide more advanced functionality for the service that made it. The XML file is not -mine-, and to search for all the html entities and wrap them in cdata before parsing would be kinda silly I think :O So yea, thats what I was trying to avoid having to do :O -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] XML and htmlentities conditionally?
I have a block of XML that looks as follows: <*_~_*> Røyken VGS <*_~_*> Now, if I run that block of XML through htmlentities, I will get the following: <*_!_*> Røyken VGS <*_~_*> XML parsers will return a problem, as there is both an unclosed tag and an invalid tag, in two places no less (however the error will occur on the first "tag". In order for this particular XML file to parse properly, I -must- run html_entity_decode. This causes quite the predicament as if I were to then run htmlentities() on this portion of the file, it would produce quite a bit of chaos. My question is, can I in any way efficiently (i -stress- efficiently, if anyone read my previous XML and special characters post its a rather large XMl file (breaking 18mb now) and speed is of the essence) cause html_entity_decode to not decode those tags? Or any other way would be nice too, I'm pretty much open to anything... as long as it doesnt severely hurt the efficiency of the script. (I discovered the error of my ways in the previous problem btw, having a doctype helps... me == brainded in that :s) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML and special characters
Steve Clay wrote: Sunday, January 22, 2006, 10:10:54 PM, Adam Hubscher wrote: ee dee da da da? §ð <-- those that look like html entities are the represented characters. I was mistaken, they are html entities, Can you show us a small chunk of this XML that throws errors? You said you've tried various parsers. Did none of those parsers have error logging capabilities? Show us the errors. Steve I realized my problem and fixed it. For the future, a doctype is required no matter what ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML and special characters
Adam Hubscher wrote: tedd wrote: I've been having a tough time with parsing XML files and special characters. -snip- Any suggestions as to how I could get around this seemingly impossible road block thats been placed by what seems to be the xml engines :O.. Adam: I believe that these "special" character will be with us for a long while. I suggest that you review the Unicode database for these characters and my suggestion is to use the code-points (HEX equivalences) for these characters. For example, 0061 is a small "a", 2022 is a "bullet", 2713 is a "check-mark" and so on. Most language glyphs of the world are represented in the Unicode database. HTH's tedd Oh, I understand that they'll be here for a while. The problem is the XML file is not my own, rather, its generated by another service that I am creating a stemmed service for. I feel I have asked much of the owner of that service in creating a properly formed XML file (he was simply using pseudo xml that was, although nice and organized, unable to be parsed.. period, and took forever with pregs, at least now running through an XML generator the script itself takes less time on his part too, and hes thankful for that.) There are usernames listed in the file that use these special characters. Rather than have him have to well, go through and edit the 3 some odd users that are indexed... unless there is a way for the xml writer to do hex codes instead of unicode codes automatically... (and in that partake, is there any way to read them automatically with a parser?), then the idea is feasible. Other than that, I'm trying to find a solution to parse the existing file with the unicode data that causes a fatal error in the parser. ee dee da da da? §ð <-- those that look like html entities are the represented characters. I was mistaken, they are html entities, which is even odder to me. I apologize for earlier referring to utf8, they do not decode with utf8, they decode with html entities. however, i continue to try methods to get it to read... still it does not read properly. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML and special characters
tedd wrote: I've been having a tough time with parsing XML files and special characters. -snip- Any suggestions as to how I could get around this seemingly impossible road block thats been placed by what seems to be the xml engines :O.. Adam: I believe that these "special" character will be with us for a long while. I suggest that you review the Unicode database for these characters and my suggestion is to use the code-points (HEX equivalences) for these characters. For example, 0061 is a small "a", 2022 is a "bullet", 2713 is a "check-mark" and so on. Most language glyphs of the world are represented in the Unicode database. HTH's tedd Oh, I understand that they'll be here for a while. The problem is the XML file is not my own, rather, its generated by another service that I am creating a stemmed service for. I feel I have asked much of the owner of that service in creating a properly formed XML file (he was simply using pseudo xml that was, although nice and organized, unable to be parsed.. period, and took forever with pregs, at least now running through an XML generator the script itself takes less time on his part too, and hes thankful for that.) There are usernames listed in the file that use these special characters. Rather than have him have to well, go through and edit the 3 some odd users that are indexed... unless there is a way for the xml writer to do hex codes instead of unicode codes automatically... (and in that partake, is there any way to read them automatically with a parser?), then the idea is feasible. Other than that, I'm trying to find a solution to parse the existing file with the unicode data that causes a fatal error in the parser. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] XML and special characters
I've been having a tough time with parsing XML files and special characters. I have attempted every applicable engine, last try SAX, to attempt at parsing a (rather large, 17.8mb) xml file. The problem I hit, is when it hits a UTF8 encoded character. I've attempted at decoded the file before it hits the parser, I've attempted even ENCODING it (god knows why that'd work, it didnt, lol). I've tried html_entities, etc. Nothing as such has worked. I've also tried simply removing the character, and low/behold, it worked! Darned thing... §µÖÕÔÓÒ Those are the characters so far that have caused me problems. I'd give the utf8 encoded equivalent, but I'm not sure of it off the top of my head. My code, varies so much that I'm not sure it'd be useful to type it out. The issue seems not to be with my code, as when I parse the file manually with a whole bunch of inefficient regex statements, everything works out peachy. The problem with that way again is, it eats system resources for a very long time (remember, 17mb file, and its all plain text? :)). Any suggestions as to how I could get around this seemingly impossible road block thats been placed by what seems to be the xml engines :O.. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Schroedinger's Bug - may require exorcism...
So... I have this script (being called in a perfectly typical way by PHP 4.4.1 through mod_php in Apache 2.0.55) which sometimes runs perfectly, and sometimes chooses, totally haphazardly, to seemingly run itself twice, which of course causes it to die with a fatal error after it tries to redefine some functions. As mysterious as that is, it turns out it must be something altogether more sinister. I tried putting die() at the end of the script, on the assumption that it was for some reason executing twice, yet behold: the problem is still present, and the PHP error log still complains about constants and functions being redefined! The problem, I therefore thought, cannot be that the script is being run twice. (In retrospect, this was the most likely possibility, because the page doesn't actually output anything if it dies with this error.) So for debugging, I added a bit that logs one message to a file immediately before the die() at the end of the file, and a different message after the die(). The die() seems to be working normally, in that it only logs the first message... But wait a second! WTF? If the PHP error log is to be believed, then the script should be dying with a fatal error before it even *gets* to that point in the script, isn't it? And the greater WTF is the fact that, as I mentioned above, every time the page is requested, it unpredictably either does this or works flawlessly. Oh my. How do I even *begin* to debug something like this? Thanks for any help. -- Adam Atlas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Core dumps
Hi all, new to the list, and a bit of a php cluebie. I know I'll omit some details that you'll need, so tell me what you need to know. I've been happily running mod_php4 (4.4.0) with apache 2.0.52 on FreeBSD 4.9 for quite some time, no problems. Today I tried to install phpBB from /usr/ports/www/phpbb and it failed with a message about needing CLI, and having already installed a conflicting port. Some googling suggested I needed to deinstall www/mod_php4 and install lang/php4 instead. Once I did that, I found that I had broken my gallery and squirrelmail installs. Apache logs entries thus: [Sat Jul 16 20:25:36 2005] [notice] child pid 53883 exit signal Bus error (10) Attempting to run a .php file from the command line results in a core dump, for example: php /usr/local/www/data/gallery/index.php Bus error (core dumped) So can anyone explain in small words what to try next? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Images and File Permissions
I have a script that generates, creates, and updates dynamic banner images for users of a service. Recently I have run into a problem with file permissions... that has thoroughly annoyed me. I found a solution to fix the problem, however, it was then hit with another problem, and I'm not sure how secure I find my solution to be. During the image creation process, the files are given the normal image permission of 644 (rw-r--r--). Of course, this makes updating impossible. I attempted to use a simple chmod();, however, the script didnt have the permissions to do this. I couldnt figure out a way to fix this, so I moved on to looking for other solutions. I ended up with somethign that worked, slightly, but did not provide me with an actual fix due to another problem. I would connect to the folder via local FTP, then using ftp_site run a direct CHMOD on the files. However, in doing this, I feel that the script itself is insecure. Also, it didnt work in the end. After running the update script, to test out my new solution, I was confronted with a new problem that I didnt understand. The FTP command returned "Bad File Descriptor" after executing the CHMOD. After attempting in a few other of my own FTP clients, I ran into -exactly- the same problem. My questions are this: A) Is there any way to set the permissions on the file on creation of the image? B) If no, is there a way I can do the CHMOD, even though chmod(); returned insufficient permissions to do so? C) If no, is there a way I can fix the bad file descriptor, to fix the ftp solution I have? Any other solutions would be able as well, given that they're somewhat secure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Echo array string index?
Matt Darby wrote: I have an array setup as such: *$arr['generated text']='generated number';* What would be the best way to echo the key in a loop? Seems pretty easy but I've never attempted... Thanks all! Matt Darby I'm not sure I understand the question. You could do foreach($arr as $key => $value) { print($key); }. There are also a number of functions that get the current key on the array's pointer: http://us2.php.net/manual/en/function.key.php http://us2.php.net/manual/en/function.array-keys.php But once again, it really comes down to what exactly it is you want to do... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Images and File Permissions
I have a script that generates, creates, and updates dynamic banner images for users of a service. Recently I have run into a problem with file permissions... that has thoroughly annoyed me. I found a solution to fix the problem, however, it was then hit with another problem, and I'm not sure how secure I find my solution to be. During the image creation process, the files are given the normal image permission of 644 (rw-r--r--). Of course, this makes updating impossible. I attempted to use a simple chmod();, however, the script didnt have the permissions to do this. I couldnt figure out a way to fix this, so I moved on to looking for other solutions. I ended up with somethign that worked, slightly, but did not provide me with an actual fix due to another problem. I would connect to the folder via local FTP, then using ftp_site run a direct CHMOD on the files. However, in doing this, I feel that the script itself is insecure. Also, it didnt work in the end. After running the update script, to test out my new solution, I was confronted with a new problem that I didnt understand. The FTP command returned "Bad File Descriptor" after executing the CHMOD. After attempting in a few other of my own FTP clients, I ran into -exactly- the same problem. My questions are this: A) Is there any way to set the permissions on the file on creation of the image? B) If no, is there a way I can do the CHMOD, even though chmod(); returned insufficient permissions to do so? C) If no, is there a way I can fix the bad file descriptor, to fix the ftp solution I have? Any other solutions would be able as well, given that they're somewhat secure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Session variables are not stored when set in implicitly calledconstructor!??
Hallo again, thank You for Your response. > > > > // singleton for request > > class Request { > > function __destructor() { > > $_SESSION["variable"] = "hallo"; > > The __destructor() method is supposed to be about killing the class > (Request). It's probably bad practice to be changing $_SESSION vars > inside of there even if that $_SESSION var affects your class. Here, > read this page and maybe it will make more sense to you: > http://php.net/manual/en/language.oop5.decon.php i agree that in *most* cases destructor should only clean up after object. unfortunatly for "request" class there are few requirements: 1) must allow immidiate use w/o any explicit initialization or finalizaion. e.g. at any file You can use only Request::getInstance()->isRefresh() /** test if this request was caused by browser refresh */. this should be one and only line (except for inclusion of request.php oc) referencing request class -- no explicit call to Request::saveToSession() or anything ugly and potentialy disastrous like that. 2) must provide mechanism for generating per session uniqe request identiers. now implemented as md5($_SESSION["next_reqest_id"]++) not very effective but handy:-P 3) must be serializable (this is why i can not put that session manipulation at __sleep function) these requirements (1,3) cast out __destruct, __sleep and explicit call to some saveToSession function. do You have any other idea when to store this information , please? > Heck, look at the user contributed notes since one of them will directly > affect this idea of yours. *doh* i don't know how could i coverlooke taht user reaction:-( thank You. > If the reference count for $req is greater than 0 (i.e. there is a > Singleton) then __destruct won't be called. And why should it be > called? Because, again, __destruct is for cleaning up the class while > the object is getting destroyed. Isn't __destruct is called even if reference count is gr then zero as a part of script finalization? imo yes -- i tried this with echoing something within singletons destructor (no invoke with explicit delete:-) and it worked. BR a3c - Original Messages - > Hallo everybody, > hope I am writing to correct mailinglist(^_^*)... Absolutely! > I have troubles with sessions and descructor in php5. Can not set session > variable in destructor when it's called implicitly. Do You know solution > please? > I think problem is that session is stored before imlicit object destruction > *doh* > > example.php: > session_start(); > session_register("variable"); *Note* You don't need to use session_register() if you use $_SESSION. In fact this probably isn't even doing what you think it is. Using $_SESSION indexes is the preferred way to go about using sessions. > > // singleton for request > class Request { > function __destructor() { > $_SESSION["variable"] = "hallo"; The __destructor() method is supposed to be about killing the class (Request). It's probably bad practice to be changing $_SESSION vars inside of there even if that $_SESSION var affects your class. Here, read this page and maybe it will make more sense to you: http://php.net/manual/en/language.oop5.decon.php Heck, look at the user contributed notes since one of them will directly affect this idea of yours. > } > } > > $req = Request::getInstance(); > $req->doSomeThink(); > echo "This should be hallo 2nd time: " . $_SESSION["variable"];// > unfortunatly this is not set > echo " Click and cry;-("; > // implicit desturctor call If the reference count for $req is greater than 0 (i.e. there is a Singleton) then __destruct won't be called. And why should it be called? Because, again, __destruct is for cleaning up the class while the object is getting destroyed. > ?> smime.p7s Description: S/MIME cryptographic signature
[PHP] Session variables are not stored when set in implicitly called constructor!??
Hallo everybody, hope I am writing to correct mailinglist(^_^*)... I have troubles with sessions and descructor in php5. Can not set session variable in destructor when it's called implicitly. Do You know solution please? I think problem is that session is stored before imlicit object destruction *doh* example.php: doSomeThink(); echo "This should be hallo 2nd time: " . $_SESSION["variable"];// unfortunatly this is not set echo " Click and cry;-("; // implicit desturctor call ?> Thank You very much... BR a3c -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Redirection after login with security
Synopsis: I am writing a management system for a MSSql database driven game, and I've run into an issue. The community site is located on a remote webserver, to protect the actual server from any possible vulnerabilities in the community application/forum application (as we all have seen the recent issues with phpBB and various CMS systems). The management system grants the ability to access and modify various properties of your in-game account. In an attempt to provide the best way to limit the # of accounts per person, I assumed that this could be accomplished by placing a dummy value only used by the site itself that is the username/encoded password for them on the community, and test if... when searched for in the database, a result set of x is discovered, then they are unable to create another account. Problem: I would like to possibly utilize a login system (created on the remote server), that would then check their username and password against the CMS database located there, then redirect with that information (encrypted of course), to the local site where the information gets stored in a session. Then when they go to create a new account, it stores the extra verfied information into the database. However, the issue at hand here is, I'm not sure how secure it would be if I were to say, create a secure login form, verify the data... and then create another pseudo form that directs the person to the local-based site using hidden post variables (this is my original thought on the subject). Is there another way I could go about doing this (ie, a way that I could identify a user that is almost assuredly never going to change) or is there a more secure way? Or, am I on the right track? Thanks for any help! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Socket_connect producing errors that show no reason
Jochem Maas wrote: Adam Hubscher wrote: The code looks like this: if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); } socket_set_option($sock, SOL_SOCKET,SO_RCVTIMEO, array('sec' => 1, 'usec' => 0)); $output = ''; for($i = 0; $i < count($file); $i++){ $servernum = $file[$i]; $i++; $servername = $file[$i]; $serverport = $file2[$i]; $serverport = preg_replace('/\s/','',$serverport); // Test if server online - if not, output offline. If yes, output Online. if(!socket_connect($sock, $ip, $mapport)){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debug $output .= "Server Name: " . $servername. " ~~ Offline "; continue; } else{ $output .= "Server Name: " . $servername. " ~~ Online "; } } My problem now is that as it runs through the loop - it has a connection error. Warning: socket_connect() [function.socket-connect]: unable to connect [106]: Transport endpoint is already connected in status.php on line 17 maybe you should close the socket before trying to open it again? also where is $ip being set? Even looking at examples, I cannot figure out why this error is being produced. I cannot close the socket at the end of the loop, as it would make any further attempts for online status impossible. The socket_close($sock) is directly after the loop. Thanks for any help! Hm. Thats interesting. I attempted that the other day, however at that time it produced results that are... very similar to an infinite loop (continuously "loading page" on status bar, and when I hit stop the page had nothing loaded). I expected it to be the same - however it worked this time, beautifully in fact. Thanks, you pushed me to try a second time :P Thats interesting as well, however... I consulted one of my PHP books for when I was learning the changes in PHP5 and looked at the example for socket_connect, it shows an example for querying the Return to Castle Wolfenstein master server, storing the data in an array, and then without utilizing socket_close in any of the loops - it continues to conect to each server and query it for its status (players, settings, etc). That is why I didnt see much error in my code - the example showed it to be correct in my eyes. Anyways, yea, thanks for the help! ($ip was set just above that codeblock, for testing purposes I was using a local IP - 192.168.1.68 to test for functionality.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket_connect producing errors that show no reason
The code looks like this: if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); } socket_set_option($sock, SOL_SOCKET,SO_RCVTIMEO, array('sec' => 1, 'usec' => 0)); $output = ''; for($i = 0; $i < count($file); $i++){ $servernum = $file[$i]; $i++; $servername = $file[$i]; $serverport = $file2[$i]; $serverport = preg_replace('/\s/','',$serverport); // Test if server online - if not, output offline. If yes, output Online. if(!socket_connect($sock, $ip, $mapport)){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debug $output .= "Server Name: " . $servername. " ~~ Offline "; continue; } else{ $output .= "Server Name: " . $servername. " ~~ Online "; } } My problem now is that as it runs through the loop - it has a connection error. Warning: socket_connect() [function.socket-connect]: unable to connect [106]: Transport endpoint is already connected in status.php on line 17 Even looking at examples, I cannot figure out why this error is being produced. I cannot close the socket at the end of the loop, as it would make any further attempts for online status impossible. The socket_close($sock) is directly after the loop. Thanks for any help! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: $_POST
Andrew Maxwell wrote: When you submit something, and you want to make sure that the user inputs all of the info, is there an easier way to do it than this: if ((!$_POST[name]) || !$_POST[pass]) || (!$_POST[blah])) { etc. } is there an easy way to check if all of the varibles have data in them? ~Andrew Well, you could use a simple foreach: foreach ($_POST as $key => $value){ if($value === '') { print("You must fill in all the values");} else{continue;} } I'm not sure if empty($value); would work, but its worth a try. You could however use it, within the foreach by doing: empty($_POST[$key]); (if $key = name, it would test $_POST[$name] whether it is empty or not). http://us2.php.net/manual/en/function.empty.php I would assume that empty() would work in this case eitherway, and is most likely your best bet. However, within this function it may also be smart to include a few form validation rules for the security of your form as well. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Socket_Connect returning unusual error
Richard Lynch wrote: Adam Hubscher wrote: Warning: socket_connect() expects parameter 3 to be long, string given in testing.php on line 21 Couldn't Create Socket: Success PHP usually auto-converts data -- However it's possible that this EXPERIMENTAL function (?) doesn't have the magic code down in the guts of PHP. So, try type-casting your third parameter to an (int): $currport = $servers[$key]['Port']; // was attempting this to see $currport = (int) $servers[$key]['Port']; echo "currport is: '$currport'\n"; If this fixes it, file a bug report at http://bugs.php.net -- search for the same issue first. It should get fixed pretty quick-like (relatively speaking) if that's all it is. It's also possible that your 'Port' is empty or something... That's why I included the 'echo' -- Always hand-check the data you are sending when weird things happen. One line of debugging output can save hours of time and fistfuls of hair. I actually fixed it by using a simple preg_replace to remove any returns/spaces. It was actually imported from a text file and I forgot to clean up any excess characters taht could still exist. However,now I get the error: Couldn't Create Socket: Transport endpoint is already connected after it successfully connects once already. The new code is found in my other post (socket_connect errors), but for reference: if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); } socket_set_option($sock, SOL_SOCKET,SO_RCVTIMEO, array('sec' => 1, 'usec' => 0)); $output = ''; for($i = 0; $i < count($file); $i++){ $servernum = $file[$i]; $i++; $servername = $file[$i]; $serverport = $file2[$i]; $serverport = preg_replace('/\s/','',$serverport); // Test if server online - if not, output offline. If yes, output Online. if(!socket_connect($sock, $ip, $mapport)){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debug $output .= "Server Name: " . $servername. " ~~ Offline "; continue; } else{ $output .= "Server Name: " . $servername. " ~~ Online "; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] socket_connect errors
Ok, I had made a post earlier but bout 5min later I figured out the problem (I had spaces and returns that were in the array beside the ports). The code looks like this: if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); } socket_set_option($sock, SOL_SOCKET,SO_RCVTIMEO, array('sec' => 1, 'usec' => 0)); $output = ''; for($i = 0; $i < count($file); $i++){ $servernum = $file[$i]; $i++; $servername = $file[$i]; $serverport = $file2[$i]; $serverport = preg_replace('/\s/','',$serverport); // Test if server online - if not, output offline. If yes, output Online. if(!socket_connect($sock, $ip, $mapport)){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debug $output .= "Server Name: " . $servername. " ~~ Offline "; continue; } else{ $output .= "Server Name: " . $servername. " ~~ Online "; } } My problem now is that as it runs through the loop - it has a connection error. Warning: socket_connect() [function.socket-connect]: unable to connect [106]: Transport endpoint is already connected in status.php on line 17 Even looking at examples, I cannot figure out why this error is being produced. I cannot close the socket at the end of the loop, as it would make any further attempts for online status impossible. The socket_close($sock) is directly after the loop. Thanks for any help! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket_Connect returning unusual error
Warning: socket_connect() expects parameter 3 to be long, string given in testing.php on line 21 Couldn't Create Socket: Success It actually spits that across for every socket I'm trying to connect. I'm doing an online status for multiple servers, which I have tested to work when I simply do a socket_connect($sock,$url,$port); on the port numbers of the various servers. The servers all reside on the same IP address. The script actually works manually, ie if i put the actual port in to the socket_connect function call. However, as soon as I put the variable in - it wont work. The code looks like so: foreach ($servers as $key => $value){ $currport = $servers[$key]['Port']; // was attempting this to see if it would work - it did not either. Normally tried $servers[$key]['Port'] directly. if(!socket_connect($sock, $ip, $currport)){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debugging purposes $output .= "Server Name: " . $Servers[$key]['Name']. " ~~ Offline "; } else{ $output .= "Server Name: " . $Servers[$key]['Name']. " ~~ Online "; } } I cant quite find anything that is... actually wrong with the code. I dont understand the error all that much either, as it says "Success" in it. Needless to say - I'm thoroughly confused! Anyone help me out? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] socket_connect giving me weird error
Warning: socket_connect() expects parameter 3 to be long, string given in testing.php on line 21 Couldn't Create Socket: Success It actually spits that across for every socket I'm trying to connect. I'm doing an online status for multiple servers, which I have tested to work when I simply do a socket_connect($sock,$url,$port); on the port numbers of the various servers. The servers all reside on the same IP address. The script actually works manually, ie if i put the actual port in to the socket_connect function call. However, as soon as I put the variable in - it wont work. The code looks like so: foreach ($servers as $key => $value){ $currport = $servers[$key]['Port']; // was attempting this to see if it would work - it did not either. Normally tried $servers[$key]['Port'] directly. if(!socket_connect($sock, 'rmoff.ath.cx', $currport)){ print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debugging purposes $output .= "Server Name: " . $Servers[$key]['Name']. " ~~ Offline "; } else{ $output .= "Server Name: " . $Servers[$key]['Name']. " ~~ Online "; } } I cant quite find anything that is... actually wrong with the code. I dont understand the error all that much either, as it says "Success" in it. Needless to say - I'm thoroughly confused! Anyone help me out? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preventing execution without inclusion
Thomas Goyne wrote: On Thu, 13 Jan 2005 16:25:30 -0600, Adam Hubscher <[EMAIL PROTECTED]> wrote: 1 (the preferred way): user accesses http://www.example.org/index.php?function=Join, this loads the class NewUser and begins its implementation. Because of the __autoload, it includes class.join.php, in order to utilize the class. 2 (the wrong way): user accesses http://www.example.org/includes/class.join.php without going through index.php. I am trying to prevent 2 from even occuring, utilizing a piece of code that would check if index.php had included it, or not. This code would be in the beginning of all the class files, at the top, before any othercode was to be executed. Ideally, you'd put all of the files users aren't supposed to access outside of the document root, so there just isn't a uri that points to the file. If (as your question makes it sound) the includes do nothing but define a class, and don't actually run any code, then it really doesn't matter if users directly access an include, as nothing will happen. Ok, thats what I expected to be the case - I was just being cautious. Unfortunately with what the application is providing for (a game server), there is a large userbase of people that would potentially do anything in their power... or learning ability, to inflict harm upon the users and the database of the site/game server which I am running. Security has been my primary lack-of-sleep for the last few days, and this was one of the last things eluding me. Thank you very much Thomas! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preventing execution without inclusion
From within the application, I use one page to include classes/variables and so on. Is there a way (I may have been missing it in the documentation for PHP, however I didnt see anything related) to prevent a user from directly accessing/executing *.php by the file making sure taht it was only included by index.php? For example: config.php defines: function __autoload($class_name) { $class_name = strtolower($class_name); include_once('class.'.$class_name.'.php'); } as per PHP5 example 1 (the preferred way): user accesses http://www.example.org/index.php?function=Join, this loads the class NewUser and begins its implementation. Because of the __autoload, it includes class.join.php, in order to utilize the class. 2 (the wrong way): user accesses http://www.example.org/includes/class.join.php without going through index.php. I am trying to prevent 2 from even occuring, utilizing a piece of code that would check if index.php had included it, or not. This code would be in the beginning of all the class files, at the top, before any other code was to be executed. As of yet, it has eluded me... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-XML-DEV] DomXPath and default XML namespaces
On Mon, 13 Dec 2004, Dan Phiffer wrote: > Adam Maccabee Trachtenberg wrote: > > > This is an XPath FAQ. Without a ns prefix, XPath doesn't choose > > elements living in the default ns, but ones living in no namespace. > > Are there any good references you might point me to? I'm pretty new to > this stuff and beyond my "in a Nutshell" book don't have many places to > consult yet. Nothing good I can think of off hand besides the spec. That's really the only tricky XPath gotcha, however. -adam -- [EMAIL PROTECTED] | http://www.trachtenberg.com author of o'reilly's "upgrading to php 5" and "php cookbook" avoid the holiday rush, buy your copies today! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-XML-DEV] DomXPath and default XML namespaces
On Mon, 13 Dec 2004, Dan Phiffer wrote: > I guess what I would expect to work is to allow for blank values as the > first argument to registerNamespace, representing the default namespace, > but that causes the queries to always return no matches. Is there > something I'm missing with this? This is an XPath FAQ. Without a ns prefix, XPath doesn't choose elements living in the default ns, but ones living in no namespace. Otherwise, you have problems with: What would /root/foo be, the first, the second, both? And if this example is resolvable, what happens to: And /root/foo/qxx? Do you select qxx in the default ns? Or not? -adam -- [EMAIL PROTECTED] | http://www.trachtenberg.com author of o'reilly's "upgrading to php 5" and "php cookbook" avoid the holiday rush, buy your copies today! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] grabbing source of a URL
Hi, I don't know what functions to use so maybe someone can help me out. I want to grab a URL's source (all the code from a link) and then cut out a block of text from it, throw it away, and then show the page. For example, if I have page.html with 3 lines: hi this is line a this is line b this is line c i want my php script to grab the source of page.html, strip out: this is line a and then display what is left, how would I go about doing this? I don't know what function to use to grab the page. for the string to remove, I know I can probably do a str_replace and replace the known code with nothing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: [SOLVED][PHP] Re: simple mail() question
Hi Manuel, That was *exactly* the issue. I can't express my gratitude for the assistance enough -Adam Original Message Follows From: Manuel Lemos <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Subject: [PHP] Re: simple mail() question Date: Sat, 13 Nov 2004 19:21:18 -0200 Hello, On 11/13/2004 04:28 PM, Adam Fleming wrote: Hello All, I have a simple mail() question, and I hope a hero can shed some light. I can't understand why my messages are being encoded, and extra headers are being added, *before* the message is sent through sendmail. It seems that you have mbstring.func_overload set to an odd number making mail be overloaded by mb_send_mail. Actually the way those messages go they will be blocked by most modern spam filters. So, I would say mb_send_mail is buggy, meaning do not use it. -- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html -- 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] simple mail() question
Hello All, I have a simple mail() question, and I hope a hero can shed some light. I can't understand why my messages are being encoded, and extra headers are being added, *before* the message is sent through sendmail. Infinite Thanks, Adam Input: $more test.php Expected Result: $php -d sendmail_path=/bin/cat test.php To: [EMAIL PROTECTED] Subject: subject Content-Type: text/plain; charset=us-ascii body Actual Result: $php -d sendmail_path=/bin/cat test.php To: [EMAIL PROTECTED] Subject: subject Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: BASE64 Ym9keQ== -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] stripping text from a string
Hi, I use a piece of proprietary software at work that uses weird session ID strings in the URL. A sample URL looks like: http://zed2.mdah.state.ms.us/F/CC8V7H1JF4LNBVP5KARL4KGE8AHIKP1I72JSBG6AYQSMK8YF4Y-01471?func=find-b-0 The weird session ID string changes each time you login. Anyway, how can I strip out all of the text between the last / and the ? and insert it into another variable? So in this case, the end result would be a variable containing: CC8V7H1JF4LNBVP5KARL4KGE8AHIKP1I72JSBG6AYQSMK8YF4Y-01471 thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Good Class/API Design ?
Hey all, I just got my hands on the excellent books PHP Anthology 1 & 2 and am wanting to start playing around with classes. My question to the list is, what, in your opinion, constitutes good class/api design? Is it better to design several smaller classes that each focus on one task and do that task well, or to build more general classes that handle a number of related tasks? Also, when you are beginning a new project, what methods do you find helpful to follow in taking your project from concept to finished? The books also mention ways to use phpDocumentor to document your code and SimpleTest to test your code as it is written. These along with some XP techniques I read about seem like good practices to follow. Does anyone have any other ideas/practices that it would be good for a new oop developer like myself to make a habit it of? Thanks!! -- Adam Reiswig "Accelerating into the unknown..." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fopen and http://
On Fri, 8 Oct 2004, Hendrik Schmieder wrote: > What say phpinfo about Registered PHP Streams ? > >Hendrik > > Hi, I think I just figured out my problem...I had to use rtrim($line) because I think there was a \n or an invisible character at the end of the line that was being passed to the http:// server from looking at the server's access_log and error_log files. So now it works except on the very last line it processes, it prints "does not exist", so there is still some sort of a hidden character but its not affecting fetching the URLs from the web server. so i'm still trying to figure that last line out, but everything else works. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fopen and http://
On Fri, 8 Oct 2004, Matt M. wrote: > > But I don't understand why I am getting that error about failed to open > > strem: HTTP request failed, when I can bring up the links fine in a > > browser on the server running the php script. So can anyone help me out? > > Thanks > > do you have allow_url_fopen enabled? > > http://us4.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen > > Yes I do, in my php.ini I have: ;; ; Fopen wrappers ; ;; ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. allow_url_fopen = On -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fopen and http://
Hi, I'm having a problem with fopen and http files. I keep getting the error: Warning: fopen(http://zed/htdocs/rgfindingaids/series594.html ) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/awilliam/public_html/rgfaidstest.php on line 15 http://zed/htdocs/rgfindingaids/series594.html does not exist Warning: fopen(http://zed/htdocs/rgfindingaids/ser391.html ) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/awilliam/public_html/rgfaidstest.php on line 15 http://zed/htdocs/rgfindingaids/ser391.html does not exist Warning: fopen(http://zed/htdocs/rgfindingaids/ser392.html ) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/awilliam/public_html/rgfaidstest.php on line 15 http://zed/htdocs/rgfindingaids/ser392.html does not exist I have a text file /home/awilliam/public_html/rgfaids containing URLs such as: http://zed/htdocs/rgfindingaids/series594.html http://zed/htdocs/rgfindingaids/ser391.html http://zed/htdocs/rgfindingaids/ser392.html and I can bring up these URLs fine in a browser on the PC i'm running the script on. The following is my code: "; } elseif ($filetotest) { echo "$line does exist"; } } ?> But I don't understand why I am getting that error about failed to open strem: HTTP request failed, when I can bring up the links fine in a browser on the server running the php script. So can anyone help me out? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] opposite of array_unique()?
array_unique() removes duplicate values from an array. Is there an opposite function or way of keeping all values in a single dimentional array that are duplicates and removing all that are duplicates? for example if I have an array: array( [0] => 'dog', [1] => 'cat', [2] => 'rabbit', [3] => 'cat') how do I make it just have array ( [0] => 'cat' )? i want to drop the non-duplicates and trim the array to only have one of the duplicates? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php