Magento Forum

   
Including an external php file in a phtml template
 
talmor
Member
 
Avatar
Total Posts:  43
Joined:  2008-11-14
Israel
 

Hi,

I’m trying to include an external php file in one of my phtml files by using the following command:

include(’http://www.mylaptop.co.il/test.php’);

I’ve also tried using “require”.  I tried playing with the file attributes and also made sure the file is accessible through the browser.

In all cases I get the message:
“Fatal error: main() [function.require]: Failed opening required ‘http://www.mylaptop.co.il/test.php’ (include_path=’/home/mylaptop/public_html/app/code/local:/home/mylaptop/public_html/app/code/community:/home/mylaptop/public_html/app/code/core:/home/mylaptop/public_html/lib:.:/usr/lib/php’) in /home/mylaptop/public_html/app/design/frontend/Tal/Tal/template/blogindex.phtml on line 17”

It seems like magento cannot find the file, any clues?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

It’s looks like PHP issue, not Magento smile
PHP looking for file you are trying to include from (include_path=’/home/mylaptop/public_html/app/code/local:/home/mylaptop/public_html/app/code/community:/home/mylaptop/public_html/app/code/core:/home/mylaptop/public_html/lib:.:/usr/lib/php’) but not from http://…

Try to look for allow_url_fopen and just PHP manual.

 
Magento Community Magento Community
Magento Community
Magento Community
 
talmor
Member
 
Avatar
Total Posts:  43
Joined:  2008-11-14
Israel
 

Thanks, It seems that the allow_url_fopen is a server option ?  or is it something in Magento?

It’s weird since I did include the http in my path .

My server allows php fully since I also use other systems like wordpress and phpbb , any idea where to look for the problem ?

I just used the simple include command.

 
Magento Community Magento Community
Magento Community
Magento Community
 
talmor
Member
 
Avatar
Total Posts:  43
Joined:  2008-11-14
Israel
 

If I put the php file in the app/code/local folder of Magento, the include works.

So I am assuming this is a magento issue that is blocking external php files.

Any idea how to overcome this ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

Still not sure if it’s Magento problem.

allow_url_fopen is an option at PHP configuration file that lets you open external files
take a look at:

http://www.php.net/manual/en/features.remote-files.php

and just create test2.php close to Magento dir file and try to include(’http://www.mylaptop.co.il/test.php’);

 
Magento Community Magento Community
Magento Community
Magento Community
 
talmor
Member
 
Avatar
Total Posts:  43
Joined:  2008-11-14
Israel
 

I’ve read everything you sent me , thanks.  it seems that allow_url_fopen is enabled.

I am able to include(’test.php’);
but not able to include(’http://www.mylaptop.co.il/test.php’);

The same file.  Looks like the http is a problem .

 
Magento Community Magento Community
Magento Community
Magento Community
 
PaulE
Member
 
Avatar
Total Posts:  43
Joined:  2008-12-09
 
talmor - 10 March 2009 01:36 PM

I’ve read everything you sent me , thanks.  it seems that allow_url_fopen is enabled.

I am able to include(’test.php’);
but not able to include(’http://www.mylaptop.co.il/test.php’);

The same file.  Looks like the http is a problem .

Not a HTTP/Magento/PHP problem. Just a security thingy. PHP doesn’t allow you to include/require external PHP files. Else you could easily connect to somebodies database (as soon as somebody makes an connection in their config.php etc.). For this you should use fopen, file_get_contents or curl.

 
Magento Community Magento Community
Magento Community
Magento Community
 
patu7
Member
 
Total Posts:  64
Joined:  2011-09-12
 

HI,

Can anybody plz tell me how to include external php file in Magento?
Plz provide sample code for the same...that would be really helpful....

I am using Magento\’s event-observer model so I want to include say Function1.php file in Observer.php?
Below are my file locations-:
/xampp/htdocs/localhost/magento/app/code/local/Sample/Event/Model/Observer.php Observer.php

<?php 
 
 
include(\"connection/Final/Function1.php\"); 
 
 
class 
Sample_Event_Model_Observer  

    
public function Mytestmethod($observer)  
   
{
}
}

/xampp/htdocs/localhost/magento/app/connection/Final/Function1.php

Function1.php
{}

 
Magento Community Magento Community
Magento Community
Magento Community
 
satish
Enthusiast
 
Total Posts:  812
Joined:  2008-03-24
34,mantri Sadan,Shivaji Nagar,Nagpur,MS,India 4400
 

If you want some specific PHP code to be executed.

I suggest use Helper code of module and place that PHP cade in a function.

Now in controller function call or elsewhere in code flow you can call this helper function.

Satish

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top