M
M
midarovrk2016-08-04 22:24:47
PHP
midarovrk, 2016-08-04 22:24:47

Why does the script work on one php server and not on the other?

Hi all.
I've been scratching my head for 4 hours now and can't find the cause.
I have a PHP script for pulling information from the API

<?php 
if(preg_match('/^[0-9]*$/',$_GET['id'])!=true) exit('Ошибка');
header("Access-Control-Allow-Origin: ссылка");

  $data=json_decode(file_get_contents('ссылка='.$_GET['id']),true);
  //print_r($data);
  $name=$data['nameRU'];
    $nameEN=$data['nameEN'];
  $growth=$data['growth'];
  $birthday=$data['birthday'];
    $age=$data['age'];
  $birthplace=$data['birthplace'];
  $profession=$data['profession'];
  $photo=$data['posterURL'];
  $photo='ссылка_'.$data['peopleID'].'.jpg';

  $count=0;
  for($i=0;$i<count($data['filmography']);$i++) {
    if(count($data['filmography'][$i])>1) {
      for($j=0;$j<count($data['filmography'][$i]);$j++) $count++;
    }
    else $count++;
  }

  $array['name']=(isset($name) AND $name!='') ? $name : '-';
    $array['nameEN']=(isset($nameEN) AND $nameEN!='') ? $nameEN : '-';
  $array['growth']=(isset($growth) AND $growth!='') ? $growth : '-';
  $array['birthday']=(isset($birthday) AND $birthday!='') ? $birthday : '-';
  $array['age']=(isset($age) AND $age!='') ? $age : '-';
    $array['birthplace']=(isset($birthplace) AND $birthplace!='') ? $birthplace : '-';
  $array['profession']=(isset($profession) AND $profession!='') ? $profession : '-';
  $array['photo']=(isset($photo) AND $photo!='') ? $photo : '-';
  $array['films']=(isset($count) AND $count !='') ? $count : '-';

    if($array['name']=='NaN')
    echo json_encode(Array('error'=>'Данные не найдены :('));
  else {
    $data=json_encode($array);
 
    echo $data;
}
?>

So, on the trial hosting server timeweb.ru (I don’t know what kind of control panel) everything works as it should.
And on my VPS server (ISPmanager 4.4 Lite panel) from thehost.ua does not always work.
And it does not work in those cases when the API does not have, for example, ['birthday'] or ['age'], etc.
So he puts dashes on the first serv as it is written in the script.
And the second server (ISPmanager 4.4 Lite panel) does not output anything at all, i.e. doesn't work at all. Why might this happen? I think because of the control panel chtoli?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Dyshkant, 2016-08-04
@midarovrk

Probably different servers have different error_reporting settings . Fortunately, it can be set not only through the server configuration, but also during script execution .
In general, the above code fragment looks like a terrible crutch. I would advise you to use the array_key_exists function to check if the corresponding key exists in the array $data. Something like:
Thus, you are guaranteed to access an array element only if such a key exists in it.

D
Dmitry Entelis, 2016-08-04
@DmitriyEntelis

See php error log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question