[FAQTS] PHP Knowledge Base Update -- May 18th, 2000

From: Date: Fri, 19 May 2000 03:23:54 +0000
Subject: [FAQTS] PHP Knowledge Base Update -- May 18th, 2000
Groups: php.kb 
Request: Send a blank email to php-kb+get-49@lists.php.net to get a copy of this message
Thanks to everyone who sent corrections yesterday, they've been integrated with the updates. http://php.faqts.com cheers, Nathan ## Unanswered Questions ######################################## ------------------------------------------------------------- How do I perform a keyword search through text stored in BLOBs? http://www.faqts.com/knowledge-base/view.phtml/aid/3051 ------------------------------------------------------------- Jeff Liu ------------------------------------------------------------- Why can't I run php from command line? http://www.faqts.com/knowledge-base/view.phtml/aid/1746 ------------------------------------------------------------- Charles Chan, Henrik Hansen ## New Entries ################################################# ------------------------------------------------------------- Can I use PHP with Oracle on Windows? How do I enable the Oracle functions with PHP on Windows? http://www.faqts.com/knowledge-base/view.phtml/aid/3010 ------------------------------------------------------------- Nathan Wallace Gregor Zurowski, Zack Beatty Yes, it does have Oracle 8 support. Include the php3_oci80.dll in your php.ini file (via extentsion=php3_oci80.dll). Then you can use all OCI function described in the manual. Don't forget to install Net8 on your machine. Here are the "php3_oci73.dll" functions that you are using (i.e. ora_logon): http://www.php.net/manual/ref.oracle.php3 Here are the "php3_oci80.dll" functions you should be using (i.e. OCIlogon): http://www.php.net/manual/ref.oci8.php3 You need to change all of the old Oracle functions to the new ones in order to use the new oci80.dll. ------------------------------------------------------------- Scalability of PHP. Is it possible to scale a PHP system to several computer through loadbalancing or similar??? HOW?? http://www.faqts.com/knowledge-base/view.phtml/aid/3013 ------------------------------------------------------------- Christian Bjørnbak, Nathan Wallace M.Stolte Sure, but if you use sessions be aware that all the clustered servers can transparently use them, with cookies for example. ------------------------------------------------------------- can php update a textfile that i can use for a flash movie? http://www.faqts.com/knowledge-base/view.phtml/aid/3025 ------------------------------------------------------------- philipp schiedl, Nathan Wallace Maarten Stolte Yes, but afaik flash needs it's texts urlencoded (is this the correct term?). There is a tool which does something like that on freshmeat.net ------------------------------------------------------------- Why do I keep getting a "permission denied" error for Postgres queries? How can I give a user permissions in Postgres? http://www.faqts.com/knowledge-base/view.phtml/aid/3026 ------------------------------------------------------------- Nathan Wallace Doug Semig This answer assumes that you want the Postgres user "nobody" to have permissions. What you have to do now is GRANT permissions for the user "nobody" to do things with your tables. Log in to psql as the owner of the database and type in: GRANT SELECT, INSERT, DELETE, UPDATE ON tablename TO nobody; Type that line in for each table your web application will need to run select, insert, delete, and update queries on. Note that if you don't want to grant the "nobody" user the ability to delete or update, then you'd leave those out of the GRANT statement. ------------------------------------------------------------- What are the advantages of storing session data in a database and not a file? Should I use database session handling or file session handling? http://www.faqts.com/knowledge-base/view.phtml/aid/3027 ------------------------------------------------------------- Nathan Wallace Sascha Schumann, Richard Lynch You need a database in the central-database, multiple-front-web-servers scenario. If you have only one web server, files are good enough. I'm thinking that once you have a database connection open, an extra query to get their session info is probably less than opening / read / closing a file... If you're not already using a database, a straight file-system will be faster, probably. Caveats: You really should spend time building samples and "fake" data and pounding on a server to see where the bottle-neck is going to be, and fixing that bottle-neck to get the most bang for the buck, but it shouldn't be too hard to do a side-by-side comparison of file versus database session-handling with sample date for your system. The file-system solution won't scale to multi-tier architecture too well. The database system will, assuming you can scale your database in the first place. ------------------------------------------------------------- How can I create a color a shade darker than a given hex value? http://www.faqts.com/knowledge-base/view.phtml/aid/3028 ------------------------------------------------------------- Nathan Wallace Phil Driscoll Extract the individual colour components using & and shifts, multiply by a suitable factor (eg 0.9) then recombine $Red=intval((($Color & 0xFF0000)>>16)*0.9); $Green=intval((($Color & 0xFF00)>>8)*0.9); $Blue=intval(($Color & 0xFF)*0.9); $Color=($Red<<16)+($Green<<8)+$Blue; Someone who understands operator precidence better than I do could probably lose a few brackets. There's also probably some cute trick which does the entire job in one shot. ------------------------------------------------------------- How can I access a secure database server from a PHP web server? How should I setup my web server network so the database server is not accessible to people? http://www.faqts.com/knowledge-base/view.phtml/aid/3029 ------------------------------------------------------------- Nathan Wallace Rick Widmer You establish a second, separate network between the web servers and the database server. As long as the web servers don't forward packets the two networks can never communicate, yet the web servers can access both the Internet and the database server. The key to security is not so much locking down the ports on the database server as making sure the web servers do not forward packets to/from the Internet. I'm not saying don't lock down unneeded ports, that is common sense, just pointing out the key is not forwarding packets thru the web servers. How to set it up... Database Server: This machine is fairly normal and has only one network card. Shut off everything but the database server. No sendmail, httpd, etc. Disable anything you don't _need_ in inetd.conf. If you don't need any inetd services don't start the daemon. Pick an IP address from RFC1918 address space. (10.x.x.x, 192.168.x.x and one other block I don't remember.) Add this address to your /etc/hosts files or DNS so web server(s) can find the database server. The Database Network: Connect the database machine to a new hub or switch that is NOT connected to the Internet. If there is only one web server you can use a crossover cable. Connect the second network card in each web server to the database network hub. Make SURE it connects to nothing but web servers that need access to the hidden database server. One possible exception would be a backup server. (As in a box with a tape drive.) It would be able to see the web servers and the database, but not the Internet, or your news and mail servers. Web server(s): Add a second network card. Pick an RFC1918 address in the same subnet as the database server. Connect it to the database network. Make sure IP forwarding is OFF, so the machine will not route packets from one interface to the other. THIS IS VERY IMPORTANT!!! I compile static kernels with IP Forwarding disabled for my servers. Make sure the database server is referenced in /etc/hosts or DNS so you can list it by name in the hostname parameter of all your scripts. Start pointing your scripts at the hidden database server. ------------------------------------------------------------- Why are there 2 functions : OCIParse and OCIExecute? http://www.faqts.com/knowledge-base/view.phtml/aid/3030 ------------------------------------------------------------- Nathan Wallace Arnaud Megret It enables to bind in and out PHP variables with the query. It is possible to call OCIEXecute() multiple times after one call to OCIParse. So you could bind variables to the SQL query, and executes it several times changing the values of the binded variables before each call to OCIExecute. Thus improving speed... ------------------------------------------------------------- It's possible set the timeout for php scripts using IIS? http://www.faqts.com/knowledge-base/view.phtml/aid/3046 ------------------------------------------------------------- Clemente Biondo, Richard Heyes Simply use set_time_limit(). The one argument is the time limit in seconds, eg. set_time_limit(20). Setting it to zero (eg. set_time_limit (0) )will set no time limit. ------------------------------------------------------------- Why do my strings contain strange "%20" type things? http://www.faqts.com/knowledge-base/view.phtml/aid/3055 ------------------------------------------------------------- Nathan Wallace They have been URL encoded, %20 is a fancy way of representing a space. Try the urldecode function: http://www.php.net/manual/function.urldecode.php ------------------------------------------------------------- How can I convert the last modified time for a file to a MySQL datetime? How can I convert the last modified time for a file to a MySQL datetime? http://www.faqts.com/knowledge-base/view.phtml/aid/3056 ------------------------------------------------------------- Nathan Wallace Meir Kriheli Try this: date('Y-m-d H:i:s',filemtime(<filename>) ------------------------------------------------------------- How can I make sure a session stays open during a long file download? http://www.faqts.com/knowledge-base/view.phtml/aid/3057 ------------------------------------------------------------- Nathan Wallace Sascha Schumann When the user starts to download a file, set the timestamp to now + x * s where x is the size of the file currently downloaded and s is the estimated transfer rate (i.e. assume that your customer uses a slow modem). That will prevent the session from being deleted too early. ------------------------------------------------------------- What's the best way to start writing a PHP program? http://www.faqts.com/knowledge-base/view.phtml/aid/3058 ------------------------------------------------------------- Nathan Wallace Matt McClanahan Design, design, design. Figure out, on paper, exactly what you want to do. Otherwise, you'll just be coding your way around with no real goal. Plan on separating content from logic, it'll always assure cleaner, more maintainable code. Usually the apps I write are DB-related, so to use that sort of application as an example, the first step would be nailing down, with fairly broad scope, what sort of data needs to be stored. This doesn't have to mean tracking down every possible facet of information that will ever be pertinent, just get a good idea. Part of the app design may call for it to be extensible anyway, so you don't have to know everything ahead of time. Once you have a good understanding of what data needs to be stored, design your database. Flow charts are your friend. :) Having a visualization of the structure of the DB will come in handy for subsequent steps. Now it's time for an interface between your app and the database. I generally avoid putting direct DB calls in my app as much as possible, your feelings may vary. Now that Pear is around, I've been using that for my abstraction. There are other options, of course. I tend to write three functions for each logical grouping of database fields. For example, if it were a web log, there may be some groups of fields such as Users, Entries, Categories, and Polls. For these, I would write getEntry, setEntry, deleteEntry, getUser, setUser, deleteUser, and so on. I may not find a need to use all these functions, but being able to assume they're there if I come to that point later on is handy. Usually for me the next step is the administrative portion of the app. The screens involved in (using the web log example) logging in as a user, posting a new entry, and perhaps adding a poll. The admin interface tends to have three components to it: The navigation, the forms for input, and the code for validating/DB access. Since separating content from code is good, I tend to have these three components thoroughly separated. The navigation can be done any number of ways, I tend to use button menu screens (You log in, get a Main Menu, click on 'Manage Users', get a User Menu, click on 'Add User', get an Add User form, etc.) For form input, I like to make my forms dual-purpose. That is, the same file can be used for adding a user as it can for editing. It's a simple process, and it's handy for keeping maintenance hassles low. These forms, of course, submit their data to the code that does validation and DB access. So that's the admin side, more or less. Once that's all in place, the only thing left to do is the actual web pages that people will be using. I'm no designer, so I don't relish this part. Thankfully, I work with people who are designers, so often while I'm coding the admin side, they're doing up the templates for the site. Then integration is just a matter of plugging in snippits of PHP to extract a value here, interate through some DB fields there.. Pretty soon, it's all done. (Okay, so it usually doesn't seen like 'pretty soon' when it actually gets finished). Okay, I'll stop rambling now. ------------------------------------------------------------- What are some design techniques for multi-language sites? How can I build a site that supports multiple languages? http://www.faqts.com/knowledge-base/view.phtml/aid/3059 ------------------------------------------------------------- Nathan Wallace Stephan Neander, Pavel Kaess, Dave Goodrich, Rob Hardowa There are a few different ways to approach this complex problem: - templates - include files - Apache with HTTP_ACCEPT_LANGUAGE - gettext Templates ~~~~~~~~~ The apache directive is a good idea although I haven't experimented with it yet. I'm designing a site in English and Spanish, with plans for a Portugese version. I decided to go with templates instead of includes. I originally started out with FastTemplates but after experimenting with it decided on the template calss included with PHPLIB. I wanted to use PHPLIB for sessions anyway so it was a natural. I'm still in the early stages so i can't give you too much information. As far as determining the language, you could use the apache directive, or you could check what Languages are accepted by the client browser and then respond accordingly. This is the option I'm tinkering with. Basically here is how I grab the language. 1. Check the clients browser for what languages it accepts. If one is on your list, feed them that document. 2. Keep track of the language using sessions. 3. always offer, on every page, the option to change to, or view the document in an alternate language. I'm using templates and mysql to cut down on the work and storage requirements of having two of everything. Check out phpbuilder.com for some good tutorials on how and why to use templates. Include Files ~~~~~~~~~~~~~ First create a text file for each language containg entries such as: $lang["msgErr_critical"] = 'Critical Error!'; $lang["msgErr_siteindex"] = 'Unable to create site index.'; $lang["msgErr_notexist"] = 'does not exist.'; This file would be duplicated for each language. Then: $gw_language = 'au'; // Language // This could be set as a default or passed from a form. $gw_dir_idx_base = '/home2/ace/idx/'; // Base IDX location $gw_dir["lang"] = $gw_dir_idx_base.'lang/'; // Language files // This is just to hold the directory where the language files belong. // Include Language File ////////////////////////////////////// include($gw_dir["lang"].$gw_language.".inc"); // This Includes the relevant file Then just do something like the following: $gw_error_msg = $lang["msgErr_notexist"].'<BR>P_IDX: '.$p_idx; So the only thing that needs to change to switch languages is to change the variable $gw_language Apache with HTTP_ACCEPT_LANGUAGE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Curious ourselves we plan to use Apaches ability to select an index paged based on the HTTP_ACCEPT_LANGUAGE arg. For instance the browser ends 'en' we can use Apache to direct them to index.html.en which will load an english php include file. This of course leaves a defualt of english, haven't tried it yet, but we believe it's the best solution we have thought up. gettext ~~~~~~~ See: http://www.faqts.com/knowledge-base/view.phtml/aid/2953/fid/422 http://www.faqts.com/knowledge-base/view.phtml/aid/2832/fid/422 ------------------------------------------------------------- How can I get the date 7 days prior to today? http://www.faqts.com/knowledge-base/view.phtml/aid/3060 ------------------------------------------------------------- Nathan Wallace Chris Boget, Michael Waples First method: $oneDay = 86400; // number of seconds in a day $today = date( "U" ); $weekAgo = $today - ( $oneDay * 7 ); echo "One week ago was: " . date( "F d, Y", $weekAgo ) . "<br>\n"; Second method: $week = strtotime("-1 week"); or $week = strtotime("-7 days"); echo date("l jS F", $week); ## Edited Entries ############################################## ------------------------------------------------------------- How do you install OpenLDAP with PHP and Apache? http://www.faqts.com/knowledge-base/view.phtml/aid/808 ------------------------------------------------------------- Joshua Starr, Henrik Hansen PHP manual You should compile PHP with the following configure flag: --with-ldap=DIR Where DIR is where LDAP is installed. ------------------------------------------------------------- Does PHP work on an AIX platform? http://www.faqts.com/knowledge-base/view.phtml/aid/1346 ------------------------------------------------------------- Jimmy A Blanco, Henrik Hansen Yes the PHP source code should work on most unix platforms, including AIX ------------------------------------------------------------- how can i compile php with mcrypt correctly? i tried, but failed. http://www.faqts.com/knowledge-base/view.phtml/aid/1336 ------------------------------------------------------------- lily xie, Henrik Hansen, Nathan Wallace PHP Manual Compile PHP with the following configure flag: --with-mcrypt Which includes support for the mcrypt library. See the mcrypt documentation for more information[1]. If you use the optional DIR argument, PHP will look for mcrypt.h in DIR/include. 1. The documentations is here: http://www.php.net/distributions/bigmanual.html#REF.MCRYPT ------------------------------------------------------------- On which Operating systems is PHP (successfully) running? http://www.faqts.com/knowledge-base/view.phtml/aid/2030 ------------------------------------------------------------- Wolfgang Schaefer, Henrik Hansen, Nathan Wallace PHP 3.0 maillinglist,Sascha Schumann We have positive reports from at least these unix variants: AIX, OpenBSD, NetBSD, FreeBSD, Linux, IRIX, UnixWare 7, OpenServer, A/UNIX, Tru64, BSDi, Solaris 2, SunOS 4 PHP also runs on: Windows NT, Macintosh, VMS and OS/2 ------------------------------------------------------------- Is it possible to use dl("sharedlib.so") under linux, similar to the way it used under Windows? http://www.faqts.com/knowledge-base/view.phtml/aid/2096 ------------------------------------------------------------- Scott Brause, Henrik Hansen Yes it is, for example if you want to load the mysql functions do: dl(mysql.so); ------------------------------------------------------------- How do I install php3, mysql and apache on windows95? http://www.faqts.com/knowledge-base/view.phtml/aid/2354 ------------------------------------------------------------- Preeti Sikri, Henrik Hansen Look at this page which has docomentation on how to install php/mysql/etc on windows platforms http://www.umesd.k12.or.us/php/win32install.html ------------------------------------------------------------- What should I do to make my php to work with MySQL ? http://www.faqts.com/knowledge-base/view.phtml/aid/2520 ------------------------------------------------------------- Antony Lee, Henrik Hansen, Andrey Zmievski PHP manual Compile PHP with: --with-mysql=DIR Which enables MySQL support. The parameter to this option is the MySQL install directory and defaults to /usr/local. This is the default installation directory of the MySQL distribution. Bofore doing this you should have a working mysql server installed on your system. PHP 4 comes bundled with MySQL client library and it is enabled by default, thus obviating the need for --with-mysql, unless you have a newer version installed somewhere else. ------------------------------------------------------------- Is there a port of PHP for OpenVMS? http://www.faqts.com/knowledge-base/view.phtml/aid/2863 ------------------------------------------------------------- Istvan Banfi, Henrik Hansen Yes the php source should compile under vms platforms. ------------------------------------------------------------- How can I find out what the date of the last monday was without year/month concerns? http://www.faqts.com/knowledge-base/view.phtml/aid/2988 ------------------------------------------------------------- Dave Mitchell, Bill Pargeter The following _should_ determine the date of the last Monday (or today, if today's Monday): $MonDate = mktime(0,0,0, (int)date("m"), (int)date("j") - (((int)date("w") + 6) % 7), (int)date("Y")); The principle is to use the 'day of week' to offset the 'day of month' and let mktime() do the rest. Disclaimer: It's not thoroughly tested -- comments/corrections welcome! ------------------------------------------------------------- I'm looking for doc's on php_admin_value and php_admin_flag. Any idea where I could find them? I have looked at zend.com and php.net with no luck. http://www.faqts.com/knowledge-base/view.phtml/aid/2990 ------------------------------------------------------------- Thomas J. Mackie III, Nick Vasilogianis taken from "Professional PHP Programming" php_admin_value: name value - This sets of admin related variable specified by name to value. Administrative configuration settings can only be set from within th emain Apache configuration file(httpd.conf), and not from the .htaccess files. php_admin_flag: name on|off - This is used to set to either on or off any admin-related boolean configuration option specified by the name.

« previous php.kb (#49) next »