2016-04-10 12 views
0

Ich habe das folgende HTML-Formular mit PHP:

<form name="login" action="http://oz-local.com:8080/_admin/login.php?action=process" method="post"> 

<input type="text" name="username" class="form-control" placeholder="Username"/> 

<input type="password" name="password" class="form-control" placeholder="Password"/> 

<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button> 

</form> 

Wenn ich versuche, den Wert von „Aktion“ zu bekommen $_GET['action'] verwendet, ist es leer . Aber wenn ich $_REQUEST['action'] verwende, bekomme ich den Wert "process".

Das Skript, das ich für diesen Einsatz ist:

echo (isset($_REQUEST['action']) ? 'Yes': 'No'); 
echo '<br>R: ' . $_REQUEST['action'] . '<br><br>'; 
echo (isset($_GET['action']) ? 'Yes': 'No'); 
$gA = $_GET['action']; 
echo '<br>gA: ' . $_GET['action']; 
echo '<br><br>'; 
echo (isset($_POST['action']) ? 'Yes': 'No'); 
$pA = $_POST['action']; 
echo '<br>pA: ' . $_POST['action']; 
echo '<br><br>'; 
echo (isset($_COOKIE['action']) ? 'Si': 'No'); 
$cA = $_COOKIE['action']; 
echo '<br>cA: ' . $_COOKIE['action']; 
$method = $_SERVER['REQUEST_METHOD']; 
echo 'M: ' . $method; 

Ist es normal?
Das lässt mich nicht spüren !!

Jede Hilfe meine Zweifel zu klären ist gut

+1

* "aber $ _GET ist es nicht" * - das ist normal, da Sie eine POST-Methode verwenden. –

+0

@ user6184870 Bitte überprüfen Sie meine Antwort. –

Antwort

0

gesehen Wenn HTML-Formulare einreichen, gibt es zwei Methoden ein verwenden: GET und POST. In Ihrem HTML, haben Sie festgelegt, dass das Formular verwendet werden sollte:

method="post" 

Das bedeutet $_GET Arrays PHP wird es nicht enthalten, sondern es ist zugänglich entweder über $_POST['action'] oder $_REQUEST['action'].

$_REQUEST ist eine Kombination von sowohl GET-und POST-Werte.

1

Da Sie POST-Methode verwenden, in form action-Attribut,
<form name="login" action="http://oz-local.com:8080/_admin/login.php?action=process" method="post">

Sie alle Werte $_POST mit bekommen können, brauchen Sie nicht $_GET.
Da $_POST ist sicherer zu verwenden als, $_GET.

0

Werfen Sie einen Blick auf unter

$ _GET Variablen aus dem Abfragezeichenfolgeflag abrufen oder Ihre URL.

$ _POST ruft Variablen aus einer POST-Methode ab, z. B. (allgemein) Formulare.

$ _REQUEST ist eine Zusammenführung von $ _GET und $ _POST. Es ruft sowohl die Variable GET als auch die Methode POST ab.