[PHP] PHP and the C Preprocessor
I'm working on a system where I take a directory full of PHP files (plus some #defines, etc.), run them through the C Preprocessor (and m4 later, but that's to solve a very specific problem), and have the results go into an output directory that's web-accessible. My intent is to have one set of PHP files create several sites that are each configured their own specific way and have certain portions of the code removed. (I prefer #ifdef over an if() check in PHP because it means the code that won't be used doesn't need to be parsed either, and it's cleaner in many ways). I've had some measure of success, however I've also had quite a few problems crop up. Rather than have 100+ lines of define() statements that need to be parsed every single page load (my include file is quite large), I've opted to replace them with CPP-level #define statements. This works (in MOST cases and I can work around the exceptions), with a few major issues: The major problem is: #defineDNA42// Life, the Universe and Everything echo The meaning of life is , DNA, .; Most of the cpp options I've tried do not strip out the //-style comments, so I end up with: echo The meaning of life is , 42// Life, the Universe and Everything, .; which creates a rather nasty parse error. I've tried -x c++ to allow the //-style comments, but then I'm not allowed to use multi-line string constants (I do this quite extensively in echo statements). As a last resort, I tried -x assembler-with-cpp, which happily changed my multi-line string constants into single-line string constants (by adding a ' at the end of the line, NOT by concatenating the lines together), which promptly causes a parse error on what's supposed to be the second line of the string -- it also causes some odd mangling in certain circumstances. I would prefer to not have to change all my // comments to /*..*/ style, and would like to keep my multi-line string constants -- my goal is to get this working without significant source code changes (exceptions being define() to #define and other small changes). Has anyone here had any luck setting up something similiar? cpp, php, and m4 are invoked as shown below (as Makefile snippets) PHP = C:/php/php.exe -C -q -d short_open_tag=off CPP = cpp -P -Wcomment -undef -Wundef -nostdinc -nostdinc++ -traditional M4 = m4 -P ... $(CPP) ../src/$@ | $(M4) preproc.out $(PHP) ../tools/lint.php $(PHP) -l preproc.out mv preproc.out $@ [lint.php is a small PHP script that invokes PHP's -lint option, but also returns 0 or 1 so it'll stop the Make if there's a syntax error.) By the way, once I get this all working, I'll release the build system (not what it builds, however) as open-source for whoever wants it. It's going to be quite handy IMHO. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: open or save problem
I've CC'd a copy of your message plus this reply to the PHP mailing list for the benefit of the rest of the PHP community as well. (That and one of them might have a solution to this) I never found a clean solution to this problem with PDF files with cache: no-cache set. There are a couple of ways around this that I know of: 1. Rather than outputting the PDF file, physically create it in a web-accessible directory (with some randomly-generated filename, md5(uniqid(pdf)) . .pdf would work) and redirect the user to it. 2. Better, dump the entire PDF file into a database using some uniqid() to reference it and a timestamp, and redirect to a PHP script that doesn't use sessions/doesn't send the cache-control header (or uses cache-control: private) which pulls the PDF back out of the database and feeds it to the user. The timestamp can be used to automatically delete the file after a short time, 5-30 minutes later depending on the length of the PDF. Neither of these solutions are perfect, however, and if the PDF contains security-sensitive information you still have the same problem as they'll be cached. If you want to do further research into this, I periodically hear something about an issue between Apache and PDF, but I don't know the details of that. It's possible the problems are related -- if so, there may be a fix somewhere on the Apache site. -- Daniel Grace - Original Message - From: Dylan Miller [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 30, 2002 1:17 PM Subject: open or save problem Daniel Grace, Hi, I saw a post of yours on the php.general message board: http://groups.google.com/groups?hl=enlr=ie=UTF-8oe=UTF8selm=20020302062 856.49458.qmail%40pb1.pair.com I'm writing a program to send a PDF file to a browser, and I get the exact problem you describe when I set Cache-Control to no-cache. If I remove the Cache-Control header, everything works fine, but with it in there, I get the open or save dialog with open grayed out. For security reasons, I'd like to avoid caching. I was just wondering if you ever found out anything more about this. I've been reading and searching the web, and your post was the only thing I could find related to this issue. I'd really appreciate any insight you could give me. Thanks, Dylan Miller Solimar Systems, Inc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: ssl security question
Jan grafström [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have made a file wich start a session and set a session variable if user and pass are verifyed. Than I use the session variable to protect all other userfiles. To run the file I enter: http://myserver.com/start.php3?user=xpass=yy What is the differans using SSL and enter the same url? If a hacker sniff the ssl-string can he send that string and start the file anyway? SSL connections are inherently encrypted. The encryption is done in such a manner that makes a 'record/playback' attack impossible, as the key used to encrypt things with changes. I don't recall the exact specifics right off-hand but any good resource on SSL will explain it. SSL is completely encrypted, right down to everything sent over the wire. If someone was sniffing they'd just see a bunch of random garbage that would do them very little use. However, displaying the username and password as part of the URL (GET method) is a security risk in the sense that many browsers will keep it in their history and thus someone with access to the history can determine their username/password. POST would really be a better method to use here in this case. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Search a flat file.
Be warned that explode won't work as expected if any of your fields contain colons, though it doesn't look like it'll be an issue in this sort of case. Gaylen Fraley [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Use the explode() function based on the colon. Then parse the 2nd array element for the username that you want. If matched, display all elements in that array row. Conversely you could use the implode() to reassemble the array row. [...] Tom Ray [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I want to be able to search a flat file line by line looking for data such as a username then display all the information in that line. Is there some way to search the following format: record1:username:info:info:info record2:username:info:info:info record3:username:info:info:info -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Speed comparison of PHP vs. PERL (not conclusive)
Peter [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... You mention that you could have written the PHP code in a more efficient way using continue(). Why not time this as surely a built in function would be quicker than one written in the code. -- snip to my old test results -- [dewin@ulysses profiling]$ time ./prime.php /dev/null real0m14.465s user0m8.610s sys 0m0.070s [dewin@ulysses profiling]$ time ./prime.pl /dev/null real0m5.302s user0m3.180s sys 0m0.000s My intent upon writing this program was to compare the relative speed of execution between PERL and PHP, however it's been established that it's not really a valid test as PERL is optimized for looping whereas PHP is better in other areas. (Personally, I don't know the PHP source very well but I'm curious as to whether trying to bring it closer to PERL's speed is an eventual design goal -- I DO have some tightly-looping PHP code that does see frequent use and it would be nice to speed it up. (but my own code could be sped up with a better algorithm too -- I'd ask about it but it's not a priority to me at the moment)). My intent was to make the scripts as equal as possible so the results would reflect pure speed and not capabilities of the language. (Of course, I've been told PERL has an equivalent to PHP's continue(n) syntax, so the issue is moot.) However, for the sake of completeness I'll profile both variants of prime.php again: Old method (set temp val, break, test temp val, continue if temp val set): [dewin@ulysses profiling]$ time ./prime.php /dev/null real0m14.304s user0m8.520s sys 0m0.060s new method: (continue(2);) [dewin@ulysses profiling]$ time ./prime.php /dev/null real0m14.402s user0m8.620s sys 0m0.030s Surprising? To be fair, I only timed the old method once and took the average from three times on the new method (I changed my only copy of the code and didn't feel like changing it back to retest the old method). The times shown in my original tests (above) probably more accurately reflect the old method than the current ones. That being said, it looks like continue(2) is actually a tiny tiny bit slower (we're talking around 0.010s over a 1-iteration loop on a 700 mhz machine here) than doing it by hand the old way. With an amount that small though, I'm more inclined to believe it's just statistical error/random variance than anything else. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Speed comparison of PHP vs. PERL (not conclusive)
This all started in a little debate between me and a friend of mine who I think is as much a PERL zealot as I am a PHP zealot (I was briefly pondering the idea of a Win32 API extension for PHP), and the results were rather surprising -- to me, at least.. It all started when I asked him what PERL had that PHP didn't in terms of language (not taking community, modules, etc. into an account). We both believed that the two would be very similiar in speed -- he thought PERL would be a little faster but not enough to be noticeable. For the first test, I went with a program that computed prime numbers between 2 and 1, using no form of caching or anything like that. I gave him the PHP source with the task of writing something in PERL as close to the original PHP source as possible. The results: (note: I didn't know if PERL had PHP's continue(2), hence why I used the slightly less efficient method here:) prime.php: #!/usr/bin/php -q ?php echo 2\n; for($check = 3 ; $check 1 ; $check += 2) { $prime = 1; $half = (int) $check / 2; for($against = 2 ; $against = $half ; ++$against) { if(!($check % $against)) { $prime = 0; break; } } if($prime) echo $check\n; } prime.pl: #!/usr/bin/perl # print 2\n; my $num; for ($num = 3; $num 1; $num+=2) { my $prime = 1; for $check ( 2 .. int($num/2) ) { if ($num % $check == 0) { $prime = 0; last; } } #print $num\n if $prime; } The test machine is an AMD Duron 700 MHz using an a-bit KT7A motherboard with 256 MB of PC100 SDRAM. uname -a reports Linux ulysses.venura.net 2.4.17-ulysses1 #1 Sat Dec 29 14:44:46 PST 2001 i686 unknown, PHP 4.2.1 was configured with --enable-inline-optimization --prefix=[somepath], PERL 5.6.1 was configured with -O3 (among other options) (PHP compiles with -g -O2 with no 'easy' (at-configure-time) way to change that, to my knowledge). Both programs were ran once normally to verify they actually generated prime numbers, and then the bash time command was used to time them, piping their output to /dev/null to prevent that from being a factor. I re-ran the tests a few times with results consistently similiar to those listed here: The results: [dewin@ulysses profiling]$ time ./prime.php /dev/null real0m14.465s user0m8.610s sys 0m0.070s [dewin@ulysses profiling]$ time ./prime.pl /dev/null real0m5.302s user0m3.180s sys 0m0.000s A second system, with PHP compiled the same way and a PERL 5.6.1 binary distributed by Red Hat, 1.2 ghz with 442 MB of RAM: [root@mrr-016 law]# time ./prime.pl /dev/null real 0m2.078s user 0m2.040s sys 0m0.010s [root@mrr-016 law]# time ./prime.php /dev/null real 0m5.512s user 0m5.430s sys 0m0.010s Comments? I was expecting the numbers to be very similiar -- rather shocked that the PERL ended up being about 2.5x as fast as PHP was. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Speed comparison of PHP vs. PERL (not conclusive)
I made an oops! when I wrote: prime.pl: #!/usr/bin/perl # print 2\n; my $num; for ($num = 3; $num 1; $num+=2) { my $prime = 1; for $check ( 2 .. int($num/2) ) { if ($num % $check == 0) { $prime = 0; last; } } #print $num\n if $prime; Disregard the comment characters there. I added them in after testing (to see how much of an effect the output made -- wasn't noticeable) and forgot to remove them when c+p'ing the source to the newsgroup. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Speed comparison of PHP vs. PERL (not conclusive)
Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Sure, you could put it that way. When benchmarking something you really should benchmark stuff that you actually care about. Benchmark PHP spewing out a web page after making a couple of SQL queries, for example. That's typical usage, so that is what you should benchmark. Very few PHP scripts are going to loop a couple of hundred thousand times to do something. -Rasmus On Fri, 31 May 2002, Ilia A. wrote: Does this mean that running a comparison benchmarks between PHP and any other language would in many cases show PHP to be slower simply because it's looping code is slow? [...] It is typical usage, yes, but the conversation that gave me the idea to do the quick speed comparison was the idea that PHP can be used for more than just web-scripting. I have a couple maintenance PHP scripts that run command-line (usually management/maintenance programs for a large PHP+MySQL app), and there is the entire php-gtk project as well. (The whole conversation started because I pondered the idea of maybe writing a Win32 API extension for PHP) And a loop in PHP isn't exactly non-typical. I'd need more fingers and toes to count how many times I've wrote while($row = mysql_fetch_assoc($result)) { ... } -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Apache, html, PHP and global variables
This was originally sent to the httpd-users mailing list, I'm moving it to the php-general list to bring it on-topic and because I think it's something worth sharing. I'm also hoping I actually remembered the address for the php-general list since I typically post there via the newsgroup. On Thursday, May 30, 2002 at 7:34 AM, Peter [EMAIL PROTECTED] wrote: [...] I am designing a web site which has a number of pages. One of these provides the facility for the user to log onto a mysql database. Other web pages allow the user to query and update different tables in the database. [...] I used the mysql_pconnect function in the login page and assumed that the connection would automatically be available to all other pages in the site as hey are invoked, but find that I have to include it in every page that access the data base. mysql_pconnect creates a persistent database connection that survives across multiple page loads, however, the connection is NOT always available to all other pages. Specifically: 1. You still must call mysql_pconnect in each page that accesses the db. What mysql_pconnect does is avoid the overhead of reconnecting -- but you'll need to call it again on each page to get the connection handle. Read more at http://www.php.net/mysql_pconnect 2. If you are running your webserver in multiple processes (99% of the time this is true with Apache, which you are using) and the same user happens to be served by multiple processes, each process will require its own connection to the server -- which will be made the first time that process calls mysql_pconnect. Since your particular setup has a user logging into a mysql database (presumably with their own account instead of one shared db account that takes care of db management via your code), this means you can have a theoretical maximum of users * processes connections to your database. Make sure MySQL is configured to allow that many connections. (20 apache processes and 10 users is 200 connections that stick around a long time...it adds up real fast!). If the ability to raise the connection limit isn't available, you may want to use mysql_connect instead -- slightly slower, but you won't have to worry about unused connections lingering. (It's still possible to hit the limit, though, just not as likely.) -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: reindexing an array after unset()
Erik Price [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... On Wednesday, May 8, 2002, at 03:28 PM, Kyle Gibson wrote: What do you think? Try array_pop($array); array_pop() is perfect, except that I don't want to take the last element off the end. Otherwise I would definitely use it. Erik $array = array_values($array) will re-index your array without the need for array_pop and array_push. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Empty Delimiter error
Rich Pinder [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Let me try again: This line of the script: if (!stristr($lines[$key], $email)) { yields the following error: Warning: Empty delimiter in /home/sites/site56/web. Do you know what causes this error ? Thanks r My guess is that $email is empty (or possibly $lines[$key]). The documentation for stristr says nothing about generating warnings on such an occurance, but it would make sense. If your script can handle $email being empty, simply adjust your level of error-reporting or silence the warning with an @. Otherwise, fix whatever it is that's causing $email to be empty. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: get the median from an array of integers
The web page features ten listboxes, each of which contains the same options Let's say that you can choose A, B, C, D, or E from each listbox Submit the form, run some code to figure out which was most-frequently selected, and then display that value on the next page That's all I really want to do, but I'm pretty bad at math -- I could enter all the values into an array and run some kind of averaging code on them, but the problem is that I don't want an average, I need the most-chosen value As for the median value, there's a relatively easy way to do this in PHP: 1 Sort the array (sort()) 2 Count the number of elements in the array (count()) 3 Take the element that is equal to half the number of the elements (rounded to an int, which way you round doesn't matter) (really_easy_code()) Might be off-by-1 but that's fixed easily enough -- Daniel Grace -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
Re: [PHP] Overriding session headers
William Lovaton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]; May be this helps: http://www.php.net/manual/en/function.ob-start.php Nope, that won't work. I'm not even sending output at this point, just trying to prevent a header from being sent and I'm not being allowed to override it. Maybe in some later version we'll get the ability to either fine-tune what headers the Session handler sends, or the ability to directly modify what's being sent for headers? Pleeease? -- Daniel Grace (my original message is re-quoted for context below) Is there a way to override the headers that session_start() sends to the browser from within a PHP script? On php 4.0.4pl1 (will be upgrading to 4.1.1 later) on SOME browsers (notably, IE 6.0 on XP -- my setup), a script I have that outputs a PDF document will misbehave in IE when the No-store portion of a cache-control header is present... which PHP sends as part of the sessions. When this is present, IE6 will either come up with a blank page, or it'll present your typical You are downloading the file: blah blah blah... would you like to open the file or save it to your computer? dialog box. However, the 'open' option of the dialog box will be grayed out, and clicking Save yields an error message reading Internet Explorer can notnot download location from host. Internet explorer was not able to open this Internet Site. The requested site is either unavailable or cannot be found. Please try again later. Like I said, it seems to be the No-store part of a cache-control header that causes the problem. Change the caching options for sessions from nocache to private fixes this, but happens to break other things on the site. Sending my own cache-control headers with header() either merges them with the ones the session_start sends, or does absolutely nothing (verified by doing a GET /url HTTP/1.0 via telnet to port 80), regardless of whether the header occurs before or after the session_start. -- Daniel Grace P.S. The PDF documents are generated using Wayne Munro's cpdf and cezpdf classes, located at http://sourceforge.net/projects/pdf-php/; They do not require clibpdf or pdflib and are public-domain, so there are no licensing fees involved... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Overriding session headers
Is there a way to override the headers that session_start() sends to the browser from within a PHP script? On php 404pl1 (will be upgrading to 411 later) on SOME browsers (notably, IE 60 on XP -- my setup), a script I have that outputs a PDF document will misbehave in IE when the No-store portion of a cache-control header is present which PHP sends as part of the sessions When this is present, IE6 will either come up with a blank page, or it'll present your typical You are downloading the file: blah blah blah would you like to open the file or save it to your computer? dialog box However, the 'open' option of the dialog box will be grayed out, and clicking Save yields an error message reading Internet Explorer can notnot download location from host Internet explorer was not able to open this Internet Site The requested site is either unavailable or cannot be found Please try again later Like I said, it seems to be the No-store part of a cache-control header that causes the problem Change the caching options for sessions from nocache to private fixes this, but happens to break other things on the site Sending my own cache-control headers with header() either merges them with the ones the session_start sends, or does absolutely nothing (verified by doing a GET /url HTTP/10 via telnet to port 80), regardless of whether the header occurs before or after the session_start -- Daniel Grace PS The PDF documents are generated using Wayne Munro's cpdf and cezpdf classes, located at http://sourceforgenet/projects/pdf-php/; They do not require clibpdf or pdflib and are public-domain, so there are no licensing fees involved -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
Re: [PHP] breaking out of two loops
Lars Torben Wilson [EMAIL PROTECTED] wrote in message 1012867253.2248.185.camel@ali">news:1012867253.2248.185.camel@ali... On Mon, 2002-02-04 at 15:54, Erik Price wrote: Short and sweet: If I have an if statement inside a switch statement, how can I break out of both blocks that I am in? Will one break end everything? Or should I use one for each level deep that I am? Erik From the manual: break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of You can find this at http://www.php.net/break (which will take you to http://www.php.net/manual/en/control-structures.break.php). Hope this helps, Torben That being said, break only breaks out of looping constructs. A break placed within an if-block will break out of the loop around it. There isn't a direct way to break out of an if-block alone (if that's your intent), though this will work: do { if(condition) { ... ... ... break; } } while(0); -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie: function for downloading
Manuel Ritsch [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hey There I have a little question I'm making a page where you can download mp3's (hip hop and funk beats made by myself) and i want, if you press on the link (a href=yadayada.mp3), that it doesn't start an internal audio player (like some configurations/browsers do), rather i want that the download dialog (like when you download .exe or .zip files) appears to save the mp3 on your harddisk, can anyone give me a tip? Greets -- manu Take a look at http://www.php.net/header, particularly the Content-Disposition portion of it: If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog. ?php header(Content-type: application/pdf); header(Content-Disposition: attachment; filename=downloaded.pdf); /* ... output pdf file ... */ Note: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround. There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading to Service Pack 2 or later. You'll need to choose the correct content-type and filename of course. -- PHP General 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] Re: echo HTML code ;
André wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a PHP file that I show values of variables in several parts, and for that I put in almost the whole page echo... HTML code + PHP codes (variables, functions, etc.) + HTML code... ; I don't know nor why I put, I think it went to not to be finishing and beginning PHP parts as: ?php echo$variable; PHP functions; etc.? HTML code ?php echo$variable; PHP functions; etc.? HTML code ?php echo$variável; PHP functions; etc.? HTML code Can these several echo's harm the processing of the server? Can that turn slow the visualization of the page? Should I remove the maximum possible of echo... HTML Code ... ; or can I leave how it is? André Not using echo IS faster, but the difference is barely noticeable. If you're outputting lots of PHP variables, your current way is fine. By the way, you may wish to consider using 'here documents': echo XYZZY Here documents are nice. They work like doubly-quoted strings do, only you don't need to escape any of the quotes, single or double. They can also do $variable expansion and all those are nice things (escape your \$-signs if you use them for anything else), and of course html will work just fine. For more about Here Documents, take a look at here: http://www.php.net/manual/en/language.types.string.php XYZZY; -- Daniel Grace -- PHP General 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] Re: Swapping BR for \n... ?
Jon [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Nevermind, I found some code at last which actually works : $txt = preg_replace(/(\015\012)|(\015)|(\012)/,BR,$txt); rather than using a regular expression, try: $txt = strtr($txt, array(\r\n = br /, \n = br /, \r = br /)); This is probably faster, see http://www.php.net/strtr for details. -- PHP General 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]
Re: [PHP] how to send to URL on if statement?
There is one other option if you're willing to take a slight drop in performance. Take a quick look at: http://www.php.net/manual/en/ref.outcontrol.php -- Daniel Grace [EMAIL PROTECTED] Richard Crawford [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... If you have already sent output to the browser, then you won't be able to use the PHP header() command to redirect the browser. There are a couple of ways around this, though; look into the META tag in HTML, or you can use JavaScript to redirect the browser. -- PHP General 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] Re: 1st 100 charactors that are pulled from a mySql Database
Philip J. Newman [EMAIL PROTECTED] wrote in message 007a01c19fbe$2fbfb4e0$0401a8c0@philip">news:007a01c19fbe$2fbfb4e0$0401a8c0@philip... Would like to know if there is away that I can only print out the 1st 100 charactors that are pulled from a mySql Database, anyone help? Philip J. Newman Philip's Domain - Internet Project. http://www.philipsdomain.com/ [EMAIL PROTECTED] Phone: +64 25 6144012 Two ways: 1. SELECT LEFT(fieldname, 100) FROM table ... [see: http://www.mysql.com/doc/S/t/String_functions.html ] This will make MySQL return only the first 100 characters from your table. It SHOULD be safe in instances where there are less than 100 characters as well (it'll return the entire string in that case) This is the faster approach as the work is done in MySQL, and only 100 bytes of data are actually sent to your application (as opposed to the entire field). It has some limitations, however. 2. $shortened_string = substr($string, 0, 100); [see: http://www.php.net/substr/ ] Be warned that if $string contains HTML escapes, entities will count as multiple character, e.g. amp; is 5 characters and thus may be cut in half if it occurs towards the end of your 100 characters. See http://www.php.net/get_html_translation_table for a possible solution to this problem, or store your data in plaintext (this is impossible if you need to store HTML formatting in your text). I use this function to trim long names on my message boards at http://venura.net/ . Mind you, it will not properly handle _all_ HTML escapes, but it does the job well enough. // strLimit($string, $length) // Limits string lengths. If a string is shorter than length, returns that string. If the string is longer than length, returns the first // (length-3) characters of the string, plus a '...' to show continuation. Use: lists. // Modified to appropriately handle html-escapes function strLimit($string, $length) { $length += (4 * substr_count($string, )); // comment out this line if you aren't dealing with HTML escapes if(strlen($string) = $length) return $string; else return substr($string, 0, $length - 3) . ...; } One possible trick you can do in order to boost performance (by not transferring the entire string from the entire database, but still being able to know whether it's too long) is combine both #1 and #2 and actually pull the first 150-200 characters from the database, which should be enough to deal with most HTML escapes without dumping the entire table. -- Daniel Grace [EMAIL PROTECTED] -- PHP General 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] Overriding php.ini at runtime
I'm using the PHP CGI (4.1.0) with Apache (1.3.22) (would rather use the module, but have a setup that requires suEXEC and the like and I've hacked a few things together to make things work and all that.) and have came up with a bit of a dilemma. I need a way to override the php.ini file at page load time, preferably via an .htaccess file. I know Apache supports the php_ini directive but this only works for the Apache module and not the CGI. Is there an equivalent to the php_ini directive available for the CGI version, perhaps in the form of an environment variable or whatnot? I seem to remember a way of setting php_short_open_tags=on or somesuch but may be wrong. (It also may be that suexec is filtering out all those nice environment variables and thus making it not seem to work, but I'd rather know for sure before I make more modifications to the file that the Apache group says not to modify...) -- Daniel Grace [EMAIL PROTECTED] Please CC me in replies -- PHP General 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] Re: PHP array or SQL problem
Dean Householder [EMAIL PROTECTED] wrote in message 007301c19d97$21968660$d5246541@daylightcreations">news:007301c19d97$21968660$d5246541@daylightcreations... I've got a database with lname (lastname), fname (firstname), and nickname. What I want to do is search by either first name or last name. Either way, I display the nickname instead of the firstname if it exists. I have no problems on the last name, but when I sort by firstname, the people with nicknames that are very different come up at the place where their first name (not the displayed name) is. For example: Adam Smith Joe Schmoe Bill Somebody When Bill Somebody is really William Somebody in the database, his nickname is bill and that's what's displayed but he 'bill' shows up in 'williams' spot. Here is my SQL query: select * from employees order by fname; Should I create an array and sort it there or can I somehow query MySQL to sort by nickname only if it exists and then by fname? Dean SELECT IF(nickname IS NOT NULL AND nickname != , nickname, fname) AS fname, lname FROM table ORDER BY fname if it doesn't sort right, copy the IF(...) to the oRDER BY part -- Daniel Grace -- PHP General 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]
Re: [PHP] Overriding php.ini at runtime
Jason Wong [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... On Tuesday 15 January 2002 17:24, Daniel Grace wrote: Is there an equivalent to the php_ini directive available for the CGI version Some settings in php.ini can be changed at run-time using ini_set(). Check manual for details. short_open_tags isn't one of them I don't believe, and that's the one I primarily need to be able to change. -- PHP General 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]
Re: [PHP] Re: Generate Alphabet
Bogdan Stancescu [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... 2. print $letter++ -- why doesn't this evaluate to b at the first loop when it's already 'a'? Ok, this I may be able to explain because it's neither print ++$letter nor print ($letter++), but I wouldn't have trusted this syntax to work this way a million years! $foo++ is 'postfix', ++$foo is 'prefix' This means that the addition of 1 occurs AFTER (hence post) the expression's value is returned, not before. In other words, it's equivalent to this: print $foo; $foo = $foo + 1; not this: $foo = $foo + 1; print $foo; -- Daniel Grace -- PHP General 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] Re: Get Page Title
R. Elsenaar [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi, To get the title of an external page to put into a link, has somebody did that already and can give me some hints for this trick Robert // Your question managed to spark my interest and get me to write this... // // WARNING: If you are accepting user input for the page URL, you will // want to validate it before passing it to this function. // // I use fopen in order to (hopefully) not need to download the entire // page when we only want something that's likely to be in the first // few lines. // // This is not guarunteed to get the right title, esp. for dynamic pages // or anything // TEST 1: titleFirst Test/title // TEST 2: headtitleSecond Test/title/head // TEST 3: headtitleSecond Test/title/title // This function will return the filename or URL of the page if: // 1. The page has no title.../title tags. // 2. The page cannot be opened. // Consider expanding from this concept. It is not extensively tested. function get_page_title($page) { $contents = implode(' ', file($page)); if(!$contents) return($page); // Something didn't work right. if(eregi('title[^]*([^]*)/title[^]*', $contents, $regs)) { return(trim(ereg_replace('[[:space:]]+', ' ', $regs[1]))); } return($page); } echo get_page_title($path_to_page); -- PHP General 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] Re: Get PHP Configuration
Larentium [EMAIL PROTECTED] wrote in message 001f01c19334$270c8940$[EMAIL PROTECTED]">news:001f01c19334$270c8940$[EMAIL PROTECTED]... How would you get the current PHP configuration information, more specifically, the exact command line used at compilation? I want to add --with-imap, but have no idea how to determine what the current settings are. Larentium phpinfo() shows you the configure command. If you have the PHP CGI and are running on *nix or something like such, you can also. /path/to/php -i | grep ./configure -- Daniel Grace http://hosting.venura.net/ (STILL under construction) -- PHP General 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] Re: How to convert integers representations of a date to a date format variable
Carlos Fernando Scheidecker Antunes [EMAIL PROTECTED] wrote in message 002c01c19197$7beb6c40$0a505ad1@Nando4">news:002c01c19197$7beb6c40$0a505ad1@Nando4... Hello All, I would like to convert integers like the day, month and year to a date representation to store it in a session variable. There's a form where the user posts day, month and year. So then I run checkdate($month,$day,$year) and make sure the date is valid. So, let's say I have 12 for month, 30 for day and 2001 as year. Do I have to create a timestamp? How to create a TimeStamp? I need to store it as 30/12/2001 (but not a string) not only on a session variable but also to make it easier to work with a MySQL table. After that I want to play with it as a string so I will use the date() function, that's why it is important to save it as a validade date format value. Any sugestions? Thank you in advance, Carlos Fernando. Linux User #207984 see http://php.net/mktime or http://php.net/gmmktime , which will give you a unix timestamp that date() will accept (as will FROM_UNIXTIME() in MYSQL if you want to use that for storing it in the database) mktime(0, 0, 0, $month, $day, $year) should do the trick -- Daniel Grace -- PHP General 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] Re: RESOLVED(maybe):Warning: Cannot send session cookie
David Jackson [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... All -- It appears that the problem was a table design problems, my primary index wasn't set to auto-increment? So I was trying to insert records with duplicate keys !! This of course leads to another question, how do I return SQL error messages to the browser? Thanks, David Out of habit, I abstract all of the MySQL functions to handle this. My current setup for http://hosting.venura.net/ (still under construction). outputs error messages like this: function sqlQuery($query, $secure = 0) { $result = mysql_query($query); if(!$result) { if($secure) { $query = '*** hidden ***'; } else { /* This is just an oddity from how I construct some queries, primarily INSERTs. If all of your queries are on a single line of text with no leading/trailing whitespace or you don't care about appearance, you can delete this section of the code */ $query = explode(\n, $query); foreach($query as $line = $text) { $query[$line] = trim($text); } $query = implode(\n, $query); } die('h1Oops.../h1pbSorry, but something seems to have gone terribly wrong.../b/p pre MySQL Error Number: ' . htmlspecialchars(mysql_errno()) . ' MySQL Error Description: ' . htmlspecialchars(mysql_error()) . ' Query Text: ' . htmlspecialchars($query) . ' /pre p(Yes, you probably have found a bug.)/p '); } else return ($result); } This will dump the query, error number and error description whenever a SQL query fails. You can set the optional second parameter ($secure) to true if your query involves anything that you don't want the end-user to see, such as updating a password or something like that. disclaimer: I didn't check to see what database engine you're using. If you're using MySQL, this should work, otherwise use something similiar. -- PHP General 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]
Re: [PHP] User Authentication
Paul Burney [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... on 12/16/01 12:58 PM, Daniel Grace at [EMAIL PROTECTED] wrote: Anyways, though the 401 part works and actually brings up the typical Enter Username/Password box, $PHP_AUTH_USER and $PHP_AUTH_PW are not being set. There are no .htaccess files in the directory (or any parent dirs for that matter), and no AuthType directives all in my httpd.conf file. I have been unsuccessful in determining what is wrong, and am flat out of ideas. My guess would be that register_globals is off. If I recall correctly, $PHP_AUTH_USER and $PHP_AUTH_PW need register_globals on to work like you want them to. Check phpinfo() to see if another variable, maybe one in the new arrays, will give them to you. If not, you can look for the Authorize Header and then manually parse out the User and PW information. Paul ?php /* Happy Holidays */ mysql_select_db('North_Pole'); mysql_query('SELECT reindeer FROM stable WHERE nose_color=red'); ? Bah, my test page displayed a phpinfo() and I never noticed this... For some reason You were correct. $PHP_AUTH_USER and $PHP_AUTH_PW reside in _$SERVER under PHP 4.1.0 (and thus presumably $HTTP_SERVER_VARS under PHP 4.0.6) This means I can actually get back to making progress on my site... -- Daniel Grace Warning: Undefined variable: signature in email.php on line 35 -- PHP General 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] Re: problem finding out original filename while using php to upload.
Neil M [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I am using php to upload image files. heres my code .. ? if (is_uploaded_file($photo_file)) { clearstatcache (); $size = filesize ( $photo_file ) ; if ( $size 1024000 ) { print (BR ERROR - File is too big ! File uploads should be below 1024 k ( 1mb ) BR); exit ; } move_uploaded_file($photo_file, $upload_path$check_nick-nickname); } else { echo BR ERROR : File upload was not successfull , please try again !BR; } ? -- the problem is that when i look for the original filename ( e.g. myphoto.gif ) , $photo_file contains a random file name like 383hr93php As i mentioned , its image files i am uploading , how do i know what type of image the file was ? like .jpg , .png etc. Any help appreciatted , i am really stuck on this ;0) Thanks Neil M $photo_file will map to the name of the temporary file on the server's HD -- it is NOT the name of the original file. You'll want to use $photo_file_name to determine the original filename, or better yet, $photo_file_type to determine the content type. (a gif is image/gif, for instance). See http://www.php.net/manual/en/features.file-upload.php -- Daniel Grace echo make_witty_sig($foo) . \n; -- PHP General 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] HTTP Authentication problems
Hello, I'm working on a website for what will eventually be free PHP/MySQL/Apache/DNS/etc hosting (see: http://hosting.venura.net , no requests for accounts will be entertained right now), and am having problems trying to get HTTP Authentication working. I had it working a month or so ago, but then I put the project on hold for awhile and came back to a mess that wasn't -- don't know how unless I somehow broke it just before I quit working on it. Anyways, I'm running PHP 4.1.0 (had same problems with 4.0.6 earlier so I know it's not some weird bug with the new version), Apache 1.3.22+mod_ssl and Linux 2.4. I'm working (for now) with a small test script containing this (and running on SSL, which I had no problems with earlier.) --- ?php header(HTTP/1.0 401 Unauthorized); header(WWW-Authenticate: Basic realm=\hosting.venura.net Member Services U: . $PHP_AUTH_USER . , P: . $PHP_AUTH_PW . \ ); ? html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en head title[secure]venura.net :: Unauthorized/title /head body ?php phpinfo(); ? /body /html --- The idea being that I can see the username/password entered in the authentication box itself. Anyways, though the 401 part works and actually brings up the typical Enter Username/Password box, $PHP_AUTH_USER and $PHP_AUTH_PW are not being set. Neither is $REMOTE_USER. There are no .htaccess files in the directory (or any parent dirs for that matter), and no AuthType directives all in my httpd.conf file. I have been unsuccessful in determining what is wrong, and am flat out of ideas. My php.ini and httpd.conf files are available at http://hosting.venura.net/fixme/ Any ideas? -- Daniel Grace -- PHP General 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] User Authentication
Hello, I'm working on a website for what will eventually be free PHP/MySQL/Apache/DNS/etc hosting (see: http://hosting.venura.net , no requests for accounts will be entertained right now), and am having problems trying to get HTTP Authentication working. I had it working a month or so ago, but then I put the project on hold for awhile and came back to a mess that wasn't -- don't know how unless I somehow broke it just before I quit working on it. Anyways, I'm running PHP 4.1.0 (had same problems with 4.0.6 earlier so I know it's not some weird bug with the new version), Apache 1.3.22+mod_ssl and Linux 2.4. I'm working (for now) with a small test script containing this (and running on SSL, which I had no problems with earlier.) --- ?php header(HTTP/1.0 401 Unauthorized); header(WWW-Authenticate: Basic realm=\hosting.venura.net Member Services U: . $PHP_AUTH_USER . , P: . $PHP_AUTH_PW . \ ); ? html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en head title[secure]venura.net :: Unauthorized/title /head body ?php phpinfo(); ? /body /html --- The idea being that I can see the username/password entered in the authentication box itself. Anyways, though the 401 part works and actually brings up the typical Enter Username/Password box, $PHP_AUTH_USER and $PHP_AUTH_PW are not being set. There are no .htaccess files in the directory (or any parent dirs for that matter), and no AuthType directives all in my httpd.conf file. I have been unsuccessful in determining what is wrong, and am flat out of ideas. My php.ini and httpd.conf files are available at http://hosting.venura.net/fixme/ Any ideas? -- Daniel Grace -- PHP General 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] Re: PHP4.1.0 Apache1.3.22 under WinXP
Christian Calloway [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi everyone, I'm having troubles getting Apache to recognize .php files, and thus parse them. I followed the instructions included with the PHP4.1.0 distribution, and have PHP loaded as an Apache module, checking my services confirms this as its description reads Apache/1.3.22 (Win32) PHP/4.1.0. But when I attempt to load a .php file, I will get the entire file, unparsed. I added the following two lines to my httpd.conf file: LoadModule php4_module C:\Apache.MySQL.PHP\PHP\sapi\php4apache.dll AddType application/x-httpd-php .php Am I missing something? Thanks, Christian I don't see anything missing, taking a look at my own (working as far as that goes) config at http://hosting.venura.net/fixme/httpd_conf.txt Are you sure that you have short_open_tags or the asp style tags enabled in your php.ini file [if you're using them.] If you don't have them enabled but are using them in your pages, it'll seem to not work. The easiest way to check to see if that's the problem, short of checking php.ini, is to make a quick and dirty test page: ?php phpinfo(); ? ? /* If you can see this, then short_open_tags = off. Of course, if phpinfo() is displayed above, this should be fairly obvious */ ? % /* If you can see this, then asp_style_tags = off. Of course, if phpinfo() is displayed above, this should be fairly obvious */ % -- Daniel Grace No ASP, ever. - from the venura.net announcement of hosting.venura.net's hosting services. -- PHP General 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]
Re: [PHP] Nesting 'foreach ()'
"Tim Ward" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... is okay (but still doesn't work) although I have noticed that you seem to need to code-block single statements in if ... else constructs i.e if (1==1) echo("fred") else echo("bill"): should work but doesn't. if (1==1) echo("fred"); else echo("bill"): --^ You need to have a semicolon before the else. - Daniel Grace http://dewin.oldbattery.com/ -- "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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]
Re: [PHP] Undocumented Socket functions?
"Rog" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Can anyone here decipher for me some of the undocumented Socket functions in PHP4? For instance, how do I use select() to multiplex multiple connections? With the functions that are documented, there is a nice example of a simple echoing TCP server, but it only accepts a single connection which has limited usage. Can anyone come up with an example to expand that to multiple connections. I too would be interested in knowing this. I was once (and still am) interested in developing a MUD (= multi-user text-based game) engine entirely in PHP. This would be nice because powerful scripts and stuff like that could be coded within the mud and executed on-the-fly if proper considerations were taken towards stability and security. -- - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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]
Re: [PHP] File Download Completion
On Wednesday, January 31, 2001 at 12:00 PM, "Boaz Yahav" [EMAIL PROTECTED] wrote: Seems like your theory doesn't stand the reality test :) This is the script which for some reason works with Netscape but not with IE (it used to) : ignore_user_abort(0); $filename="test.gz"; $file="/home/examples/" . $filename; header("Content-Disposition: attachment; filename=$filename"); header("Content-Type: application/x-gzip"); header("Content-Length: ".filesize($file)); header("Pragma: no-cache"); header("Expires: 0"); /* $fp = fopen($file, "r"); if(!$fp) { echo"Can't open file for read"; exit(); } print fread($fp, filesize($file)); */ // readfile($file) does the same thing. echo"BRBRBRBRH1BThe file was downloaded successfully/B/H1BRBRBRBR"; For some reason it never shows the last echo weather i let the DL complete or stop it in the middle... Remember that everything you are sending to the browser -- whether it be by print, echo, readfile, or HTML code outside of ?PHP ... ?, becomes the file the user is downloading. If you were to open the gzip file you're sending, you'd notice that the "BRBRBRBRH1BThe file was downloaded/B successfully/B/H1BRBRBRBR" is being appended to the end of that file. -- PHP General 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]
Re: [PHP] Read Vs. Include
On Tuesday, January 30, 2001 at 3:04 PM, Alexandar Skwar wrote: So sprach Daniel Grace am Thu, Jan 25, 2001 at 07:18:52PM -0800: readfile($filename); Why not include? Because include will execute any PHP code in the included file and readfile will not, it just dumps the entire file to the webbrowser. If you want to display the contents of an HTML document and that HTML document should not have any PHP code in it, it's best to play it safe and use readfile(). This is especially true if the HTML document can be visitor modified (say, a guestbook), as not doing so could potentially let anybody execute any PHP code they want on your webserver. - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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]
Re: [PHP] File Download Completion
"Boaz Yahav" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Is it possible to find out if a client finished to DL a file? Suppose i put a link to a file and people start to DL the file. Some people can stop the DL in the middle. I need to know how many people completed the DL. Any simple ideas how to do this? thanks berber One option could be to use ignore_user_abort: ?PHP ignore_user_abort(0); // Script will be aborted if transfer fails for whatever reason ? blahblahblahyaddityyaddiy yaddity ?PHP // If we're this far, it means the file's more or less transferred all the way. file_did_download(); ? Caveats with this: 1. Your file has to be part of the PHP page (though not neccessarily in the file itself, header("content-type: blah/blah"); combined with readfile($filename) will do the trick I think. 2. You (probably) can't use programs that are capable of resuming file transfers. If you can somehow, I have NO idea how it'll react. 3. If the user aborts right after the file_did_download() function is called but before the script actually terminates, things can go awry. I'm not entirely sure how this would be handled. -- - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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]
Re: [PHP] SQL question
"John LYC" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... hi all, does mysql support this? select * from tablename where id in (select id from table2 where cond) thanks No. MySQL does not support so-called sub-selects. Here's an easy workaround in PHP: $result = mysql_query("SELECT id FROM table2 WHERE cond"); $idlist = array(); while($row = mysql_fetch_assoc($result)) { $idlist[] = $row[id]; } $result = mysql_query("SELECT id FROM table1 WHERE id IN(" . implode(", ", $idlist) . ")"); Making sure $idlist actually contains at least one item (if it doesn't the second query will fail) is left as an exercise to the reader. -- - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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]
Re: [PHP] Read Vs. Include
Any of these will work: echo implode("\n", file($filename)); fpassthru(fopen($filename, "r")); readfile($filename); You probably want readfile(). http://www.php.net/manual/en/function.readfile.php -- - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication ""Karl J. Stubsjoen"" [EMAIL PROTECTED] wrote in message 005b01c086fa$ec53ba30$0afc020a@kstubsjoen">news:005b01c086fa$ec53ba30$0afc020a@kstubsjoen... Hello, I want to *read* a file into a page and not process any PHP. I'm just reading an HTML file. I though it was simple, I thought I had it figured out, but now when I try, I get the following error: Fatal error: Call to unsupported or undefined function read() in /var/www/wherever.com/betastore/iscookies.php on line 41 Here is the code (line 41 is superceded by a +): 37: # display no cookies message 38: function NoCookies() { 39: global $DOCUMENT_ROOT; 40: $LocalScript = $DOCUMENT_ROOT . "/betastore"; 41: read ($LocalScript . "/thispage.html"); 42: } Thanks for any help. -- PHP General 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 General 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]
Re: [PHP] sleep and usleep not working ??
""Benny Nissen"" [EMAIL PROTECTED] wrote in message 94k0ql$em$[EMAIL PROTECTED]">news:94k0ql$em$[EMAIL PROTECTED]... Hi All I have tried to get this to work but it does not produce any output in the browser - why $i = 1; while ($i) { if(connection_aborted()) break; echo $i; echo "BR"; $i++; sleep(1); //usleep(1000); } If you're trying to get a delayed output affect (which isn't recommended, but would probably work in this case as long as you're not inside a table), you'll either need to do: ob_implicit_flush(1); // at the beginning of the script (use 0 to turn it back off) or: flush(); // after the echo and before the sleep. Side note: When you're using PHP for shell scripts (Don't look at me like that) and the like, ob_implicit_flush is your friend. -- - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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] News gateway question
I use the news.netimages.com gateway to access this mailing list since I don't feel like getting my mailbox flooded with mail (and wasn't really happy with the way the digest worked). However, I've noticed that the newsgroup only works for reading -- e.g. I can't post messages to it and have to send them to the mailing list. Is there any easy way to post to the group instead? -- - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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] PHP as a MUD engine?
Yes, I know this sounds crazy, but think about it. I've often pondered the feasibility of using PHP as a MUD engine. While it would probably not run nearly as fast as something implemented in C/C++, it would have a lot of flexibility: - Changes to the common code wouldn't neccessarily have to require a restart of the MUD engine but could be implemented on-the-fly. - Rooms, characters, items, etc. could use all the power of PHP's scripting language. This means you can a complex scripting language for them. - We get PHP's flexibility with dealing with strings, etc. - We don't have to worry about malloc() and free() in C -- less potential memory leaks. The biggest issue would be maintaining security, as using PHP to handle room scripts means that anyone who builds for the MUD would be able to run PHP code on the server. You can only imagine what would happen if someone put an exit; in their script, or if the script had errors in syntax. I personally don't yet have the time to undertake such a project (I'm working on the Venura Message Board (= a message board user/character database driven in PHP, intended for use for freeform roleplaying games that are run via a message board system -- see http://dewin.oldbattery.com/venura/ )), but I am interested to see what people think. - Daniel Grace http://dewin.oldbattery.com/ "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication -- PHP General 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]