Home > Software engineering >  Is there a reason why apache stops being able to read the localhost the moment this particular file
Is there a reason why apache stops being able to read the localhost the moment this particular file

Time:06-29

Running XAMPP which loads and runs fine, and can see every other localhost/folder , however as soon as I upload this

<?php 
$data = array (
  'number' => 1,
  'current_date' => date('Y-m-d'),
  'name' => 'RS'
);
$ch = curl_init();

$options = array(
  CURLOPT_URL => 'http://localhost/fake_api/',
  CURLOPT_POST => 1,
  CURLOPT_POSTFIELDS => $data, 
  CURLOPT_RETURNTRANSFER => 1,
);

curl_setopt_array($ch, $options);

$result = curl_exec($ch);

curl_close($ch);

print_r($result);

?>

php file, it returns 'object not found' to the browser. I am trying to teach myself the POST method using cURL scripting, as eventually on a live server I will need to POST to a live API, but I am seriously stumbling at this hurdle.

I do have a separate /directory with a fake_api php document which is seen by apache and can be seen in the browser returning array().

EDIT Apache stops seeing the entire /directory which that particular php file is in, not just the /directory/file.php

CodePudding user response:

I have found the answer after more reseaerch, I didnt specify an array with [] within the curl_opt_array() or the initial data variable

$data = array ();

should have been

$data = array ([]);
  • Related