If someone doesn't feel like reading the whole explanation, you can skip to the last 2 paragraphs where I have the actual question
So I have this bunch of websites made with CakePHP. In one of the pages (this is the same for all the websites), I load an XML file and process its contents (using the XML helper). This has been working for quite some time. Now, suddenly, it doesn't work anymore in any of the websites (and the code hasn't changed a bit), it gives an "error opening file".
At the same time, another script of those websites (which has nothing to do with the previous one, it's plain PHP, outside the cakephp "area") has stopped working too. In this case, it's a scripts that creates a connection with a video hosting provider (Fliqz) and retrieves the URL of a video given a video id. Suddently, it throws an error something like "session was not created" (the script creates some sort of session with Fliqz' server to get the URL).
All this sounds very weird, I know. The first thing I've done, after checking that the code is correct, is call 1&1 (the hosting provider) and ask if they have made any change in the server. They said that they changed to PHP5 a few months ago (which I was aware of, and everything was working fine after that change), but that they haven't changed anything else.
My question would be, is there anything I can do to figure out what is causing these problems? For example, I found some post of someone saying that his hosting had restricted some functionality that allowed external connections. Or in another post I saw a suggestion about doing this: echo file_get_contents("http://google.com/") and I got an error, meaning that some setting wasn't right. I even tried to use simplexml_load_file (instead of the XMl helper) in the page where I load the XML file and didn't work, giving another error...
I would like to know, if a PHP setting is causing this, which one could it be, so I can look at it and call again 1&1 to tell them what they need to change (if there's anything to change). Otherwise, how in the world can something just stop working?
Thank you for any advice! It is much appreciated!
EDIT: detailed explanation of errors
1. Error related to the XML not loading using CakePHP's XML helper
This is the code I use (which used to worked perfectly):
$completeurl = '/full/path/to/file/myfile.xml';
App::import('Xml');
$xml =& new XML($completeurl);
$this->list = Set::reverse($xml);
I don't get any error or warning. If I debug $xml, I get this:
Xml Object
(
[__parser] =>
[__file] =>
[__rawData] =>
[__header] =>
[__tags] => Array
(
)
[version] => 1.0
[encoding] => UTF-8
[name] => #document
[namespace] =>
[namespaces] => Array
(
)
[value] =>
[attributes] => Array
(
)
[children] => Array
(
)
[__parent] =>
)
If I debug $this->list I get an empty array. Before this problem, I would get an associative array with all the information of the XML file, perfectly structured. Oh, and the XML file is the same it used to be, and I've revalidated it just in case giving no errors.
2. Error related to XML file not loading using simplexml_load_file()
This is the code I've tried with "regular" php (without using any CakePHP helper):
$file = '/full/path/to/file/myfile.xml';
if(!$xml = simplexml_load_file($file))
exit('Failed to open '.$file);
And this are the errors (warnings):
Warning (2): simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration [APP/plugins/icd_discovery/webroot/videos.php, line 29]
Warning (2): simplexml_load_file(http://discovery.ingles100.com/icd_discovery/xml/videos_unidades.xml) [function.simplexml-load-file]: failed to open stream: no suitable wrapper could be found [APP/plugins/icd_discovery/webroot/videos.php, line 29]
Warning (2): simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://discovery.ingles100.com/icd_discovery/xml/videos_unidades.xml" [APP/plugins/icd_discovery/webroot/videos.php, line 29]
If I put a relative path for the file, I just get the last warning, but still not loading it.
** 3. Error related to script to load URL of hosted videos in Fliqz**
The page that contains this script is totally unrelated to the previous ones (meaning that the code there doesn't affect the code here). We use the following script (provided by Fliqz) to request the URL of our videos hosted there:
include_once '../fliqz/dlMetrics.php';
// initializing new session
$videoID = '123123123';
$applicationID = '456456456';
$uniqueID = null;
// create a new fliqzDownload Object
$metricsObj = new dlMetrics();
// get new session, using Application ID from Account:
$sessionID = $metricsObj->newSession($applicationID,NULL,NULL,NULL,$uniqueID);
// show server time when new session was created:
$start = $metricsObj->getSessionStart();
// Get asset location (note: must use dashes in asset ID example: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
$video_URL = $metricsObj->initLoad($videoID);
By doing this, we would get the URL of the video in the $video_URL variable. Again, this used to work perfectly. Suddenly, it doesn't.
So is it a coincidence that all this things stop working? I think that something has changed somewhere. Not the code, I'm the only one who touches that. The PHP version changed a while ago, and everything was working fine. Something in the server? 1&1 says that they didn't, or at least the person I talked to. If I have to call back, I would like to be able to point a little better where do I think the problem might be coming from, that's why I need you help guys!
Again, thanks for any advice!
Create a file called php.ini with the following content:
allow_url_fopen = ON
and place it in the same folder (or folders) as those scripts.
Related
I hosted a website i worked on on amazon web services, and for some reason some things dont work compared to when I run it locally on localhost.
of those things are the
if (array_key_exists("error", $json))
function and
the file_get_contents function.
Ive commented out the array key exists part and that solved the issue, at least for that part of logging in, until i get to the view documents page where a slim application error displays
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
and the issue for that lies in the viewdocspage.php file, particularly this code:
<?php
$raw = file_get_contents("http://cosoft.us-east-1.elasticbeanstalk.com/cosoft/mywiki/api.php?action=query&list=allpages&format=json");
$pages_response = json_decode($raw, true);
$pages_array = $pages_response["query"]["allpages"];
$page_titles = [];
I looked and read up on many threads that the issue lies with the file_get_contents in which the URL contains special characters, such as spaces (which mine doesnt have) and so needs to be encoded, using urlencode (or rawurlencode..?)
now ive tried encoding the whole url like this:
$raw = file_get_contents(urlencode("http://cosoft.us-east-1.elasticbeanstalk.com/cosoft/mywiki/api.php?action=query&list=allpages&format=json"));
but that resulted in this error:
slim error
Message: file_get_contents(http%3A%2F%2Fcosoft.us-east-1.elasticbeanstalk.com%2Fcosoft%2Fmywiki%2Fapi.php%3Faction%3Dquery%26list%3Dallpages%26format%3Djson): failed to open stream: No such file or directory
I figured that this may happen since I read that not all the URL should be wrapped by this encoding, but heres where Im stuck: which part of the url do i use the encoding on? the only special characters i keep coming accross regarding this error is spaces, but i dont have any spaces, so its something else which i dont know what it is...
Help is appreciated, thanks!
You would just need to url_encode the parameters. Say you had a value $value='My name is earl'
If you wanted to pass this value as a parameter in your url
http://somesite.com/?name=$value there would be spaces in the value that is url_encoded. So if you encode it as 'http://somesite.com/?name='.urlencode($value), when this is encoded the value will turn into My+name+is+earl
Reading resources from a URL may be restricted by the server's configuration.
http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
You should use CURL for this.
Okay - simple details first:
Feed URL: http://feeds.wired.com/wired/index
When I access this directly through simplepie and not CraftCMS, the feed loads without issue. When I access it through the CMS template system it throws an error saying the returned XML is effectively garbage. Looking into this, its because the feed host is returning a page not found.
I have dug through the code to find out why it is a page not found on a valid URL and found that in the file:
/library/simplepie/registry.php
public function &create($type, $parameters = array()) (around line 160)
Now in this function I see that a new reflection class is created and new InstanceArgs are sent the parameters. At this point the Feed URL gets changed from:
http://feeds.wired.com/wired/index
to
http://feeds.wired.com/wired/index?#
Effectively this new URL with the added ?# on the end is causing the feed site to return a page not found. And hence all my errors...
This is beginning to hit the end of my abilities - and I would like to know what is causing the ?# to be added and if there is a way to prevent it? Or any other possible solutions to my problem.
I can't explain why it works outside of Craft and not inside, but it definitely looks like a SimplePie bug to me.
Just created an issue and pull request with the fix for them (https://github.com/simplepie/simplepie/issues/366) and will see about updating it in Craft itself.
Update: looks my fix didn't broke some of their tests, so we won't be putting that into Craft, but they have acknowledged it needs to be fixed.
I'm designing a web application that can be customized based on which retail location the end user is coming from. For example, if a user is coming from a store called Farmer's Market, there may be customized content or extra links available to that user, specific to that particular store. file_exists() is used to determine if there are any customized portions of the page that need to be imported.
Up until now, we've been using a relatively insecure method, in which the item ID# and the store are simply passed in as GET parameters, and the system knows to apply them to each of the links within the page. However, we're switching to a reversible hash method, in which the store and item number are encrypted (to look something like "gd651hd8h41dg0h81"), and the pages simply decode them and assign the store and ID variables.
Since then, however, we've been running into an error that Googling extensively hasn't found me an answer for. There are several similar blocks of code, but they all look something like this:
$buttons_first = "../stores/" . $store . "/buttons_first.php";
if(file_exists($buttons_first))
{
include($buttons_first);
}
(The /stores/ directory is actually in the directory above the working one, hence the ../)
Fairly straightforward. But despite working fine when a regular ID and store is passed in, using the encrypted ID throws this error for each one of those similar statements:
Warning: file_exists() expects parameter 1 to be a valid path, string given in [url removed] on line 11
I've had the script spit back the full URL, and it appears to be assigning $store correctly. I'm running PHP 5.4.11 on 1&1 hosting (because I know they have some abnormalities in the way their servers work), if that helps any.
I got the same error before but I don't know if this solution of mine works on your problem you need to remove the "\0" try replace it:
$cleaned = strval(str_replace("\0", "", $buttons_first));
it worked on my case.
Run a var_dump(strpos($buttons_first,"\0")), this warning could come up when a path has a null byte, for security reasons. If that doesn't work, check the length of the string and make sure it is what you'd expect, just in case there are other invisible bytes.
It may be a problem with the path as it depends where you are running the script from. It's safer to use absolute paths. To get the path to the directory in which the current script is executing, you can use dirname(__FILE__).
Add / before stores/, you are better off using absolute paths.
I know this post was created on 2013 but didn't saw the common solution.
This error occurs after adding multiple to the file submit form
for example you are using files like this on php: $_FILES['file']['tmp_name']
But after the adding multiple option to the form. Your input name became file => file[]
so even if you post just one file, $_FILES['file']['tmp_name'] should be change to $_FILES['file']['tmp_name'][0]
So I have this url http://my-server.com/feeds/feed.pl?op=retrieveIncidents&type=social,government&cbsa=31100 that contains xml data built by another process. Now I was using file_get_contents() with the url hardcoded and it worked perfectly. At this stage of dev I had to start using the config files and the cbsa codes from the current user logged in the application.
Now this /feeds/feed.pl?op=retrieveIncidents&type=social,government&cbsa= comes from the config.
This 31100 comes from the user object.
This http://my-server.com comes from a helper fn().
$server = $this->serverUrl();
$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini', APPLICATION_ENV);
$curOperator = Default_Model_Operator::getActiveOperator();
$feedUrl = $server.$config->ims->idfFeed.$curOperator->regions;
If I print/echo $feedUrllooks like http://my-server.com/feeds/feed.pl?op=retrieveIncidents&type=social,government&cbsa=31100
But when I do $feed = file_get_contents($feedUrl) I get
Warning: file_get_contents(http://vdot.orion.meridian-enviro.com/feeds/feed.pl?op=retrieveIncidents&type=social,government&cbsa=31100) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/Agena/lvegerano/svn/webapps/ims/trunk/phpfiles/application/views/scripts/chp/list-for-dashboard.phtml on line 9
Make note of the &. I have tried htmlentities_decode(),urlencode()and other and cant get this to works. What can I do so file_get_contents() translate &to&?
Any help on how to fix this would be greatly appreciated.
I guess I forgot to answer this. The problem was our varnish setup. It is setup to lookup urls and if recognized inserts the host name. Because I had just started working here I was not aware of this feature. Therefore the error I thought it was it wasn't since the varnish was masking the url.
I am combining two existing scripts to built something new and safe time by using existing code:
php_simple_html_dom to parse some html
the wp-db.php class from wordpress to access the database
These two scripts don't play nicely along. I used xdebug to find out that the main problem was caused in this piece of code in php_simple_html_dom:
if (($error=error_get_last())>null) {
$this->clear();
return false;
}
Because the wordpress template I use fires some E_NOTICE level errors this results in my php_simple_html_dom getting cleared.
The weird thing is, I do not include any template code as I include and instantiate wp-db.php myself like this:
require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
$wpdb = new wpdb(DB_USER,DB_PASSWORD,DB_NAME,DB_HOST);
Even when I step through the code completely with xdebug it never hits anything else from wordpress then wp-config.php or wp-db.php.
Edit:
As indicated by horatio, this actually does get called from the
include of wp-settings.php in the end of wp-config.php. I now
understand why my debugger never hit it: netbeans had failed to
download wp-settings.php so it could not debug it.
Nevertheless this is the error returned by error_get_last():
Array
(
[type] => 8
[message] => Undefined index: id
[file] => (real-path-deleted)/wp-content/themes/supermassive/lib/inc/options.php
[line] => 10
)
I think I could solve this problem using one of two different strategies:
1. Stop the unneccessary wordpress code that is causing the errors from running.
Reset the error returned by error_get_last() before php_simple_html_dom is run.
Which of these would be the best and how would I go about to achieve it?