Trying to include file not working

I have some online player stats from my server and would like to display them on the website

I have tried using php include but nothing is displayed

can anyone help with this ? thanks

the code i tried was this, btw the game stats file is on another server not on lovebug.epizy.com

test

I found a solution, thanks

I understand you found a solution but for those that may see the thread to find there own solution:

<?php
include 'http://mygameserverurl/playerstats.html';
?>

or as BayoDino commented

$fromurl = 'http://mygameserverurl/playerstats.html';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $fromurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$get_page = curl_exec($curl);
curl_close($curl);
1 Like

You cannot include from http url. It must be path.

Hence the file is hosted on another server. You should include it by using Curl.

2 Likes

ah thanks guys

I used echo file_get_contents( “http://mygameserverurl/playerstats.html”);

is using curl better ?

Unsure. With curl youcan also send http requests. Like Ajax in Javascript.

This is MUCH safer. This way, if someone hacks the game server and gets access to this file, they can’t add PHP code and execute those on your hosting account. This will just print the PHP code in the browser. Using include will cause the PHP code to be executed on your website.

3 Likes

thanks Admin thats really great news

im just learning stuff and a bit unsure of things, finally I did something right lol

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.