Podstrony
- Strona startowa
- PHP Kompendium Programisty Blake Schwendiman PL
- php manual pl (2)
- Matthews M., Cole J., Gradecki J. MySQL and Java Developer Guide
- Heath Lorraine Najwspanialsi kochankowie Londynu 03 Przebudzenie w ramionach księcia
- Mikser analogowy ALLEN&HEATH seria PA i CP. Instrukcja PL
- Morressy John Kedrigern i wilkolaki
- Piotr Sztompka Socjologia
- Eddings, Dav
- Brust Steven Yendi
- [2]Erikson Steven Bramy Domu Umarlych
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- bless.xlx.pl
[ Pobierz całość w formacie PDF ]
.Something like this:function safe_query ($query = ){if (empty($query)) { return FALSE; }if(QUERY_DEBUG == Off ){$result = mysql_query($query) or3537-4 ch08.f.qc 12/15/00 15:23 Page 204204 Part III: Simple Applicationsdie ( Query failed: pleaseconatact the Webmaster );}else{$result = mysql_query($query)or die( ack! query failed: . errorno=.mysql_errno(). error=.mysql_error(). query=.$query);}return $result;}FROM /GUESTBOOK2K/HEADER.PHPOnce again, this file will be included in every page in this application.It will keepall of the functions specific to this application.In addition, there are a few detailsthat the first few lines of this application will see to.Notice the use of the variable$DOCUMENT_ROOT.This is an Apache variable, accessible through PHP, which indi-cates the default root folder.By making use of this variable, our entire applicationbecomes portable.If we move the entire book folder and all of its sub-folders, thesefiles will be found and accessed properly.Keep in mind that this is an Apache vari-able; your operating system and Web server may require a different variable.Checkphpinfo() to make sure.include( $DOCUMENT_ROOT/book/functions/charset.php );include( $DOCUMENT_ROOT/book/functions/basic.php );$conn = mysql_connect( localhost , username , password ) ordie( could not connect to database );mysql_select_db( guestbook2k , $conn)die( could not select guestbook2k );define( PAGE_LIMIT , 2);The first line includes our default character set.The charset.php file contains justone line:header( Content-Type: text/html; charset=ISO-8859-1 );3537-4 ch08.f.qc 12/15/00 15:23 Page 205Chapter 8: Guestbook 2000, the (Semi-)Bulletproof Guestbook 205This function will help prevent people from sending you values encoded in a dif-ferent character set.If they did send text in a different character set, the functionsin cleanup_text() would fail, and you would still be open to some cross-sitescripting hacks.This is a difficult problem.If you want more details check out thesearticles:http://www.cert.org/tech_tips/malicious_code_mitigation.htmlhttp://www.apache.org/info/css-security/encoding_examples.htmlHere we ve included something interesting: a constant, here named PAGE_LIMIT.A constant is like a variable in that it contains a value (in this instance, 2).However,that value cannot be changed by a simple assignment or by functions other thandefine().Constants do not run into the same scope problems that are encounteredwith variables, so they can be used within functions without having to pass them isarguments or worry about declaring globals.After running the define() function,the constant PAGE_LIMIT will be available everywhere in my script.PAGE_LIMIT decides the number of entries that will be viewable on each page.You are welcome to change this if you would like to see a larger number.If you are putting together a query using a constant, you will have to endTipyour quoted string in order to make use of the constant value.For example,query = select * from db_name limit PAGE_LIMITwill confuse MySQL, because PHP has not replaced the name of the constantwith its value.However, this will work:query = select * from db_name limit .PAGE_LIMITPHP has many built-in constants you can use within your scripts.A list ofconstants is included in the PHP manual: http://www.php.net/manual/language.constants.phpPRINT_ENTRY() This prints the results of a query within a table.function print_entry($row,$preserve= ){$numargs = func_num_args();for ($i = 2; $i 0){$errmsg.= $email has already signed this guestbook.\n ;}}// perform a very simple check on the format of the url supplied// by the user (if any)if (!empty($url) && !eregi( ^http://[A-Za-z0-9\%\?\_\:\~\/\.-]+$ ,$url)){$errmsg.= $url doesn t look like a valid URL\n ;}if (empty($errmsg)){$query = insert into guestbook . (name,location,email,url,comments,remote_addr) values . ( $name , $location , $email , $url , $comments , $REMOTE_ADDR );safe_query($query);print Thanks, $name!!\n ;}else{print myimage.gif ).The first argument will take another array containing other attributes.For thetag, that first array might contain alt text, width, and height $myarray =array( alt => My Image , width => 20 , height => 25.3537-4 ch09.f.qc 12/15/00 15:23 Page 230230 Part III: Simple ApplicationsIf appropriate, these two arrays will be merged into one.Then, from this mergedarray, a string is created that has the name = value pairs.If a value is empty, thename will exist without a value.Note that elements passed in the second array will overwrite those in the first,enabling you to overcome default values easily.This occurs because in the array_merge() function, if there are two elements with the same associative key, the lastone will overwrite the previous one.This allows other functions that create HTMLtags to keep a set of defaults in the first argument and values for the specific call inthe second
[ Pobierz całość w formacie PDF ]