opening URL as file/overwriting php.ini on the server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

opening URL as file/overwriting php.ini on the server

Post by konstantin »

i'm trying to use simplexml_open_file() function to process an Amazon response, BUT:

altough the file works fine on my machine, when i try to open the page i get:

Code: Select all

Fatal error: Call to undefined function: simplexml_load_file() in /homepages/...
obviosly that's the kind of error when the server is not running PHP 5... well, the thing is that it is for a fact running PHP 5, and i renamed the extension of my file from .php to .php5. i can load the file, but i get:

Code: Select all

Warning: simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration in  /homepages/...
my understanding is that i need the

Code: Select all

allow_url_fopen = On
in the php.ini on the server. i read somewhere that you can overwrite the ini like this:

Code: Select all

ini_set("allow_url_fopen", "On");
but it doesn't work... any suggestions? thanks.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Set the entry in your php.ini or httpd.conf

See here: http://us2.php.net/manual/en/ini.php#ini.list

only some options can be overridden by ini_set, if .htaccess is allowed you can do it that way too
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

what does PHP_INI_SYSTEM mean when it comes to overwriting the setting on the SERVER ini file from your loaded php file?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

its right there on that link, plus i told you in my previous post. .. please try to show some initiative
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP_INI_SYSTEM: Entry can be set in php.ini or httpd.conf

Your host likely turned it off due to security problems. Try looking at using cURL or fsockopen() to fetch the file then use the string parsing of the functionality you want to handle the data returned.
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

sorry, i didn't scroll all the way down...

now my understanding is that i can't overwrite the setting through the script in my file, as the php.ini is on the hosting company's server... :(
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

is .htaccess disabled? is curl available? are sockets disabled? you could open a socket and do a http request manually, you could use curl to grab the page, you could ask your host to overide the setting the setting in httpd.conf for just you (and tell them theyll loose your business if you don't).

I hear VPSs are good ;-)
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

everything worked great on my laptop until it decided to crash 2 days ago... i'm working on a school project and i'm supposed to show my progress. since i no longer have my laptop to present, i'm forced to make the project run on a server... a friend of mine is running a server, together with some other people, and was kind enough to assist me with providing me some space and doing some settings for me. i'm not paying anything for this so i can't force him to change ini settings. i guess he'll talk to the other people and let me know...

since i'm a total PHP n00b, i just don't see how i can use cURL or fsockopen() to fetch the file at this point. but thanks for your help anyway.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

konstantin wrote:i just don't see how i can use cURL or fsockopen() to fetch the file at this point.
there's a good example on the man page: http://us2.php.net/fsockopen
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

ok, i got the fsockopen() to work and now i have a variable $result, that's a string starting with the '<?xml...' tag.

as i mentioned in my initial post, i used simplexml_load_file() before to take care of the fetching (i.e. do all the work). now that i have that string variable, how do i fetch it so that i can access the attributes?

thanks,
k
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

OMG, wish every problem had such an easy solution.

Thanks much!
Post Reply