September 26
Uno degli usi più comuni per linguaggi di scripting lato server come PHP è quello di inviare informazioni da e per ricevere informazioni da altre pagine web. PHP è dotato di funzioni ($ _GET e $ _POST) che rendono questo processo semplice per la memorizzazione dei dati automaticamente presentati in moduli Web in built-in array PHP. Una volta che i dati sono memorizzati utilizzando queste funzioni, può essere recuperato e utilizzato in una varietà di modi, per esempio, per alterare interfacce utente, per fornire un feedback, o, più frequentemente, per memorizzare valori di campo in file e database.
1 Aprire un editor di testo, e creare un nuovo file chiamato postVar.php. Aggiungere alcuni tag HTML per il file che compongono una pagina HTML di base.
<Html>
<Head> </ head>
<Body> </ body>
</ Html>
2 Utilizzare i tag HTML per creare un modulo HTML tra il "<body>" e "</ corpo" tag e impostare il metodo del form di "post" e impostare l'azione del modulo a "postVar.php." Chiudere il tag form.
<Html>
<Head> </ head>
<Body>
<Form method = "post" action = "postVar.php">
</ Form>
</ Body>
</ Html>
3 Aggiungere un ingresso HTML campo ( "<input>") tra il "<form>" e "</ form>" tag, e impostare l'attributo "valore" del campo di input per il testo "valore passato". Impostare "nome" del campo di input attribuire al "passed_input."
<Html>
<Head> </ head>
<Body>
<Form action = metodo "postVar.php" = "post">
<Input value = nome "valore passato" = "passed_input">
</ Form>
</ Body>
</ Html>
4 Aggiungere un secondo ingresso HTML ( "<input>") campo al file. Impostare l'attributo del campo "tipo" a "Invia". Questo attributo indica che il campo di input (pulsante) deve inviare il modulo quando si fa clic.
<Html>
<Head> </ head>
<Body>
<Form action = metodo "postVar.php" = "post">
<Input value = nome "valore passato" = "passed_input">
<Input type = "submit">
</ Form>
</ Body>
</ Html>
5 Aggiungere un delimitatore di PHP open ( "<? Php") e una stretta delimitatore PHP ( "?>") Per il file. Posizionare questi delimitatori tra il "<body>" e "</ body>" tag HTML.
<Html>
<Head>
<Form action = metodo "postVar.php" = "post">
<Input value = nome "valore passato" = "passed_input">
<Input type = "submit">
</ Form>
</ Head>
<Body>
<? Php
?>
</ Body>
</ Html>
6 Utilizzare il metodo _POST PHP $ ed un comando echo per recuperare il valore "passed_input" e l'uscita alla pagina Web. Salvare e chiudere postVar.php.
<Html>
<Head>
<Form action = metodo "postVar.php" = "post">
<Input value = nome "valore passato" = "passed_input">
<Input type = "submit">
</ Form>
</ Head>
<Body>
<? Php
echo $ _POST [ 'passed_input'];
?>
</ Body>
</ Html>
7 Aprire postVar.php in un browser Web. Fare clic sul pulsante "Submit Query" per inviare la pagina e recuperare il valore di iscrizione. Verificare che il valore viene scritto nella pagina.
8 Aprire un editor di testo, e creare un nuovo file chiamato "getVar.php." Aggiungere alcuni tag HTML per il file che compongono una pagina HTML di base.
<Html>
<Head> </ head>
<Body> </ body>
</ Html>
9 Aggiungere due delimitatori PHP per il file tra il "<body>" e "</ body>" tag. Qualsiasi testo inserito tra questi due delimitatori viene interpretato come codice PHP.
<Html>
<Head> </ head>
<Body>
<? Php
?>
</ Body>
</ Html>
10 Utilizzare il metodo di PHP "$ _GET" e un PHP comando "echo ()" per recuperare il valore "passed_value" e l'uscita alla pagina Web. Salvare e chiudere getVar.php.
<Html>
<Head> </ head>
<Body>
<? Php
echo $ _GET [ 'passed_value'];
?>
</ Body>
</ Html>
11 Aprire "getVar.php" in un browser Web. Aggiungere l'argomento
"? Passed_value = valore passato" per aprire la pagina e passare l'argomento con il metodo $ _GET. Verificare che il valore viene scritto nella pagina Web. Un esempio è fornito per chiarezza e illustrazione.
getVar.php? passed_value = valore passato