Jump to content

file_get_contents suddenly not working?


opalelement

Recommended Posts

I use the following code to run a PHP script:

 

file_get_contents("http://website.com/script.php?session=7fe9cceca74fc5b6605d8487ec2523e6&mode=activate");

 

It worked this morning but suddenly is telling me:

 

Warning: file_get_contents() [function.file-get-contents]: Couldn't resolve host name in /home2/cisarel/public_html/test.php on line 38

 

Warning: file_get_contents(http://website.com/script.php?session=7fe9cceca74fc5b6605d8487ec2523e6&mode=activate) [function.file-get-contents]: failed to open stream: operation failed in /home2/cisarel/public_html/test.php on line 38

 

In this example website.com would be my own website (I call it this way so it can execute the page) and the page exists and can be accessed by me, so I don't see what is wrong with it... It worked fine, then there was a few hours downtime on the server, and when it came back up it no longer worked.

 

Does anyone know how to fix it or how to execute the script another way? Also note that the execution must support query strings

 

EDIT: Also note that if I just do file_get_contents('script.php?session=7fe9cceca74fc5b6605d8487ec2523e6&mode=activate') it returns the contents of the actual file without executing, so I don't see why it isn't working with the whole url...

Link to comment
Share on other sites

Well it is on a phpBB forum, I want to grab the index page and see the session it assigns and then take that session id, change the account associated with the id in the database, and then run a page in the ACP using file_get_contents as well... I had the first two running and the third would have run if the account it changed to had valid permissions, but then the downtime occurred before I could fix the account's permissions.

Link to comment
Share on other sites

I found a way to get it working in cURL but only when I access it form a browser, I need to run the script form a cron job... It is run like this:

 

/usr/local/bin/php -f /home2/cisarel/public_html/test.php

 

The code is like this:

 

mysql_connect("localhost", "user", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("database") or die(mysql_error());
echo "Connected to Database<br /><br />";


$ch = curl_init(); 
curl_setopt($ch, CURLOPT_USERAGENT, "BotBrowser");
curl_setopt($ch, CURLOPT_URL, "http://" . $_SERVER['HTTP_HOST']);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 
curl_close($ch);   

$loc =  strripos($output, "sid=");
echo "SID: " . $sid = substr($output, $loc+4, 32);

 

 

Is there something else I have to do to run cURL in a cron job?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.