извне веб-сайта отправьте GET-данные в файл, которого нет в документе root - PullRequest
0 голосов
/ 23 апреля 2020

myWebsite \

  • php_files \
    • form_file. php //*processes form data. This works
    • обратный вызов. php //fails to receive GET request data from require_callback.php
  • public_html \ //DocumentRoot
    • require_form_file. php //url is the value of the ‘action’ attribute in a html form.
    • require_callback. php //receives GET request from outside the website
    • index. html

Это упрощенная структура моего сайта.
form_file. php обрабатывает данные формы моего сайта. Он получает данные этой формы с помощью оператора require в require_form_file. php в документе root, public_ html. Это требование require является обязательным ____ DIR___. '/ .. / form_file. php'; Это работает.

require_callback. php требует callback . php с аналогичным требованием. Но require_callback. php отличается тем, что получает запрос GET от источника за пределами сайта. К сожалению, обратный вызов. php никогда не получает доступ к данным в запросе GET, отправленном на require_callback. php.

  1. Это потому, что запрос GET приходит извне сайт и эффективно ищет доступ к файлу, отсутствующему в документе root?
  2. Существует ли безопасный способ, которым файл, такой как обратный вызов ли получать данные извне сайта?

Я обновил вопрос с кодом ниже.

Это запрос скручивания к другому сайту, на который другой сайт отвечает запросом GET.

$start_process_data = array("callback" => "https://mytestsite.ie/require_callback.php", 
"input" => "download", "file" => "https://mytestsite.ie/$img_url","tag" => $tag_obj, 
"outputformat" => "jpg", "CURLOPT_RETURNTRANSFER" => "true");

$process_url = "https:".$url_from_create;//prepend https to construct  valid endpoint url

curl_setopt($ch_start_process, CURLOPT_URL, $process_url); 
curl_setopt($ch_start_process, CURLOPT_POSTFIELDS, 
   http_build_query ($start_process_data));//post array of arguments option
curl_setopt($ch_start_process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_start_process, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$start_response=curl_exec($ch_start_process);//assign return value of curl_exec()

require_callback. php в public_ html

<?php
header('Access-Control-Allow-Origin: *');
$url = $GET;
require_once __DIR__ .'/../php_files/callback.php';

//when the above require statement is present execution of this script fails here or before
//I know this because a mail(), at this point, to my email address deosn't fire.
//If I comment out the require statement the mail() fires

//what should happen next but doesn't:
//initiate a second curl request to $url to retrieve data from otherSite

data_from_require_callback($curl_response);// send the curl response 
//to callback_php to be processed outside of the document root
?>

обратный вызов. php в php_files за пределами каталога root public_ html

<?php
function data_from_require_callback($data)
{
//insert $data in database
}
?>  
...