php - storing form data from landing page to csv file for later use in mail client -
i have been looking afternoon, , no results have found worked me, maybe not integrating code correctly. have script landing page wifi, , php auth page, forwarding net. want use php somewhere in middle store form data landing page csv file on server use later in email client. each time user enters new set of details, csv updated new row.
the form:
<?php session_start(); $_session['id'] = $_get['id']; //user's mac address $_session['ap'] = $_get['ap']; //ap mac $_session['ssid'] = $_get['ssid']; //ssid user on (post 2.3.2) $_session['time'] = $_get['t']; //time user attempted request of portal $_session['refurl'] = $_get['url']; //url user attempted reach $_session['loggingin'] = "unique key"; //key use check if user used form or not // -- prevents them going /authorized.php on 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>
the auth page:
<?php session_start(); function sendauthorization($id, $minutes) { $unifiserver = "https://unifi-ip:8443"; $unifiuser = "unifi username"; $unifipass = "unifi password"; // start curl login $ch = curl_init(); // posting data curl_setopt($ch, curlopt_post, true); // set 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 curl_setopt($ch, curlopt_sslversion, 3); // login 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 authorize , time allowed $data = json_encode(array( 'cmd'=>'authorize-guest', 'mac'=>$id, 'minutes'=>$minutes)); // send command api curl_setopt($ch, curlopt_url, $unifiserver.'/api/cmd/stamgr'); curl_setopt($ch, curlopt_postfields, 'json='.$data); curl_exec ($ch); // logout of unifi controller curl_setopt($ch, curlopt_url, $unifiserver.'/logout'); curl_exec ($ch); curl_close ($ch); unset($ch); } if ($_session['loggingin'] == "unique key") // check see if form has been posted { ob_start(); sendauthorization($_session['id'], (12*60)); //authorizing user 12 hours ob_end_clean(); unset($_session['loggingin']); } ?> <p>connecting network...</p> <script> //allow time authorization go through settimeout("location.href='http://www.google.com'",6000); </script>
this exact solution: https://daveismyname.blog/form-to-csv-with-php downloads csv instead of storing web page, , need append row of data every time else fills out form.
thanks in advance
sorted it, else trying this, here answer. put code in @ top of processing php file, , edit own needs:
<?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); } }
Comments
Post a Comment