opalelement Posted March 7, 2009 Share Posted March 7, 2009 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... Quote Link to comment Share on other sites More sharing options...
RussellReal Posted March 7, 2009 Share Posted March 7, 2009 considering the downtime, you should update the session you're using but this is not a good method to do whatever you're doing, its inefficient.. Quote Link to comment Share on other sites More sharing options...
opalelement Posted March 7, 2009 Author Share Posted March 7, 2009 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. Quote Link to comment Share on other sites More sharing options...
opalelement Posted March 7, 2009 Author Share Posted March 7, 2009 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? Quote Link to comment Share on other sites More sharing options...
opalelement Posted March 7, 2009 Author Share Posted March 7, 2009 Got it to work, I changed the cron job to: curl http://website.com/script.php I read in another discussion board that curl requires a full URL, I kept getting the malformed URL error so I did some research:) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.