V
V
Vladislav2017-04-03 07:56:50
Laravel
Vladislav, 2017-04-03 07:56:50

How to include external php file in laravel?

Good day!
How to include external php file in laravel?
Or how can I convert

<?php
    header('Content-Type: application/json');
  $url = "";
  if( isset($_GET['url']))
  {
    $url = $_GET['url'];
  }
  if( isset($_POST['url']))
  {
    $url = $_POST['url'];
  }
  //print_r($_GET);
  //echo"$url";
  $address = str_replace("@", "&",str_replace("!", "?", str_replace("~", "=", $url)));
  //echo $address;
  $ch = curl_init($address); //начинаем сеанс работы с cURL; указываем, что будем работать со скриптом по указанному адресу 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_POST, 0); //посылаем методом GET 
  $json = curl_exec($ch); //выводим результат в JSON
  $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch); // завершаем сеанс 
  //echo "$httpcode";
  //echo "$json";
    header("HTTP/1.1 $httpcode OK");
  $obj = json_decode($json);
  echo json_encode($obj);
?>

In laravel

Answer the question

In order to leave comments, you need to log in

3 answer(s)
U
UksusoFF, 2017-04-03
@UksusoFF

In general, libs and so on can be included in the composer.json files section of autoload.
But what you have is better to transfer to the controller with native methods.

M
myxasa, 2017-04-03
@myxasa

google models and MVC framework

B
Barmunk, 2017-04-03
@Barmunk

get and post https://laravel.ru/docs/v5/requests
validation https://laravel.ru/docs/v5/validation
print_r() change to dd()
curl to guzzle docs.guzzlephp.org/en/latest
but it's better to repeat this laravel.su/docs/5.2/quickstart first and then return to your script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question