0

I want to display a PHP file for my other website page, but I am facing a problem.

Can you please tell me how I can put 2 times this code in my page?

I'll put one time code in my site then it's working fine but if put it there a 2nd time then website is not responding

<?php
$myurl = "http://domain.com/diplay.php";

function get_http_response_code($myurl) {
    $headers = get_headers($myurl);
    return substr($headers[0], 9, 3);
}
if(get_http_response_code($myurl) != "200"){
    echo "error";
}else{
   echo file_get_contents($myurl);
}
?>

<?php
$myurl1 = "http://domain1.com/diplay.php";

function get_http_response_code($myurl1) {
    $headers = get_headers($myurl1);
    return substr($headers[0], 9, 3);
}
if(get_http_response_code($myurl1) != "200"){
    echo "error";
}else{
   echo file_get_contents($myurl1);
}
?>
chrki
  • 6,143
  • 6
  • 35
  • 55
  • 1
    what happens when you open the above page? Does it timeout? Is there any error code displayed? – Kiran Shakya Dec 25 '16 at 06:39
  • 1
    Possible duplicate of ["Fatal error: Cannot redeclare "](http://stackoverflow.com/questions/1953857/fatal-error-cannot-redeclare-function) – Sean Dec 25 '16 at 07:02

1 Answers1

0

You are probably getting a fatal error, ie.

Fatal error: Cannot redeclare get_http_response_code()

as you are redeclaring function get_http_response_code() when you do the code a second time. Since your function does not change, just remove the function declaration in the 2nd code block -

...
<?php
$myurl1 = "http://domain1.com/diplay.php";

if(get_http_response_code($myurl1) != "200"){
    echo "error";
}else{
   echo file_get_contents($myurl1);
}
?>
Sean
  • 12,443
  • 3
  • 29
  • 47