[FAQTS] PHP Knowledge Base Update -- January 26th, 2000

From: Date: Wed, 26 Jan 2000 07:34:38 +0000
Subject: [FAQTS] PHP Knowledge Base Update -- January 26th, 2000
Groups: php.kb 
Request: Send a blank email to php-kb+get-42@lists.php.net to get a copy of this message
Thanks to everyone who has been contributing their time and knowledge. Please don't hesitate to jump in and edit other people's answers. There is full version control and email alerts so you won't be treading on any toes. :-) http://php.faqts.com Cheers, Nathan ## Unanswered Questions ######################################## ------------------------------------------------------------- Can you include and call C libraries in PHP scripts? How? http://www.faqts.com/knowledge-base/view.phtml/aid/680 ------------------------------------------------------------- Karen Daly ------------------------------------------------------------- What WebServer should I use for PHP3 or PHP4? And where can I get it? http://www.faqts.com/knowledge-base/view.phtml/aid/686 ------------------------------------------------------------- Trae Robrock ------------------------------------------------------------- How can I setup PHP3 with Linux and an Apache with an MS-SQL 6.5 Server under NT4.0 http://www.faqts.com/knowledge-base/view.phtml/aid/692 ------------------------------------------------------------- Guest ------------------------------------------------------------- How can I have 2 entries in one field? http://www.faqts.com/knowledge-base/view.phtml/aid/694 ------------------------------------------------------------- Chris N ------------------------------------------------------------- How can I get PHP to create javascript that updates field 2 based on field 1 in a select box? http://www.faqts.com/knowledge-base/view.phtml/aid/674 ------------------------------------------------------------- Richard Kurth, Okke Tijhuis, Nathan Wallace http://px.sklar.com/ See the "PX: PHP Code Exchange" site (http://px.sklar.com/) Go to the HTML section and look at the following: Dynamic Selectors by Leon Atkinson: Builds JavaScript that updates the contents of one selector based on another ## New Entries ################################################# ------------------------------------------------------------- Where do I use the configure command --with-xml? How can I setup PHP with XML support? http://www.faqts.com/knowledge-base/view.phtml/aid/683 ------------------------------------------------------------- Vladas Lapinskas, Assaf Nadler, Nathan Wallace This is command-line option for configure script, use it ./configure --with-xml or ./configure --with-xml=/path/to/xml/install/directory ------------------------------------------------------------- How do I insert a client-side file into a BLOB in an Oracle or mySQL database? How can I let users upload files and store them in a database? http://www.faqts.com/knowledge-base/view.phtml/aid/677 ------------------------------------------------------------- Matt Gregory, Ronell Alberts, Nathan Wallace Create a form to upload the file using the <input type="file" name="ClinetFile"> field item. Check the php documentation on uploading files for mor information onthis. To insert the file into the database: <? //The file is placed in the webservers temp folder... //use the fopen method to get the file data into a variable... $filehandle = fopen($ClientFile); $filedata = fread($filehandle, filesize($ClientFile)); //you must make it compatable with the string type of the query... $filedata = addslashes($filedata); //put the data into the blob field... ora_do("Insert into mydatabase (myblobfield) values ($filedata)"); ?> ------------------------------------------------------------- How can PHP make a SSL encrypted post to a transaction server? http://www.faqts.com/knowledge-base/view.phtml/aid/697 ------------------------------------------------------------- Matt Allen cURL (http://curl.haxx.nu/) PHP3 cannot not talk SSL nativley, therefore to make an SSL post you need to enlist the help of a little app called cURL. cURL is a command line driven app that accepts data and simulates posting a form to an SSL website. The data returned depends on the server we are posting to, although usually it is returned as a comma serperated line. cURL is called via the exec() command in PHP. Here is an example of a line that calls cURL. exec("/usr/local/bin/curl -m 120 -d \"$data\" https://$URL -L",$return_message_array, $return_number); -m is the timeout in seconds -d is the data you wish to post ($data="var=value&var1=value1") $URL is the https page you are posting to, The way i walk though the results is: for ($i = 0; $i < count($return_message_array); $i ) { $results = $results.$return_message_array[$i]; } $results then contains all the data that was returned from the server. ------------------------------------------------------------- Why does my browser try to save rather than open my PHP scripts? http://www.faqts.com/knowledge-base/view.phtml/aid/698 ------------------------------------------------------------- Nathan Wallace Marco Garbelini The problem is in the server not in the browser. The server must parse and execute the .php3 file instead of just give it to the client. You must configure the webserver to do this. ------------------------------------------------------------- Is there a way to pretokenise PHP scripts? http://www.faqts.com/knowledge-base/view.phtml/aid/699 ------------------------------------------------------------- Nathan Wallace Richard Lynch No. The pretokenizing was a failed attempt at a performance gain, and has not been maintained. PHP4/Zend will allow you to purchase a compiler that will create distributable binaries that offer the functionality most people want when they ask for pretokenizing: Code-hiding and performance. Actually, I'm not sure you'll even have to pay anything for the redistributable compiler: Maybe only the optimizer. See http://www.zend.com to verify. ------------------------------------------------------------- How can I force users to choose at least one checkbox from a group? http://www.faqts.com/knowledge-base/view.phtml/aid/701 ------------------------------------------------------------- Nathan Wallace Manuel Lemos There is a PHP Form generation and validation class that among other things does just that. Take a look here. There's an example that shows exactly how to make the kind of validation you want: http://phpclasses.UpperDesign.com/browse.html/package/1 You might prefer to do the check in Javascript before the form is submitted to the server. ------------------------------------------------------------- How can I get the size of an IMAP message? http://www.faqts.com/knowledge-base/view.phtml/aid/702 ------------------------------------------------------------- Nathan Wallace npguy, Chuck Hagenbuch Here, $mbox is a pointer to the inbox and $x is the message number: $mailsize = imap_fetchstructure($mbox, $x); You can retrieve the total size of the message with: $size = $mailsize->bytes; ------------------------------------------------------------- What happens when I cast an object as an array? How do I get a list of object properties? http://www.faqts.com/knowledge-base/view.phtml/aid/705 ------------------------------------------------------------- Leon Atkinson If you cast an object as an array, all the properties will become elements in an array. The indices will be the names of the properties. The methods will be unavailable. Once you have an array, you can loop over all the elements. ------------------------------------------------------------- Can I connect to a NNTP server from PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/707 ------------------------------------------------------------- Nathan Wallace David Coulson Yup. Check the docs for imap. it's basically exactly the same, except you have to tell it to connect using nntp to port 119. ------------------------------------------------------------- What pages need to be secure when accepting credit cards? What sequence of pages should I use for credit card transactions? http://www.faqts.com/knowledge-base/view.phtml/aid/708 ------------------------------------------------------------- Nathan Wallace Brian Clark First connection: http://www.domain.com/ Order connection: https://www.domain.com/orderform.php3 User enters card info Thanks page: https://www.domain.com/securepage.php3 User continues to another page at the site: http://www.domain.com/index.php3 Note the http/https differences. As a general rule, you make the SSL connection before any sensitive info is even typed into the browser, otherwise you defeat the purpose of SSL. ------------------------------------------------------------- Does return in an include file stop the entire script? http://www.faqts.com/knowledge-base/view.phtml/aid/710 ------------------------------------------------------------- Nathan Wallace Richard Lynch In PHP3, if you use something like this: if (isset($some_more)) return; $some_more = 1; blahblahblah; . . . The return, *NOT* inside {} brackets, will return from the include file. But this will break in PHP4, so avoid it. Instead: if (!isset($some_more)){ $some_more = 1; blahbalhbalh; } ------------------------------------------------------------- Are the results of readdir() sorted? http://www.faqts.com/knowledge-base/view.phtml/aid/711 ------------------------------------------------------------- Nathan Wallace Torben Wilson, David Coulson It'll just return the order they are stored in the directories file list, which is _usually_ oldest first, although it depends upon the filesystem your using. I personally wouldn't rely on them coming out in any sort of order. PHP returns the entries in whatever order the system C library readdir() returns them. PHP imposes no order of its own on the sort order. Here is the manual entry: http://www.php.net/manual/function.readdir.php3 ------------------------------------------------------------- Are PHP variable names case sensitive? http://www.faqts.com/knowledge-base/view.phtml/aid/713 ------------------------------------------------------------- Nathan Wallace PHP variable names are case sensitive. So, $var is not the same variable as $Var or $VAR or any other permutation. ------------------------------------------------------------- Where can I find documentation on adding internal functions to PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/714 ------------------------------------------------------------- Nathan Wallace Richard Lynch In the source tarball there is a file (somewhere) called apidoc.txt. Use that with the source of a simple PHP function you think you understand that you think works kinda like yours. ------------------------------------------------------------- How do I setup so mail() will work under windows? http://www.faqts.com/knowledge-base/view.phtml/aid/715 ------------------------------------------------------------- Nathan Wallace Phil Driscoll No problem. Just set: SMTP = the.mail.server.name ;for win32 only sendmail_from = you@wherever.com ;for win32 only in your php.ini file and then call the mail function as described in the manual. ------------------------------------------------------------- How can I remove profanity from a string? How can I censor selected words from a string? http://www.faqts.com/knowledge-base/view.phtml/aid/716 ------------------------------------------------------------- Nathan Wallace Richard Lynch Try using this function: <?php function sanitize($text){ //Any George Carlin or FCC fans remember the whole "deadly 7"list? static $naughty = array('shit', 'fuck'); while (list(,$bad) = each($naughty)){ $text = str_replace($bad, make_string('*', strlen($bad)), $text); } return $text; } ?> Note: Sure wish there was a stri_replace... And make_string is a PHP4 thing, so you may need to roll your own. ## Edited Entries ############################################## ------------------------------------------------------------- How can I let a user upload a file to the server in PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/18 ------------------------------------------------------------- Nathan Wallace Matt Allen,Tom Walsh The temporary file created by the upload only lasts until the script has ended, so you need to copy the file somewhere. if ($userfile<>"none") { if(!copy($userfile,"/choose/your/path/$userfile_name")) { print "File failed to upload"; } else { print "File uploaded"; } } The ENCTYPE parameter is required in your HTML to have the files actually upload. <form action="upload.php3" method="post" enctype="multipart/form-data"> Also when you upload a file there are other variables associated with the uploaded file name. I am calling them from memory so I could be wrong, but they would be something like: $picture_name = Original File Name $picture_size = Original File Size $picture_info = Original File Type (But I am not sure if this one is correct or I am just getting it confused with something else.) ------------------------------------------------------------- Are there any free PHP shopping carts available? http://www.faqts.com/knowledge-base/view.phtml/aid/88 ------------------------------------------------------------- Nathan Wallace, Leon Atkinson Olivier PRENANT FishCart <http://www.fishcart.org/> and FreeTrade <http://www.working- dogs.com/freetrade/> are two. Check www.freshmeat.net for others. ------------------------------------------------------------- How can I search the PHP Knowledge Base from a bookmark? http://www.faqts.com/knowledge-base/view.phtml/aid/344 ------------------------------------------------------------- Leon Atkinson Create a bookmark to the following URL: javascript:query=window.prompt('PHPKB:',''); if(query && query != '') { window.location ='http://www.faqts.com/knowledge- base/search/index.phtml?search='+query; } else { history.go(-1); } This code must be all on one line. When you click on this bookmark a small dialog will appear. Enter a search into the text box and you will taken to the PHPKB site where your search results will be listed. ------------------------------------------------------------- How do I implement a stack? How do I emulate PERL's push() and pop()? http://www.faqts.com/knowledge-base/view.phtml/aid/345 ------------------------------------------------------------- Leon Atkinson The following functions implement a stack (First In, Last Out) in PHP3. If using PHP4, use the built-in functions (array_push, array_pop). <? //adds an item to the stack function push($item, &$array) { //add item to end of array $array[] = $item; //return the size of the stack return(count($array)); } //removes item from stack function pop(&$array) { //get size of stack $count = count($array); //get the item $item = $array[$count - 1]; //delete it from the stack unset($array[$count - 1]); //return the item return($item); } print(push('Apple', $myArray) . " items on stack<BR>\n"); print(push('Ball', $myArray) . " items on stack<BR>\n"); print(push('Cat', $myArray) . " items on stack<BR>\n"); print(pop($myArray) . "<BR>\n"); print(pop($myArray) . "<BR>\n"); print(pop($myArray) . "<BR>\n"); ?> ------------------------------------------------------------- How do I set up PHP so the mail() function works with qmail? Why won't the mail() function work with qmail? http://www.faqts.com/knowledge-base/view.phtml/aid/433 ------------------------------------------------------------- Nathan Wallace, Joyce Park Sheamus Nulty Try making qmail's "sendmail" wrapper available to MUAs and leave your php3.ini as it was for sendmail. Here are sample unix commands: # ln -s /var/qmail/bin/sendmail /usr/lib/sendmail # ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail The whole sendmail wrapper thing seems pretty pointless to me. I configured php.ini to inject directly into the qmail bloodstream: /var/qmail/bin/qmail-inject. Works for me. ------------------------------------------------------------- How can I build a Yahoo-like link directory using PHP and MySQL? http://www.faqts.com/knowledge-base/view.phtml/aid/468 ------------------------------------------------------------- Rolf Ostergaard, Leon Atkinson, Nathan Wallace Go to http://www.cable-modems.org/phpHoo/ for the full story. Or check out http://www.clearink.com/conservatory/ for an alternative. ------------------------------------------------------------- What are the differences between GET and POST? Is there a limit on the size of GET and POST requests? http://www.faqts.com/knowledge-base/view.phtml/aid/638 ------------------------------------------------------------- Nathan Wallace Richard Lynch,Damien Mc Kenna, Scott Stevenson, Eugene Teo Variable data is sent as part of the URL for GET requests. In POST requests it is sent as a separate HTTP header. If you use GET, info is logged by the server (apache). For example, if you submitted password in cleartext, we can see it. POST request data is not usually logged. There used to be a limit on the length of GET requests. Now it's technically "unlimited" by spec, but individual servers are allowed to impose a limit no lower than the old limit. Ditto for POST, only POST was a higher old limit. Still can't rely on the Browser, intermediary servers, and your server to all transmit anything over the old limit (4K?) for POST. If you have that much stuff to schlep around, re-design you app to store it server side, and pass around a token to the user to maintain session state: PHP4 session functions or http://phplib.netuse.de are good, and there are others, or you could roll your own, if you understood everything in PHPLIB to start with. ------------------------------------------------------------- How do global variables and functions work? Do I declare global variables at the top level or inside functions? http://www.faqts.com/knowledge-base/view.phtml/aid/665 ------------------------------------------------------------- Nathan Wallace, John Coggeshall Torben Wilson It's all in the manual, under "Language Reference/Variables/Variable Scope": http://www.php.net/manual/language.variables.scope.php3 The basic idea is that global variables are not available within functions by default. To change that, use the 'global $varname;' statement within your function to allow access. Or use $GLOBALS['varname']. In a example: <?php int $myint = 12; function myfuct() { echo "My Int is: $myint<BR>"; global $myint; echo "My Int is now: $myint<BR>"; echo "My Int can also be: $GLOBALS['myint']<BR>"; } ?> Result: My Int is: My Int is: 12 My Int can also be: 12 Hope that makes it more clear ------------------------------------------------------------- How do I get an image in a mySQL/Oracle (or other) blob fields to display on a regular html page? http://www.faqts.com/knowledge-base/view.phtml/aid/666 ------------------------------------------------------------- Matt Gregory //The problem is that binary data cannot be inserted directly into //an html file, so we must trick the browser into thinking it's //retrieving an image on the webserver. To do this place an //image tag on the page with the src set to a php script which returns //nothing but a header and the image. The exampe below will return the //image and fill in the image tag properly... //example image tag <image src="getimage.php3?ImgID=1"> //getimage.php3 if($ImgID != 0) { $Query = "Select Image from Images where ImgID = $ImgID"; mysql_connect($DBHOST, $DBUSER, $DBPASS); mysql_select_db($DATABASE); $resultset = mysql_query($Query); if(mysql_affected_rows() > 0) { header("Content-type: image/jpeg"); print(mysql_result($resultset, 0, "Image")); } } ------------------------------------------------------------- How can I echo all the keys and values of an array? http://www.faqts.com/knowledge-base/view.phtml/aid/672 ------------------------------------------------------------- Steve Vadla, Vladas Lapinskas, Nathan Wallace To list both variables (keys) names and values, use the following script while(list($key,value)=each($arr)) echo "$key = $value"; ------------------------------------------------------------- How can I get PHP to create javascript that updates field 2 based on field 1 in a select box? http://www.faqts.com/knowledge-base/view.phtml/aid/674 ------------------------------------------------------------- Richard Kurth, Okke Tijhuis, Nathan Wallace http://px.sklar.com/ See the "PX: PHP Code Exchange" site (http://px.sklar.com/) Go to the HTML section and look at the following: Dynamic Selectors by Leon Atkinson: Builds JavaScript that updates the contents of one selector based on another

« previous php.kb (#42) next »