I am using AJAX to pass a javascript variable to PHP. Everything was working well and dandy, and then I changed the security of how my php functions will execute. Here is my javscript code:
function writetofile(file, wellname, api){
$.ajax({
type: 'post',
url: 'process.php',
data: {
api: api,
wellname: wellname,
fileName: file,
writetoFile: true
},
success: function(data){
output(api + " : " + wellname + " has been added to: " + file);
}
});
}
PHP:
// process.php
if ($_POST['writetoFile'])){ // i need to check here if writetofile is true, which it is
$api = $_POST['api'];
$wellname = $_POST['wellname'];
$fileName = $_POST['fileName'];
$break = "\n";
$str = $api. " : ". $wellname . $break;
$file = fopen($fileName,"a");
fwrite($file, $str);
fclose($file);
}
when I execute the javascript code, it doesn't write to the file, and yes, I have checked to see if the ajax request was accepted. It is, but i tried doing:
PHP
if ($_POST['writetoFile'] === true)){}
but that doesn't seem to be working either. Thank you for your help.
var_dump($_POST)? You're also not doing any error checking. Add error reporting to the top of your file(s) right after your opening<?phptagerror_reporting(E_ALL); ini_set('display_errors', 1);if ($_POST['writetoFile'])){-> check the number of). You have two.