Heev feem ntau nws yuav tsim nyog hloov cov ntaub ntawv los ntawm cov neeg siv browser mus rau server file nrog tsab ntawv rau kev ua cov ntaub ntawv no. Cia peb saib raws nraim yuav ua li cas npaj hloov qhov hloov ntawm php tsis rau tsab ntawv.
Nws yog qhov tsim nyog
Yooj yim kev paub lus PHP thiab HTML
Cov Lus Qhia
Kauj ruam 1
Txhawm rau thauj cov ntaub ntawv los ntawm cov ntaub ntawv web hauv HTTP (HyperText Transfer Protocol) ob txoj kev yog muab - GET thiab POST. Lawv txawv nyob rau hauv txoj kev lawv kis tau los ntawm cov neeg siv daim ntawv thov (browser) rau lub server daim ntawv thov (siv tau php tsab ntawv). GET txoj kev siv qhov chaw nyob bar rau qhov no. Ntawd yog, cov npe thiab cov txiaj ntsig ntawm cov hloov pauv tau mus rau nws tau ntxiv ncaj qha rau ntawm tsab ntawv chaw nyob (lossis URL - Uniform Resource Locator) los ntawm kev nug cim (?). Piv txwv, qhov URL yuav zoo li no:
Ntawm no, search.php tsab ntawv yog dhau cov kuj sib txawv thiab lub npe hu nrog tus nqi ntawm 30, tus kuj sib txawv thiab newwindow nrog tus nqi ntawm 1, thiab cov kuj tsis paub meej nrog tus nqi ntawm tawm. Tus neeg rau zaub mov, tau txais kev thov zoo li no, los ntawm "?" cais cov ntaub ntawv chaw nyob, thiab faib txhua lwm yam ntxiv ua khub sib txawv ntawm cov npe thiab tus nqi. Cov khub sib tw tau sau nyob rau hauv $ _GET array, los ntawm cov ntawv sau php uas sau rau hauv qhov chaw nyob yuav tuaj yeem tawm ntawm lawv. Hauv nws daim ntawv yooj yim tshaj plaws, daim foos ntawm html code rau xa cov ntaub ntawv no ntawm qhov browser mus rau server siv GET txoj kev zoo yuav zoo li no:
Thiab php yooj yim tshaj plaws rau kev txais cov ntaub ntawv no zoo li no:
<? php
$ num = $ _GET ['num'];
$ newwindow = $ _GET ['newwindow'];
$ nyab xeeb = $ _GET ['nyab xeeb'];
?>
Qhov tseem ceeb tshaj plaws tsis zoo ntawm qhov hloov pauv uas siv GET txoj kev:
- tsawg tus nqi ntawm cov ntaub ntawv, txij li qhov ntev ntawm URL tsis pub tshaj 255 cim;
- tsis yog txhua tus cim html-code tuaj yeem hloov pauv los ntawm hom no;
- cov ntaub ntawv kis tau pom rau tus neeg siv, uas tsis yog ib txwm pom zoo los ntawm kev ruaj ntseg pom;
Kauj ruam 2
Cov kev tsis txaus ntseeg thiab kev txwv no tuaj yeem zam dhau los siv lwm txoj kev - POST. Nws siv thaj chaw tshwj xeeb ntawm cov pob xaib kom hloov cov ntaub ntawv - headers. Hauv txhua qhov kev hwm, qhov sib txawv ntawm cov qauv no muaj tsawg heev - hauv daim ntawv xa saum toj no, tsuas yog lub npe ntawm tus qauv yuav hloov:
Thiab hauv php tsab ntawv, tsuas yog lub npe ntawm cov ntaub ntawv array:
<? php
$ num = $ _POST ['num'];
$ newwindow = $ _POST ['newwindow'];
$ nyab xeeb = $ _POST ['nyab xeeb'];
?>