[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]br /\n; } for (reset($logicalDrive); $i = key($logicalDrive); next($logicalDrive)) { echo $i: $logicalDrive[$i]br /\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] 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: 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?
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: 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?
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
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 the user is sitting on a LAN with no gateway, no connection to the internet except a single proxy server, they should still be able to make a TCP/IP connection by tunneling
[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?
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: 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 = p . str_replace(\r\n, /p\np, $text) . /p\n; echo $content; The problem is that I want to give the users the ability to add text that will be converted to h3 tags. I figure the best and easiest way to do this is give them some text markers, like --++ and ++-- that can be converted to h3 and /h3 respectively. So I guess I do: $content = str_replace(--++, h3, $text); $content1 = str_replace(++--, /h3, $content); $content2 = p . str_replace(\r\n, /p\np, $content1) . /p\n; echo $content2; But of course a user is likely to put their h3 heading at the beginning of their text. Which would generate: ph3Heading/h3text text text/p That's not good. What I need is: h3Heading/h3ptext text text/p 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 p tag at the beginning. As well as h3 tags, there may also be things such as images and hr 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 p 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 br /. 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(--++, h3, $text); $text = str_replace(++--, /h3, $text); $text = p . str_replace(\r\n, /p\np, $text) . /p\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(--++, h3, $text); $text = str_replace(++--, /h3, $text); $text = str_replace(\r\n, br /\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(h3, /h3, br /\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(h3, /h3, br /\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] 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
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
[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] 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: 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] 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: !-- index.php -- ? ob_start(); ? html head.../head body ? include ($subPage); ob_end_flush(); ? /body 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
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] ob_flush() problems
Brad Bonkoski wrote: cajbecu wrote: Hello, for ($i=0; $i 10; $i++) { $output = ccc2; print pre; echo $output; print /pre; 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] 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] 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
[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 : SELECT title='navigation' Name=navigating onChange=self.location = '/s/2318355/'+ this.options[this.selectedIndex].value + '/';option value=1 selected1. Nameoption value=2 2. Name/select 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 select/select blocks, and then for each match do another regular expression match to grab all the option 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
[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: 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
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: 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: snip snip 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 ?php class Folio implements Iterator { private $projects = array(); private $valid = FALSE; public function __construct($file = null) { if(!is_null($file)) $this-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 'a href='.$this-small_href().' title='.$this-small_title().''.$this-small_img($x).'/a'; } } ? ?php reset($folio-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
[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
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
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 $paritybr /\n; Let's make it even more compact and confusing :) echo $variable is .($variable % 2 ?'even':'odd').br /\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] 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] 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
[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
[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
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
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
[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
[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: 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: 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: 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: 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: 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
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: 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
[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
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; $i100; $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
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 php-general@lists.php.net 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
[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
[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
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 . br /; $result = mysql_query($query); $data = mysql_fetch_array($result); return $data; } foreach($elements as $key = $val){ echo val[type] = . $val[type] . br /; echo val[resource] = . $val[resource] . br /; } 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'] . br /; echo $row['bar'] . br /; 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 isquot;brvbar;bringing in these large chains is putting the xml doc points to the in ;brvbar 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, quot;. You want to do a search/replace for brvbar; And brvbar; 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 brvbar; 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] 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: 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
[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: 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: A variable inside a variable?
Alex Major wrote: Thanks for your help with my other question, heres a new one for you. I need to nest a variable, inside another variable. For example: $($buildingname)level How (if at all) is this possible? Thanks. Alex. Why? What are you doing that requires that that cannot be done with associative arrays? As in, what is wrong with: $level[$buildingname] (I'm only guessing at the correct naming scheme) Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preventing double-clicks APPEARS TO WORK FINE
John Meyer wrote: Jay Blanchard wrote: [snip] I am going to do some thinking (typing) out loud here because I need to come up with a solution to double-clicking on a form button issue. [/snip] Isn't there a javascript method that you could use to accomplish the same thing? Either that, or on the first click, you could disable that button. JavaScript can't be used for such things, or at least it can't be relied upon. What if the user has disabled JavaScript? Or what if the user has specifically disabled the JavaScript behaviour you are relying on? For example, some websites very wrongly try to disable right-clicking on webpages. Firefox provides an option (I'm not sure if it is enabled by default) that prevents pages from disabling right-click. So using said JavaScript code to disable right-clicks is not a valid way of preventing people from viewing page source or downloading files. The same would apply to any other security measure; it'd be just fine to use JavaScript to discourage multiple clicks, but it wouldn't solve the underlying problem; he'd still have to solve the problem on the backend. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: modify xml before parse
weetat wrote: Hi all, I need to read xml file before it was parsed by PHP DOM functions. The xml file have some encrypted value as shown below : InstanceName![CDATA[ù?¸ü÷úù?àù?ØZ4ÀÏ]]/InstanceName Anybody have any suggestion how to do it ? Thanks. - weetat $xmlfile = file_get_contents(http://urloffile.com/filename.xml;); I mean, that is what you asked, how to read the xml file... Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Calculations
Alex Major wrote: Hi there list. Thanks for your help with my other questions. I was carrying on working through, and stumbled across a problem when trying to times something by the 'power' of something. By this I mean..in maths you can write 3 * (2 ^ 3), the answer to which would be 24. (as 2 ^ 3 = 8). The reason that I need this, is because I'm trying to double a variable x amount of times (x is set by another variable). For example my code is: $cost = $farm_cost * (2 ^ $farm_level); Any ideas how I would go about changing my calculation, as php dosn't seem to recognise ^ meaning 'to the power of'. Regards, Alex. ... The manual is your friend. Seriously, don't come here looking for all the answers before you checked the manual. I searched for power, and the first result was the function you want. RTFM. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculations
tedd wrote: At 2:30 PM -0400 6/27/06, Kristen G. Thorson wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 27, 2006 2:11 PM To: php-general@lists.php.net Subject: Re: [PHP] Calculations When my level of free time matches my level of curiousity, I'll have to research it further. For now, I'm ok with not knowing unless someone posts the answer here. hah -TG Lucky day. ;) http://www.php.net/manual/en/language.operators.bitwise.php kgt Thanks. I wonder why that's true for php when it's common to use ^ in many other languages for powers? I can't remember the last time I used a bitwise operator for anything, but I have commonly used powers for the type of work I've done. But then again, I may be an exception. tedd Lots of functions still use bit-based flags in PHP. Which is where OR comes in handy. Can't say I've used the others recently. XOR is handy on occasion, but doesn't really need an operator. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: modify xml before parse
weetat wrote: Hi Adam, Thank for your input. However search and replace the value such as ![CDATA[ù?¸ü÷úù?àù?ØZ4ÀÏ]] to empty string ? Try the code below , no successful. $xmlfile = /home/gvintranet/datacraft/htdocs/properties/test_cdata.xml; $xml = file_get_contents($xmlfile); $xml = preg_replace('/HardwareVersion[^(\\/HardwareVersion)]\\/HardwareVersion/', 'HardwareVersion\/HardwareVersion', $xml); fwrite(fopen($xmlfile, 'wb'), $xml); Thanks - weetat Adam Zey wrote: weetat wrote: Hi all, I need to read xml file before it was parsed by PHP DOM functions. The xml file have some encrypted value as shown below : InstanceName![CDATA[ù?¸ü÷úù?àù?ØZ4ÀÏ]]/InstanceName Anybody have any suggestion how to do it ? Thanks. - weetat $xmlfile = file_get_contents(http://urloffile.com/filename.xml;); I mean, that is what you asked, how to read the xml file... Regards, Adam Zey. Why not: $xml = preg_replace(/!\\[CDATA\\[.+?\\]\\]/, , $xml); (Keep in mind I wrote that regex for RegexCoach and then tried to translate it to PHP, might be some mistakes) Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serve long duration pages
Jochem Maas wrote: John Gunther wrote: This may be more appropriate for an Apache or browser forum. Perhaps you can suggest an appropriate one. I have a PHP script that takes a long time to complete (due to very heavy database activity) although it echoes unbuffered output every few seconds. I've set max_execution_time to 0 with set_time_limit(0) so PHP doesn't time out the page but after about 3 minutes, Firefox says, The connection to the server was reset while the page was loading. and IE7 says, Internet Explorer cannot display the web page. I want to try apache_reset_timeout() but it's not implemented in 4.3.10. Is there anything I can do from PHP or elsewhere to solve this? yes. lets start by saying that any webpage script that takes that long to run is shit by design. what I would suggest is that you run a script via cron that generates a static page which you can then view whenever required; let the cron job run at what ever interval is required/possible. your database maybe be in bad shape - check you have indexes on all the fields your searching/joining on (as a first step) another alternative would be to break down the output of the script into several pages. sorry I don't have a real solution with regard to forcing the browser to keep suckig on the connection. maybe someone else with more fu does. John Gunther Bucks vs Bytes Inc You can run DB queries asynchronously and periodically send invisible HTML (IE, font/font) to the browser every few seconds. But Jochem is right, there are exactly zero cases in which a web application should have page times measured in minutes. At that point, you're doing something wrong. Either your database is poorly designed and needs optimization, or you need to look into how you deliver data to the client. Even if a page is meant for internal use, if it takes longer than a second or two to load, I usually start looking into optimizing or another way of getting the data. I often spin big operations off into cron jobs so that the data or operation is already available by the time a user loads the page. Looking into the database angle, even complex queries against databases with millions of rows should happen almost instantaneously with proper indexes and structure. I used to run a site that had about 15 thousand rows. A single table, very simple queries. And yet, those queries started taking several SECONDS to accomplish as the table grew. By the simple act of throwing in a few well placed indexes, times dropped from seconds to milliseconds, improving by orders of magnitude. I further sped things up using the MySQL query cache, and by doing all my SELECT queries against a HEAP table (a MySQL table stored entirely in memory), while updates and inserts went to disk and then were mirrored back into the HEAP table. There are so many ways to optimize databases, it's insane. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] serve long duration pages
John Gunther wrote: You're right sads (self-administered dope slap), my task is really not a web function except for the need to trigger it from an admin page. I'm going to use the PHP command line interface to run it without web interaction. However, there are still situations where a web script may sometimes involve long run times depending on the parameters supplied by the user (an example might be a SQL execution page where the user-supplied query could range from simple to very complex). I'd still like to know how to communicate via PHP that I want an infinite timeout for a particular web page.. lets start by saying that any webpage script that takes that long to run is shit by design. John As I said, have you tried outputting a constant stream of invisible HTML such as 'b/b'? Spit one of those out every second or so and the browser might be happy. You'd have to do the query asynchronously, though, since you'd need to output the tags while it was executing. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: modify xml before parse
Yeo Wee Tat wrote: Hi Adam, I can modify the xml file without any error , however when I tried to unserializer the xml file using PEAR:XML , it gave the error message below. I have attached my code for your perusal. Any ideas ? thanks ?php ini_set('display_errors', E_ALL); require_once '../library/config.php'; require_once '../library/class.XMLUtil.php'; $xmlfile = /home/gvintranet/datacraft/htdocs/uploads/cisco.xml; $xml = preg_replace(/!\\[CDATA\\[.+?\\]\\]/, ![CDATA[ignore_this]], $xml); $filehandle = fopen($xmlfile, 'wb'); $ok = fwrite($filehandle,$xml); echo ok.$ok; $options = array(complexType = object); $xml_util = new XMLUtil($xmlfile, $options); $xml_util-unserializer_XML(true); $data = $xml_util-getUnserializedData(); echo print_r($data); ? error message: pear_error Object ( [error_message_prefix] = [mode] = 1 [level] = 1024 [code] = 151 [message] = No unserialized data available. Use XML_Unserializer::unserialize() first. [userinfo] = [backtrace] = Array ( [0] = Array ( [file] = /usr/share/pear/PEAR.php [line] = 566 [function] = pear_error [class] = pear_error [type] = - [args] = Array ( [0] = No unserialized data available. Use XML_Unserializer::unserialize() first. [1] = 151 [2] = 1 [3] = 1024 [4] = ) ) [1] = Array ( [file] = /usr/share/pear/XML/Unserializer.php [line] = 489 [function] = raiseerror [class] = xml_unserializer [type] = - [args] = Array ( [0] = No unserialized data available. Use XML_Unserializer::unserialize() first. [1] = 151 ) ) [2] = Array ( [file] = /home/gvintranet/datacraft/htdocs/library/class.XMLUtil.php [line] = 54 [function] = getunserializeddata [class] = xml_unserializer [type] = - [args] = Array ( ) ) [3] = Array ( [file] = /home/gvintranet/datacraft/htdocs/admin/test_regex.php [line] = 43 [function] = getunserializeddata [class] = xmlutil [type] = - [args] = Array ( ) ) ) [callback] = ) 1 Yeo Wee Tat Tel: +65-62730049 Fax: +65-62734934 Cxrus Solutions Pte Ltd (Singapore . Thailand) 1003 Bukit Merah Central #05-20 Singapore 159836 System Integration . Business Solutions . Linux Simplified I must admit, I've never used Pear for anything (I stick to SimpleXML myself). Perhaps it doesn't like the new cdata tag you're writing? Have you tried replacing the entire cdata tag with an empty string, or trying another XML parser (like SimpleXML) just to see if the trouble is with your XML or Pear? Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: creating a threaded message system--sorting messages
Ben Liu wrote: This question might deviate from PHP into the domain of MySQL but I thought best to post here first. I'm building a message board system with PHP/MySQL. I'm trying to present the messages to the users in threaded order rather than flat. I'm having a lot of trouble figuring out how to sort the posts so they appear in the correct threaded order. I don't think I can do this purely with a SQL query. If it can be done this way, please suggest how and I'll take this question to the MySQL list. I think I have figured out the basic logic, I just have no idea how to translate it into code. Also, I may have the logic wrong. Anyhow this is what I have so far: relevant data structure loosely: post_id (unique, autoincrement, primary index) parent_id (if the post is a child, this field contains the post_id of its parent) ... 1) Query the database for all messages under a certain topic, sort by parent_id then post_id 2) Somehow resort the data so that each group of children is directly after their parent. Do this in order of ascending parent_id. Can this be done with usort() and some programatic logic/algorithm? How do you sort groups of items together rather than comparing each array element to the next array element (ie: sorting one item at a time)? Should this be done with a recursive algorithm? Anyone with experience writing code for this type of message board, or implementing existing code? Thanks for any help in advance. - Ben Just throwing an idea out there, but you can do the sorting entirely in the SQL query. The trick is to figure out the best way. The first idea that came to mind (and it sucks, but it works), is a text field with padded numbers separated by dots, and the number is the position in relation to the parent. So, with this: Post 1 Post 3 Post 5 Post 6 Post 4 Post 7 Post 2 Post 8 Now, to the helper field would contain this for each post: Post 1: 1 Post 2: 2 Post 3: 1.1 Post 4: 1.2 Post 5: 1.1.1 Post 6: 1.1.2 Post 7: 1.2.1 Post 8: 2.1 Now, by pure ascii sorting in that field, that would sort out to: Post 1: 1 Post 3: 1.1 Post 5: 1.1.1 Post 6: 1.1.2 Post 4: 1.2 Post 7: 1.2.1 Post 2: 2 Post 8: 2.1 Which is the correct sort order. The depth of the post (how far to indent it?) could be told in PHP by counting the number of periods, or storing it in the database. Now, how to figure out what to put in that field for each post? We need to do two things. First, each post needs to store the number of children. Next, when a new post is made, we do three things (Keeping in mind that in real life I'd pad each entry in the sort helper field with zeros on the left up to some large number): 1) Get the sort helper field of the parent and the parent's child count field 2) Take the parent's sort help field, and add on a period and the parent's child count plus one, insert the child. 3) Update the parent's child count. OK, now, this method sucks. It's slow, and limits the number of child posts to whatever you pad (In itself, not a big issue, if each post can only have, say, a thousand direct childs (which each themselves can have a thousand childs), not a huge issue). The slow part from ascii sorting everything is the problem, I'd think. I've never done threaded anything before, so I assume there's a better solution. I'm just saying that the job CAN be done entirely with SQL sorting. And probably faster than your proposed method of resorting everything once PHP gets ahold of it. It should be noted that you'd need each post to have a sort of superparent field that stored the topmost parent so that you could do something simple like selecting ten superparents and all their children. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Update site through email
Manuel Lemos wrote: Hello, on 06/29/2006 10:54 AM Rodrigo de Oliveira Costa said the following: Hy guys I'd like to know if there is a way to update a site through sending an email. Something like this, you send an email and the body of the email substitutes a text you use in your site. Igreat apreciate any help since I couldn't find anything on this topic. Sure, you can send a message attaching the files you want to update in your site to an address with a POP3 mailbox and then use a POP3 client to retrieve and parse the message to extract the files to be updated. You may want to try this POP3 client class that you can use for that purpose. It provides a cool feature that lets you retrieve messages from POP3 mailbox using PHP fopen or file_get_contents functions like this: file_get_contents('pop3://user:[EMAIL PROTECTED]/1'); http://www.phpclasses.org/pop3class You can also use this message parser class that lets you process your messages and extract any files easily. http://www.phpclasses.org/mimeparser Take a look at this example that demonstrates how to integrate both classes easily to parse your message structure: http://www.phpclasses.org/browse/file/14695.html I've had to have a perl script reacting to emails and acting on them. I did it using RetchMail (http://open.nit.ca/wiki/?page=RetchMail), which is mindnumbingly fast when you need to download a bunch of emails. As the page says, stupidly fast. As a disclaimer, it's an opensource app maintained by people at my workplace. Still, it's probably the fastest POP3 mail fetcher out there. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: creating a threaded message system--sorting messages
Ben Liu wrote: SOLVED, almost. I read the article suggested by K.Bear and found the recommended solution to be a bit more complicated than I wanted to implement. I then found another way to do this using the existing Adjacency List Model through a recursive function. So basically, you query the database for the post_id of the very first post in the discussion. You then call a function that displays that post, searches for all children of that post and then calls itself recursively on each of the children it discovers. This works great for spitting out the posts in the proper order. Now I'm trying to figure out how to make sure the indenting looks right in the browser. - Ben Wouldn't that involve a separate SQL query for every post? Avoid that at all costs. That's insanely slow and wasteful. Recursive functions have no business using SQL queries. I'd suggest you start looking for a more sane method of doing this. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Find out cookies on a computer?
Peter Lauri wrote: Is it possible to some how find out all cookies on a specific computer and their name and value? I assume not :) /Peter No, because you don't OWN them, therefore you have no right (either technologically or ethically) to see them. Asking such unethical questions on this list is, well, pretty dumb. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: creating a threaded message system--sorting messages
Dan McCullough wrote: I've come into this discussion pretty late so please bear with me if I go over something that has been ruled out. You are trying to print out in a threaded method the first post in a thread followed by each post after that, that is a child/reply to that post. Is that correct? So something like Example 1 Thread1 Post1 Post2 Post3 Post4 . or Example 2 Thread1 Post1 Post2 - reply to post 1 Post3 - reply to post 2 Post4 - reply to post 1 Post5 - reply to post 1 Post6 - reply to post 2 Post7 - reply to post 3 Not a valid example, because there is no guaruntee that the posts are in order. In your example, the order could easily be: Thread 1 Post 1 Post 6 Post 7 Post 2 Post 3 Post 4 Post 5 Since somebody can reply to any leaf in the tree at any time. Example 1 is very common and is the easiest to implement. From what I remember you would need a couple of DB tables for post, post_thread, post_post, thread So for your question thread isnt very relative but I thought I would throw it in. thread { threadid int(11) auto_increment, threadname threadsort ... thread_post { threadid int(11) postid int(11) Tables that serve only to tie two other tables together are a waste. I suggest you look up your normal forms again. But to sum up the reasoning, there is no point to have thread_post because you can simply have a threadid field in the post table, because it's a one-to-many relationship. A post can't belong to more than one thread. post { postid int(11) auto_increment, postname posttext ... post_post postid int(11), postid2 int(11) Same thing, I think. A post can't have more than one parent, so you might as well put the parent id into the post table. Unless you have one post_post row for every parent that a post has. This spams the database like nobody's business, but makes queries easier. Please note I have two kids fighting over the cat, trying to cook dinner and stave off a flood of water from the rising river so the SQL structure is for example. You can get everything in one query from the DB and lay it out based on the id of the post, if you DB is properly indexed and setup and queries are optimized you'll hardly notice a blip when the load gets up. You do not want to be doing multiple queries on a page when one well written query will do the trick. I'm not seeing it. Unless you have a many to many relationship on post_post, you're going to need multiple queries. Unless I'm missing some SQL syntax that allows references to previously found rows. It's been a long while since I did advanced SQL queries. I think your example relies on getting everything in one query by getting all posts with the same threadid, and then sorting by ID, but the problem is that we don't want to sort posts by ID, since a higher ID might could easily go before a post with a lower ID based on where people replied. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: creating a threaded message system--sorting messages
Ben Liu wrote: Thanks to everybody who posted on this thread. I wanted to post back the solution I came up with after removing the DB query from the recursion. In case anyone else is trying to accomplish the same thing, this is how I solved it (criticisms welcome, and note that I have not tested it extensively yet): DB structure table: discussion_posts post_id (auto increment, unique, primary index) parent_id (post_id corresponding to this post's parent) discussion_id (to allow multiple discussions, not required but I added a discussions member_id (to identify the post to the particular member posting the post) table as well to store the discussion description and unique ID for each discussion) dt_posted (date/time the post was posted) subject (title of the particular post) post_text (substance of the post) So the user selects a particular discussion from a list of discussions. We query the database for the post_id of the first post in the discussion requested, this post will have a parent_id of '0' or NULL since it has no parent. We then query the DB for all the posts in the discussion joining the members table using member_id to grab the member's first and last name (or any other member info desired). We order this query info by dt_posted. We then write the contents of our second query into a two-dimensional array ($workArr): while ([EMAIL PROTECTED]($result)) { foreach ($row as $key = $value) { if ($key==post_id) $numerKey=value; $workArr[$key][$numerKey]=$value; } } The processing of the threads into proper order looks like this: function processthread($post_id, $workArr) { echo ul class=\posting\; echo h3{$workArr['subject'][$post_id]} (#{$post_id})/h3\n; echo h4by {$workArr['first_name'][$post_id]} {$workArr['last_name'][$post_id]} .bull; on . fixdate($workArr['dt_posted'][$post_id]) . /h4; echo li{$workArr['post_text'][$post_id]}/li\n; echo h5reply to this/h5; // find all children, call itself on those too foreach ($workArr['post_id'] as $value) { if ($workArr['parent_id'][$value]==$post_id) { processthread($workArr['post_id'][$value], $workArr); } // end if } // foreach echo /ul; } And somewhere in the HTML, where appropriate, the function processthread is called for the first time passing it the $post_id value we determined in the first query (the very first post of the discussion) and the $workArr array. Use of unordered lists for design/layout is helpful here since browsers will by default indent lists within lists and list items within their respective list. This saves some PHP and CSS troubles if one were to use div or p structure instead, as I found out. Apologies for any formatting issues and vagaries about the data structure and variable naming in this post. - Ben I think that will work, but there is one huge improvement you can make. You are making millions of copies of your work array! Not only do you pass the entire array by value recursively, but foreach makes copies of the arrays it loops through! So who knows how many copies of the darned work array are being spawned left and right. This can be a memory leak, consuming lots of memory until it finishes the recursion. The first thing you can do is tell the function the array is to be handled by reference: function processthread($post_id, $workArr) { You never change the work array, I think, so you can just keep referring back to the original. The second thing to do is to make the foreach work on references instead of copies. I actually think that since what we have in our function is now a reference, the foreach WILL NOT copy it. But if it still does, there is always the fallback of doing a foreach on array_keys($workArr). Then each $value would be the key, which you'd use to reference $workArr. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: creating a threaded message system--sorting messages
Ben Liu wrote: The second thing to do is to make the foreach work on references instead of copies. I actually think that since what we have in our function is now a reference, the foreach WILL NOT copy it. Anyone have any ideas on this? Is the foreach loop in fact copying $workArr? And how could we tell (test for it) if it were? I should note that the DEFAULT behaviour of foreach is to make a copy of the array you pass it. What I'm saying is that, now that we're passing it a reference to an array instead of an actual array, is that enough to stop it from copying? The manual seems to indicate that, but is a bit vague. But if it still does, there is always the fallback of doing a foreach on array_keys($workArr). Then each $value would be the key, which you'd use to reference $workArr. I'm sorry, you lost me here a bit. I mean, do this: foreach ( array_keys($workArr) as $key ) { echo $workArr[$key]['foo']; } instead of this: foreach ( $workArr as $key = $value ) { echo $value['foo']; } Both let you do the same thing, you just reference data differently, and the first example involves working with the original array, so foreach has no chance to copy it. HOWEVER, if my above supposition about foreach not copying a reference is correct, you wouldn't need to do this. It's just a backup plan. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Update or add?
Paul Nowosielski wrote: On Friday 30 June 2006 14:37, Brian Dunning wrote: I have a table where I want to update each record with today's date as it's hit, or add the record if it's not in there: +--+-++ | id | creation_date | last_hit | +--+-++ I'm trying to do this with a minimum of hits to the db, so rather than first searching to see if a matching record is in there, I thought I'd just go ahead and update the matching record, check to see if it failed, and if it failed then add a new one, like this: $id = $_GET['id']; // Update $query = update table set last_hit=NOW() where id='$id'; $result = mysql_query($query); // Add if(the update failed) { $query = insert into table (id,creation_date,last_hit) values ('$id',NOW(),NOW()); $result = mysql_query($query); } What's the fastest way to check if the update failed? This is from the php.net docs. Return Values For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. So if($result == 0){ do something; } No no no no no! Never like that! What you want is this: if($result === false){ do something; } Never use 0 as a placeholder for false, and never use == to compare boolean values. 0 is an integer, false is a boolean. Using === ensures that result is false, and that it is a boolean that is false. It compares the value AND the type. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Chnage Management in PHP aka version control?
[EMAIL PROTECTED] wrote: By 'change management' do you mean something like version control software? CVS, Subversion, etc? We use CVS at work and tried setting up Subversion at one point. I don't know, maybe we're all a bunch of retarded monkies here or maybe both systems are just overly complicated, but I don't like either of them. We have a working CVS setup right now, but it's not integrated with Zend Studio (which would be nice) and we couldn't get Subversion to integrate nicely either so we're just sticking with CVS for now. Sad to say, but the easiest, most user-transparent and still functional file locking system I've ever used was what's built into Microsoft Office applications where it'll tell you This file is already open, would you like to open read-only and be alerted when you can write to it?. But that doesn't contain any version control (unless you turn on change tracking in some MS Office apps). I don't know about you, Jay, but all we really want to do is keep a record of revisions and be able to 'diff' between them and have the files lock so if someone tries to open the file and it's already open, that the user is alerted and allowed to open read-only if they desire. What kind of features are you looking for in a 'change management' software package? Maybe someone can recommend an app or two that will fit yours (and maybe our) needs. -TG = = = Original message = = = I have been searching and digging for a PHP based change management application but have had little luck. Can anyone make a recommendation? Thanks! ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. His message seemed to indicate that he wanted a version control application WRITTEN in PHP, not that supported PHP. Regards, Adam. -- 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] 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
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
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? sect;eth; -- 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
Steve Clay wrote: Sunday, January 22, 2006, 10:10:54 PM, Adam Hubscher wrote: ee dee da da da? sect;eth; -- 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
[PHP] XML and htmlentities conditionally?
I have a block of XML that looks as follows: namelt;*_~_*gt; Røyken VGS lt;*_~_*gt;/name Now, if I run that block of XML through htmlentities, I will get the following: name*_!_* Røyken VGS *_~_*/name 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 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: namelt;*_~_*gt; Røyken VGS lt;*_~_*gt;/name 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. name![CDATA[lt;*_~_*gt; Røyken VGS lt;*_~_*gt;]]/name 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
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
[PHP-CVS] cvs: php4 /ext/yaz php_yaz.c
dickmeiss Wed Apr 18 08:03:24 2001 EDT Modified files: /php4/ext/yaz php_yaz.c Log: Function yaz_record returns database for record if type is "database". Index: php4/ext/yaz/php_yaz.c diff -u php4/ext/yaz/php_yaz.c:1.14 php4/ext/yaz/php_yaz.c:1.15 --- php4/ext/yaz/php_yaz.c:1.14 Tue Mar 13 09:04:05 2001 +++ php4/ext/yaz/php_yaz.c Wed Apr 18 08:03:23 2001 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_yaz.c,v 1.14 2001/03/13 17:04:05 dickmeiss Exp $ */ +/* $Id: php_yaz.c,v 1.15 2001/04/18 15:03:23 dickmeiss Exp $ */ #include "php.h" @@ -244,6 +244,7 @@ #ifdef ZTS tsrm_mutex_unlock (yaz_mutex); #endif + php_error(E_WARNING, "Invalid YAZ handle"); return 0; } return assoc; @@ -492,6 +493,7 @@ } if (t-action) (*t-action) (t); + t-action = 0; } break; case Z_APDU_searchResponse: @@ -1193,7 +1195,6 @@ p = get_assoc (id); if (!p) { - zend_error(E_WARNING, "get_assoc failed for present"); RETURN_FALSE; } p-action = 0; @@ -1219,7 +1220,8 @@ for (i = 0; iMAX_ASSOC; i++) { Yaz_Association p = shared_associations[i]; - if (!p || p-order != order_associations || !p-action) + if (!p || p-order != order_associations || !p-action + || p-mask_select) continue; if (!p-cs) { @@ -1649,6 +1651,11 @@ if (ent ent-desc) RETVAL_STRING(ent-desc, 1); } + else if (!strcmp (type, "database")) + { + if (npr-databaseName) + RETVAL_STRING(npr-databaseName, 1); + } else if (!strcmp (type, "string")) { if (r-which == Z_External_sutrs ent-value == VAL_SUTRS) @@ -2201,8 +2208,13 @@ zend_hash_move_forward_ex(ht, pos)) { ulong idx; +#if PHP_API_VERSION 20010101 int type = zend_hash_get_current_key_ex(ht, key, 0, idx, 0, pos); +#else + int type = zend_hash_get_current_key_ex(ht, key, 0, + + idx, pos); +#endif if (type != HASH_KEY_IS_STRING || Z_TYPE_PP(ent) != IS_STRING) continue; ccl_qual_fitem(p-ccl_parser-bibset, (*ent)-value.str.val, key); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[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] URL vars in URL var?
http://www.php.net/manual/en/function.urlencode.php Pass it through that function (or one of the others) on: http://www.php.net/manual/en/ref.url.php On Tue, 2002-12-03 at 12:01, Shawn McKenzie wrote: I'm trying to pass a URL as a var in a URL: The url var should equal: http://www.someothersite.com/index.php?something=somethingx=100y=200 And I'm passing it to this URL: http://www.somesite.com/index.php?var=val So if I use: http://www.somesite.com/index.php?var=valurl=""> ndex.php?something=somethingx=100y=200 The problem is, if I echo $url; I get the following: http://www.someothersite.com/index.php?something=something So the vars after the in the url var are being truncated, I'm assuming that they are treated as vars of the main URL. Any help appreciated, Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] x as a multiplier
I don't think he's trying to multiply, I think he wants to print #x#, like 800x600 or 1024x768, etc... Adam On Tue, 3 Dec 2002, Kevin Stone wrote: Is it possible you're mistaken somehow? x isn't an operator in PHP. Executing $a x $b will give you a parse error. Anything in quotes is automatically casted as a string. -Kevin - Original Message - From: John Meyer [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, December 03, 2002 3:20 PM Subject: [PHP] x as a multiplier Code: $newwidth . x . $newheight What I want to get out is a string, like 89x115. All I am getting though, is one number, even though if I do this $newwidth . x . $newheight It prints out just fine. What is going on here? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 2.4.3 and Apache 2.0.x
If you mean PHP 4.2.3, it'll work with apache 2.0, but not that great. I'm also using PHP 4.3.0-rc2 with Apache 2.0 and its not any better. Adam On Wed, 4 Dec 2002, Vicente Valero wrote: Hello, PHP 2.4.3 can work with Apache 2.0.x or I need Apache 1.3.x? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP and Apache
Yes On Wed, 4 Dec 2002, Vicente Valero wrote: Excuseme my confussion, I meant PHP 4.2.3. So you suggest me PHP 4.2.3 and Apache 1.3.x?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Changeing user
change the directory ownership to the user apache runs as, or make the dir 777. Adam On Wed, 4 Dec 2002, [iso-8859-1] Davíð Örn Jóhannsson wrote: I need to be able to create dirs, chmod and other stuff on the server, but I get : Warning: MkDir failed (Permission denied), so Is there any way for me to do something so I can change the user I attept to execute those functions. Something like exec(change user, pass). Thanks David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL Table backup
Your not trying to run that from within MySQL are you? You do know that mysqldump is an entirely seperate command then the mysql console (where you would for instance type, USE DB; SELECT blah FROM table) right? On Mon, 2002-12-09 at 10:26, Shaun wrote: thanks for the reply, but that didn't help ERROR 1064: You have an error in your SQL syntax near 'mysqldump -h localhost -u xxx -p xxx backup.sql' at line 1 any ideas? Adam Voigt [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Take off the backup.sql and see if you get any error's that might explain it. On Mon, 2002-12-09 at 10:07, Shaun wrote: Hi, I am trying to backup my database can someone please tell me why the following commande wont work? mysqldump -h localhost -u username -p databasename backup.sql thanks for your help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] Using odbc_pconnect function
I believe everything you have mentioned is automatic. You don't need to pass $connectionstring since PHP detects it's the same info and just sends you the same connection. Also, I believe PHP auto-closes after a certain amount of time (might be configurable, check the php.ini). On Mon, 2002-12-09 at 10:48, Luc Roettgers wrote: Hi, Trying to use persistant connections to reduce general access times on my tables, I have the following problem. When creating my connection with: $connectionstring = odbc_pconnect(prov,username,pass); I'm able to use it on the current page but how do I resuse the variable $connectionstring on other pages since I make calls like: $queryexe = odbc_do($connectionstring, $query); Hope this is not confusing. Also, can I make the persistant connection expire after there have been no calls to the DB for a certain time? Many Thanks, -Luc -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] MySQL Table backup
Quote: It sounds like you are not running it from the command prompt but from within mysql. Reponse: I suspect as much. On Mon, 2002-12-09 at 11:15, Chris Hewitt wrote: Shaun wrote: ERROR 1064: You have an error in your SQL syntax near 'mysqldump -h localhost -u xxx -p xxx backup.sql' at line 1 It sounds like you are not running it from the command prompt but from within mysql. Unless the omission of the redirection sign but not backup.sql was intentional, in which case you have too many parameters. Adam's reply implied removing both. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] # of lines in a file
$f = fopen(filename,r); $data = "" fclose($f); $data = "" $lines = count($data); $certainline = $data[linenumberyouwant]; Replace filename in both places, and linenumberyouwant. On Mon, 2002-12-09 at 11:58, [EMAIL PROTECTED] wrote: Hey guys, I've been searching the manual for a way to grab the number of lines in a file and read a particular line from it, however I found no solution to my problem so I'm wondering if any of you out there could help me :-) - CS -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] Re: Not able to connect to FTP server
Umm, try this: $ftp = ftp_connect(ftp.direw.net) or die(Couldn't connect.); See if you get Couldn't connect. I suspect it's cause your both checking the variable and setting it in the same clause. On Mon, 2002-12-09 at 12:34, bill wrote: Have you tried passive mode? Vinod wrote: Hi friends, I am having a DSL Internet connectivity in our office and my PC is connected to Internet using a HTTP/FTP Proxy(192.168.0.10) and the browser(Mozilla) in my PC is configured to connect to net through the proxy When I tried to connect to our ftp site using the following script, I have received the message that Unable to connect. But the same script is working fine with a direct modem connection. The script is // connect to ftp server if(!($ftp=ftp_connect(ftp.dirw.net))) { print(Unable to connectbr); exit; } Please suggest me on how to connect to the ftp site using the proxy server. Regards, Vinod.B -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] Pls Help: Moving script from Win to Linux
is register globals enabled? On Tue, 10 Dec 2002, Shane wrote: Greetings gang. You know me, I never ask for help if I haven't checked all my other options, but this is day two, and I'm getting spanked on this one. Some recently moved scripts from a WIN2K server running PHP 4.2.1 to an Apache PHP 4.2.3 setup have stop accepting HTML Form Variables. I can pass variables till I am blue in the face, even see them in the URL but they are still showing up as (!isset) My ISP (Whom is using Virtual Directories) has no solution, and I have tried every code variation I could think of to troubleshoot it. This code has been working fine for Months on the WIN2K box, but just doesn't pass a var on the Linux solution. Can any Server pros out there possibly throw me a bone? My deadline is looming. :^) As always, a million thanks in advance. Yours truly. -NorthBayShane -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How to force an image to reload
Guys, not sure if this is a PHP problem or a more general HTML problem, but... I've written a small test script (see below), basically, which allows the user to rotate an image by 90degrees. When I press the button, the page reloads having rotated the image, but the old image is still displayed. (I know it's done it if I load up another browser window) Pressing refresh does cause the image to reload. Any ideas??? ?php header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past header(Last-Modified: . gmdate(D, d M Y H:i:s) . GMT); // always modified header(Cache-Control: no-store, no-cache, must-revalidate); // HTTP/1.1 header(Cache-Control: post-check=0, pre-check=0, false); header(Pragma: no-cache);// HTTP/1.0 ? head TITLEYama!/TITLE /head body p / ?php if($submit == Rotate 90) { $output=`mogrify -rotate 90 pictures/028_25.jpg`; echo $outputp /; } $submit= ; echo new value of submit=$submit; ? form name=form1 action=?php echo($PHP_SELF) ? method=post input type=submit name=submit value=Rotate 90 /form p / img src = pictures/028_25.jpg /body /html Regards thanks in advance Adam White -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to force an image to reload
Many thanks Ed, works a treat! Regards Adam White Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: 10 December 2002 18:31 To: Adam White Cc: [EMAIL PROTECTED] Subject: Re: [PHP] How to force an image to reload As one who has had to do the same thing and had gotten some help from this list I'll put in my two cents. ? $rand = rand(1000,); ? img src=image.jpg?? echo $rand; ? This echoes a ? with a random number behind the filename forcing a request to the server for the image because you probably wont have that exact same image with the random number in your cache. Ed On Tue, 10 Dec 2002, Adam White wrote: Guys, not sure if this is a PHP problem or a more general HTML problem, but... I've written a small test script (see below), basically, which allows the user to rotate an image by 90degrees. When I press the button, the page reloads having rotated the image, but the old image is still displayed. (I know it's done it if I load up another browser window) Pressing refresh does cause the image to reload. Any ideas??? ?php header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past header(Last-Modified: . gmdate(D, d M Y H:i:s) . GMT); // always modified header(Cache-Control: no-store, no-cache, must-revalidate); // HTTP/1.1 header(Cache-Control: post-check=0, pre-check=0, false); header(Pragma: no-cache);// HTTP/1.0 ? head TITLEYama!/TITLE /head body p / ?php if($submit == Rotate 90) { $output=`mogrify -rotate 90 pictures/028_25.jpg`; echo $outputp /; } $submit= ; echo new value of submit=$submit; ? form name=form1 action=?php echo($PHP_SELF) ? method=post input type=submit name=submit value=Rotate 90 /form p / img src = pictures/028_25.jpg /body /html Regards thanks in advance Adam White -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Install Problem
I'm attempting to install Pear DataObjects on Windows 2000 Advanced Server with all the most current patches and updates. When utilizing the php-cli exe to run createTables.php, we recieve the error invalid function call to getStaticProperty, in DataObject.php on line 1620. I have attempted to run the DataObjects install script but it gave a warning that the archive was an old format because there was no package.xml. We have downloaded the most recent TGZ and received the same error when installing locally. Any ideas? -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] Free MySQL Hosting...again
I'm getting Connection Refused on that website, sure your not still having problems? On Wed, 2002-12-11 at 15:33, PHP Mailing List wrote: I had a little trouble with my cable modem before, but the Free MySQL Hosting is back up if any of you are interested. =) http://mysql.nukedweb.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] protect downloadable files
Make the download link a PHP page: download.php?fileid=199 Then check to make sure there session is valid, and what not and then use the header function to make the browser know it's supposed to give a save dialog box. I don't specifically know the code, but I know this will work. On Thu, 2002-12-12 at 10:56, Jan Grafstrm wrote: Hi, I have some zipfiles in a directory and wonder how to protect the files? I send the customer to a downloadpage with links after succsessfull login. What is best to do? chmod the files when I upload them and change chmod if I have a verifief user? Any suggestions? -- Regards Jan Grafstrom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] Include?
The passwd file is frequently world-readable so programs that rely on it don't need root permissions. Now if you can view /etc/shadow, then that would be a problem since that's where the actual passwords are stored (encrypted). On Thu, 2002-12-12 at 12:53, Shawn McKenzie wrote: It seems that if I create a php file in my dir at my hosting provider and do include('/etc/passwd'); then wow, I see the contents of etc/passwd! Is this expected behavior??? I am looking at creating a script that takes a var in the url and includes the requested file. The purpose would be for only URLs (myscript.php?page=http://mysite.com/dir/cool.html, or relative URLs (myscript.php?page=/dir/cool.html). Can I do this without allowing someone to include files by filesystem reference??? Thanks! Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] Submitting a Form
1. Try: $_POST[Test] 2. $_POST[testmultiple][2] (Will give you position 3 of the select.) Or: $list = implode($_POST[testmultiple]); Will give you the values selected in $list in a comma seperated list. 3. print_r($_REQUEST) On Tue, 2002-12-17 at 12:38, Jay Thayer wrote: I have a php page, with a form I am attempting to submit. form method=Post action=""> input type=hidden name=Test value=Test Value input type=submit value=Submit name=SubmitTest form In submitTest.php, I simply put ?php print $Test; ? Yet, I continually get the browser message: Notice: Undefined variable: Test in ...\submittest.php on Line 2 1. Any reason that I can not pass the variable to the submit page? I am using an Apache Web Server on Windows XP. I am simplying attempting to pass a variable from one page to another, so I can update my database. This is just a simple test that is failing. 2. If I have a select name=testmultiple multiple HTML tag, how can I reference the x# of variables that are selected in that form value in the submittest page? I would want to get every option that is selected in the page. 3. Is there a variable so that I can see everything that is passed from the form, some debug variable I could print() to see everything that was passed from the form? Anyone have an idea? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part