Yuav Ua Li Cas Kom Dhau Tus Nqi

Cov txheej txheem:

Yuav Ua Li Cas Kom Dhau Tus Nqi
Yuav Ua Li Cas Kom Dhau Tus Nqi

Video: Yuav Ua Li Cas Kom Dhau Tus Nqi

Video: Yuav Ua Li Cas Kom Dhau Tus Nqi
Video: yuav ua ca koj thiaj yuav ploj sau muab suab vang chai hu ywj siab yaj 2024, Kaum ib hlis
Anonim

Qhov ntxim nyiam tshaj plaws rau cov neeg tuaj saib lub vev xaib, thiab vim li ntawd qhov tseem ceeb tshaj plaws rau lawv cov neeg tsim khoom, yog lawv lub peev xwm sib cuam tshuam. Ntawd yog, lub peev xwm rau tus qhua xa qee cov ntaub ntawv (lossis thov rau ntaub ntawv) rau lub server thiab tau txais lus teb los ntawm nws. Lub koom haum ntawm cov txheej txheem no yuav tsum hloov chaw ntawm lub zog los ntawm nplooj ntawv hauv tus neeg siv browser mus rau server scripts. Cov ntsiab lus niaj hnub no yog: los ntawm cov nplooj ntawv piav qhia hom lus - HTML (HyperText Markup Language - "hypertext markup language"), thiab los ntawm cov server-sab scripting lus - PHP (Hypertext Preprocessor - "hypertext preprocessor"). Peb yuav txiav txim siab cov kev xaiv yooj yim tshaj plaws rau kev hloov pauv ntawm HTML nplooj ntawv mus rau PHP scripts.

Xa cov qhob rau php tsab ntawv
Xa cov qhob rau php tsab ntawv

Nws yog qhov tsim nyog

Yooj yim kev paub lus PHP thiab HTML

Cov Lus Qhia

Kauj ruam 1

Thawj ntu ntawm qhov teeb meem (dhau cov hloov pauv los ntawm HTML nplooj ntawv) daws tau los ntawm qhov muab tso rau hauv nplooj ntawv cov cai tsim cov ntsiab lus uas tsim nyog rau cov neeg siv tswv yim thiab hloov ntawm cov ntaub ntawv xav tau hom. Cov no tuaj yeem yog "cov ntawv sau", "textarea", lossis "password" cov ntawv sau, "checkbox" lossis "radio" radio radio, "xaiv" cov npe, " ntawv "cov ntaub ntawv xaiv teb," tawm tswv yim "nyees khawm, lossis" zais " liaj teb. Cov HTML code ntawm txhua lub ntsiab yuav tsum muaj "cim npe" lossis - nws muaj lub npe ntawm cov sib txawv kis dhau. Piv txwv li, HTML rau cov kab ntau txoj kab lus yuav zoo li no:

ntawm no yog lub neej ntawd ntawv nyeem

Thiab tus lej rau lub tshav zais ntsiag to yog li no:

Ib qho ntawm cov qauv foos yuav tsum tau muab tso rau sab hauv daim foos. Lub cim npe qhib zoo li qhov no:

Ntawm no "kev ua" tag qhia txog lub npe ntawm tsab ntawv server uas tus xa xa mus yuav tsum dhau, thiab kab "qauv" qhia meej cov qauv txheej txheem ntawm kev hloov ntaub ntawv. Tsuas muaj ob txoj hauv kev - POST lossis GET. Qhov sib txawv tseem ceeb ntawm lawv yog tias nrog GET txoj kev, cov hloov pauv tau dhau mus nrog nplooj ntawv chaw nyob (URL), thiab nrog POST txoj kev, nyob hauv thaj chaw tshwj xeeb ntawm cov pob ntim hauv network (header).

Daim foos kaw tag nrho yog yooj yim:

Thiab, tau kawg, ib lub pob yuav tsum tau ntxiv rau hauv daim ntawv thiaj li hais tias tus neeg siv tau muab lus txib kom xa cov tsiaj ntawv rau lub server. Raws li qhov tshwm sim, cov HTML code ntawm daim foos nrog cov khoom rau xa cov hloov pauv rau cov ntawv sau rau server yuav zoo li no:

ntawm no yog lub neej ntawd ntawv nyeem

Daim ntawv HTML
Daim ntawv HTML

Kauj ruam 2

Tam sim no cia saib yuav ua li cas nkag mus rau cov lej sib xa xa mus rau nws los ntawm ntawv sau php server. Txhua yam yog yooj yim heev ntawm no - cov tsiaj ntawv xa los ntawm GET txoj kev tso rau hauv $ _GET superglobal array, thiab cov uas raug xa los ntawm POST txujci - rau hauv zoo li $ _POST array. Muaj ib qho ntxiv superglobal array - $ _REQUEST. Txhua yam hloov pauv rau hauv nws, tsis hais txog qhov lawv tau dhau los. Qhov yooj yim php code uas luam tawm cov ntaub ntawv hais txog cov hloov tau txais los ntawm daim foos nrog cov npe hideMe thiab cov hlua yuav zoo li no:

<? php

yog ($ _ PHEEJ)

ncha ('The variable hideMe muaj cov nqi "'. $ _ XEEM ['hideMe']. '"

');

ncha ('Cov hlua sib txawv txav muaj tus nqi "'. $ _ POST ['hlua']);

}

?>

Ntawm no yog "yog tias" kev sib piv tus neeg teb xov tooj tau siv los xyuas seb puas muaj yam hloov pauv tau POST txhua. Yog tias koj muab cov cai ntawm HTML daim ntawv thiab tsab ntawv PHP sau nyob hauv ib daim ntawv PHP, tom qab koj nyem qhov "Xa", peb tau txais cov txiaj ntsig hauv qab no:

PHP tsab ntawv
PHP tsab ntawv

Kauj ruam 3

Peb pom tias peb tau daws qhov teeb meem ntawm xa cov kev txwv ntawm daim HTML thiab tau txais lawv nrog PHP tsab ntawv.

Pom zoo: