Develop the chrome plug-in to capture some web page information. how can I write the captured information into a file? Currently, jquery ajax is used to send data to the server, and php is used to write data to Excel. However, the server cannot receive ajax information at all. please analyze the cause.
Ps: You have set up the WampServer environment and tested localHost.
Post the PHP code on the server: (demo found online)
Header ("content-type: application/json; charset: UTF-8 ");
Date_default_timezone_set ("Asia/Shanghai ");
$ FirstAccess = null;
$ RawData = file_get_contents ("php: // input ");
$ Parameters = json_decode ($ rawData );
If ($ parameters ){
If (isset ($ parameters-> url )){
$ CurrMd5 = md5 ($ parameters-> url );
$ Handle = fopen ("history.txt", "r + ");
If ($ handle ){
While ($ line = fgets ($ handle, 4096 ))! = False ){
If (0 === strpos ($ line, $ currMd5 )){
$ FirstAccess = trim (substr ($ line, 33 ));
Break;
}
}
If (! $ FirstAccess ){
$ FirstAccess = date ("Y-m-d H: I ");
Fwrite ($ handle, $ currMd5. "". $ firstAccess. "\ r \ n ");
}
Fclose ($ handle );
}
Else {
Exit (json_encode (array ('error' => 'Server unexpected error .')));
}
Exit (json_encode (array ('firstaccess' => $ firstAccess )));
}
}
Exit (json_encode (array ('error' => 'The request is incorrect .')));
?>
Reply to discussion (solution)
Have you ever encountered the same problem? Ask an experienced big brother for help? (New to PHP)