2017-07-28 1 views
0

Ich habe den ganzen Nachmittag gesucht, und keine Ergebnisse, die ich gefunden habe für mich gearbeitet, vielleicht bin ich nicht den Code richtig zu integrieren. Ich habe ein Skript für eine Landing-Page für WLAN, und die PHP für die Auth-Seite, Weiterleitung an das Netz. Ich möchte PHP irgendwo in der Mitte verwenden, um die Formulardaten von der Zielseite in eine CSV-Datei auf dem Server zu speichern, um sie später in einem E-Mail-Client zu verwenden. Jedes Mal, wenn ein Benutzer eine neue Gruppe von Details eingibt, wird der CSV mit einer neuen Zeile aktualisiert.Speichern von Formulardaten aus der Zielseite zu CSV-Datei zur späteren Verwendung in Mail-Client

Die Form:

<?php 
    session_start(); 
$_SESSION['id'] = $_GET['id'];   //user's mac address 
$_SESSION['ap'] = $_GET['ap'];   //AP mac 
$_SESSION['ssid'] = $_GET['ssid'];  //ssid the user is on (POST 
2.3.2) 
$_SESSION['time'] = $_GET['t'];   //time the user attempted a 
request of the portal 
$_SESSION['refURL'] = $_GET['url'];  //url the user attempted to 
reach 
$_SESSION['loggingin'] = "unique key"; //key to use to check if the 
user used this form or not 
       // -- prevents them from simply going to 
/authorized.php on their own 

?> 
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Portal Page Example</title> 
</head> 

<body> 
<form name="login" action="authorized.php" method="post"> 
<input id="Name" type="text" name="name" value="Name" /> 
<input id="Email" type="text" name="email" value="Email" /> 
<input id="submit" type="submit" name="submit" value="Connect" /> 
</form> 
</body> 
</html> 

Die Auth Seite:

<?php 

session_start(); 

function sendAuthorization($id, $minutes) 
{ 
$unifiServer = "https://unifi-IP:8443"; 
$unifiUser = "UniFi Username"; 
$unifiPass = "UniFi Password"; 

// Start Curl for login 
$ch = curl_init(); 
// We are posting data 
curl_setopt($ch, CURLOPT_POST, TRUE); 
// Set up cookies 
$cookie_file = "/tmp/unifi_cookie"; 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
// Allow Self Signed Certs 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
// Force SSL3 only 
curl_setopt($ch, CURLOPT_SSLVERSION, 3); 
// Login to the UniFi controller 
curl_setopt($ch, CURLOPT_URL, "$unifiServer/login"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 
    "login=login&username=$unifiUser&password=$unifiPass"); 
// send login command 
curl_exec ($ch); 

// Send user to authorize and the time allowed 
$data = json_encode(array(
    'cmd'=>'authorize-guest', 
    'mac'=>$id, 
    'minutes'=>$minutes)); 

// Send the command to the API 
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/api/cmd/stamgr'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'json='.$data); 
curl_exec ($ch); 

// Logout of the UniFi Controller 
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/logout'); 
curl_exec ($ch); 
curl_close ($ch); 
unset($ch); 
} 

if ($_SESSION['loggingin'] == "unique key") // Check to see if the form 
has been posted to 
{ 
ob_start(); 
    sendAuthorization($_SESSION['id'], (12*60)); //authorizing user for 
12 hours 
ob_end_clean(); 
unset($_SESSION['loggingin']); 
} 

?> 
<p>Connecting to the network...</p> 
<script> 
//allow time for the authorization to go through 
setTimeout("location.href='http://www.Google.com'",6000); 
</script> 

Dies ist fast die exakte Lösung: https://daveismyname.blog/form-to-csv-with-php aber es lädt die csv, anstatt es mit der Webseite zu speichern, und ich brauche Er fügt eine Datenzeile jedes Mal hinzu, wenn jemand anderes das Formular ausfüllt.

Vielen Dank im Voraus

Antwort

0

es sortiert, nur für jemand anderes versucht, dies zu tun, hier ist die Antwort. Setzen Sie diesen Code in an der Spitze Ihrer Verarbeitung PHP-Datei und bearbeiten Sie Ihre eigenen Bedürfnisse:

<?php 
$Name = Trim(stripslashes($_POST['Name'])); 
$Email = Trim(stripslashes($_POST['Email'])); 

if (!empty($Name) || !empty($Email)) { 
$csvData = $Name . "," . $Email; 
$fp = fopen("formdata.csv","a"); 
if (fp) 
{ 
fwrite($fp,$csvData."\n"); 
fclose($fp); 
} 

} 
Verwandte Themen