PHP Knowledge Base Update -- July 9th, 1999

From: Date: Sat, 10 Jul 1999 18:01:07 +0000
Subject: PHP Knowledge Base Update -- July 9th, 1999
Groups: php.kb 
Request: Send a blank email to php-kb+get-13@lists.php.net to get a copy of this message
Today I added the ability for the knowledge base to display questions and answers in French, German, Italian, Portugese and Spanish. The original English is just translated on the fly using: http://babelfish.altavista.com This is a purely experimental feature that I added because it was cool and it may help some people in understanding knowledge base entries. So don't get too upset by these known problems: - non-English pages will be slower due to translation requests - formatting is lost - the PHP code is also translated - failed translations are shown in English I'd be very interested to hear from people as to the quality of the translations. I couldn't even tell you if they are the correct language...<g> Cheers, Nathan ------------------------------------------------------------ How can I log users out of a page after a certain time period? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/481 ------------------------------------------------------------ Chris Adams Stuff a META tag in the generated html: <META HTTP-EQUIV="REFRESH" CONTENT="300;logmeout.php3"> This would cause the browser to load the logout page ("Your session has been timed out. Click here to login again.") after 300 seconds had passed from the page being loaded. If you wanted to be nice, you could have a 270 second time in JavaScript (basically, you create a function and then call settimer from the body OnLoad handler to run it) that pops up a dialog like "Your session will be timed out in 30 seconds. Cancel the timeout [Yes] [No]", which will do a reload on that page if they choose to cancel the timeout. ------------------------------------------------------------ How can I get data from another web page into PHP? Can I retrieve an external web page using PHP? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/482 ------------------------------------------------------------ Jim Winstead, Manual Lemos You can download a web page from another site using fopen("http://...", "r") http://www.php.net/manual/function.fopen.php3 But you should look at whether that site allows you to do what you want. It may not if they make their money by serving up banner ads on the pages they serve up for you. If you need to get the page via a proxy or using POSTed forms, check out: http://phpclasses.UpperDesign.com/browse.html?package=3 ------------------------------------------------------------ Is it possible to change the dn for an LDAP record? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/484 ------------------------------------------------------------ Nick Talbott See the notes at http://www.php.net/manual/function.ldap-modify.php3 Access to the LDAP API function that can directly change the dn is not provided in the PHP interface. ------------------------------------------------------------ What does "call to unsupported or undefined function" mean? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/485 ------------------------------------------------------------ Nathan Wallace This is the error reported by PHP when it cannot find the code for a function that you have called. This generally occurs when: 1. You have not compiled in support for those functions. For example, all of the database support in PHP must be compiled into the server before it is available. If you want to use the MySQL functions then you need to compile PHP with support for MySQL. 2. You haven't written the code for that function yet. ------------------------------------------------------------ How does autocommit work in Oracle and PHP? Are two identical Oracle sessions in a script part of the same transaction? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/486 ------------------------------------------------------------ Thies C. Arntzen What happens is: Oracle transactions work on the connection-level, and by default connection will be reused as long as a "page" (or the httpd if you use plogon) runs. (as long as u use the same u/p combination. sample: $c1 = ocilogon("scott","tiger"); $s1 = ociparse($c1,"insert into t (1)"); ociexecute($s1,OCI_DEFAULT); $c2 = ocilogon("scott","tiger"); $s2 = ociparse($c2,"insert into t (2)"); ociexecute($st,OCI_DEFAULT); ocicommit($c1); // THIS WILL COMMIT BOTH statements, as $c1 and $c2 // are ONE session with different service-contexts! This is important to understand. The reason this is done (btw: same in ora_* stuff and maybo others) is that usually we're looking for speed and establishing session is very expensive with oracle! But there's a way to isolate transactions: ocinlogon() http://www.php.net/manual/ref.oci8.php3 ocinlogon will create a new session on the server (so here we got the connection-overhead) but this one will be isolated from all other session! The example below illustrates this behaviour. sessions created with ocinlogon are never persistent! but if you need your "own-private" transaction context that's the way to go. (but they will still share the server-connection with other ocilogon, ociplogon calls) Some more explanation: ocilogon, nlogon, plogon are divided into two parts: we have user,pw and service OCIServerAttach is called EXACTLY once for every diffrent service you reference in a script (this call creates the oracle shadow-process) OCISessionBegin is called EXATLY once for every different pair uf user/pw combination. (here is our problem!) if you use ocinlogon a new OCISessionBegin is issued (no new server-connection if we already have a match). Example of the use of ocinlogon: <?php //set_time_limit(0); //ociinternaldebug(1); $db = ""; $c1 = ocilogon("scott","tiger",$db); $c2 = ocinlogon("scott","tiger",$db); /*$co1 = array(); $co2 = array(); $co3 = array(); for ($i = 0; $i < 10; $i ++) $co1[] = ociplogon("scott","tiger",$db); for ($i = 0; $i < 10; $i ++) $co2[] = ocilogon("scott","tiger",$db); for ($i = 0; $i < 10; $i ++) $co3[] = ocinlogon("scott","tiger",$db); $db = "godzilla"; $c1 = ociplogon("scott","tiger",$db); $c2 = ocilogon("scott","tiger",$db); $c3 = ocinlogon("scott","tiger",$db); $co1 = array(); $co2 = array(); $co3 = array(); for ($i = 0; $i < 10; $i ++) $co1[] = ociplogon("scott","tiger",$db); for ($i = 0; $i < 10; $i ++) $co2[] = ocilogon("scott","tiger",$db); for ($i = 0; $i < 10; $i ++) $co3[] = ocinlogon("scott","tiger",$db); */ function create_table($conn) { $stmt = ociparse($conn,"create table scott.hallo (test varchar2(32))"); ociexecute($stmt); echo $conn." created table\n"; } function drop_table($conn) { $stmt = ociparse($conn,"drop table scott.hallo"); ociexecute($stmt); echo $conn." dropped table\n"; } function insert_data($conn) { $stmt = ociparse($conn,"insert into scott.hallo values(sysdate)"); ociexecute($stmt,OCI_DEFAULT); echo $conn." inserted hallo\n"; } function delete_data($conn) { $stmt = ociparse($conn,"delete from scott.hallo"); ociexecute($stmt,OCI_DEFAULT); echo $conn." deleted hallo\n"; } function commit($conn) { ocicommit($conn); echo $conn." commited\n"; } function rollback($conn) { ocirollback($conn); echo $conn." rollback\n"; } function select_data($conn) { $stmt = ociparse($conn,"select * from scott.hallo"); ociexecute($stmt,OCI_DEFAULT); echo $conn."----loading\n"; while (ocifetch($stmt)) echo $conn." <".ociresult($stmt,"TEST").">\n"; echo $conn."----done\n"; } create_table($c1); insert_data($c1); select_data($c1); select_data($c2); rollback($c1); select_data($c1); select_data($c2); insert_data($c2); commit($c2); delete_data($c1); select_data($c1); select_data($c2); commit($c1); select_data($c1); select_data($c2); drop_table($c1); ?> ------------------------------------------------------------ Can I call a function with an optional argument referenced by name? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/488 ------------------------------------------------------------ Chad If your function looks like: function myfunction ( $req_prm1, $req_prm2, $opt_prm1 = "", $opt_prm1 = "", $opt_prm2 = "", $opt_prm3 = "") { // .. some code ... } You can call it as follows to only specify the third optional argument: // legal $result = myfunction($somedata,$somemore, "", "","an option"); You *cannot* specify the optional argument by name. The following is illegal in PHP: // illegal $result = myfunction($somedata,$somemore, $opt_prm3 = "an option"); The closest you'll get is passing an array to the function. The array can then have an arbitrary number of elements, and you can use only the ones set. ------------------------------------------------------------ Can I access Javascript variables in my PHP script? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/489 ------------------------------------------------------------ John Coggeshall Remember that Javascript runs on the client computer, while PHP runs on the server. That means that for Javascript variables to be accessible in PHP you must send them from the client to the server. You can POST javascript variables back to PHP. ------------------------------------------------------------ How can I replace the contents of a file? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/490 ------------------------------------------------------------ Alexander Avilov, Brad Marsh Check the mode parameter for http://www.php.net/manual/function.fopen.php3 'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. Here is an example: @$fp = fopen ("$notify", "w"); fwrite ($fp, $email_file) or die("Couldn't write e-mail file!"); @fclose ($fp); This was a script to write a file to be emailed. Every time it was called the $email_file variable was written to $notify (a path/file name combo). ------------------------------------------------------------ Why is my text insert into MSSQL being truncated? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/491 ------------------------------------------------------------ Brad Marsh, Frank M. Kromann the mssql module uses two parameters in php3.ini to control the size and limit of text columns. mssql.textsize = 4096 (0-64kb) mssql.textlimit = 4096 (0-2Gb) try setting one or both params. ------------------------------------------------------------ Why do uppercase words always sort before lower case words? How can I convert a string to lower case letters only? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/492 ------------------------------------------------------------ Nathan Wallace Uppercase always sorts before lowercase. This is because letters are sorted by their ASCII (numerical) representation. You can make any string lowercase by using: http://www.php.net/manual/function.strtolower.php3 ------------------------------------------------------------ How can I a concatenate two arrays together? How can I merge two arrays? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/494 ------------------------------------------------------------ Paul Schreiber, George Brown If you have: $foo = array(a=>b, c=>d); $bar = array(e=>f, g=>h); then do: $boo = $foo + $bar; concatenating the two arrays to get the result: $boo = array(a=>b, c=>d, e=>f, g=>h);

« previous php.kb (#13) next »