Use File_Get_Contents to grab site, then remove header and display site?

1.2k views Asked by At

In the below code, I've tried using the file get contents command to get the website content and output it, and but its showing a blank page when I run it.

<html>
<?php 

$site = "http://facebook.com";
echo $file_get_contents[$site];

?>

<html>

After this, I wanted to use

header('X-Frame-Options: GOFORIT');

or something similar to edit the header but the first code to display the webpage wasn't working so what would be the mistake?

3

There are 3 answers

0
A l w a y s S u n n y On BEST ANSWER

This may work but i guess it requires some sort of SSL or something else, see more about file_get_contents because

file_get_contents() — Reads entire file into a string

As it a function not an array as you used in your code.

<?php 
$site = "http://facebook.com";
echo file_get_contents($site); // remove $ from file_get_contents() function
?>
0
richardgirges On

The correct usage is file_get_contents(). It's a function - you're calling it as a hash variable. Just a syntax issue. See correct usage below:

<html>
<?php 

$site = "http://facebook.com";
echo file_get_contents($site);

?>
<html>

Read the file_get_contents documentation for more info: http://php.net/manual/en/function.file-get-contents.php

0
Asuquo12 On

Two points to change. 1. Remove the $ in front of file_get_content() because its a function. 2. Since it is a function the parameters is feed using () not [] which means an array and next time please try and post the error message to, it would help quickly see the problem with the code;

<html>
<?php 

$site = "http://facebook.com";
echo file_get_contents($site);

?>

<html>
  1. Adding header('X-Frame-Options: GOFORIT'); would allow you load the page into an iframe as you desired.