Help - Search - Members - Calendar
Full Version: How do I include a php file?
User Forums > Ultimate Locator v1 - v2.5 Support > General Support
Tim Mousel
Hi,

I'm working to incorporate this script - http://review-script.com.

In results_details_format.htm I'm trying to include a php file (
CODE
<? @include 'http://www.babyproofingdirectory.com/review/review_insert.php?item_id=117'; ?>
) however it is being parsed out. Is there any way I can get that file to show up in my details page?

Thanks in advance,

Tim
Brian
You are trying to put PHP code into a HTML template.

You should try putting the code in the results_list.php or results_details.php
Tim Mousel
Since it is a htm page I was trying to do it as a ssi. That didn't work...

Please look at: http://www.babyproofingdirectory.com/locat...ails.php?id=117

If I want my included file to be right after the large image, do you know where I would insert my code?

Thanks,

Tim
Brian
There is one problem with this, when you include a php page inside another php page, a second header is sent to the browser. However, this is a way around this.



You would have to add a "placeholder" to the template. Like this {myinclude} It can be any name you wish. You can place it anywhere you wish on the results_details.htm template.

Then you would have to add php code to your results_details.php file that will grab the contents of the include file. Then add some code that would replace the placeholder in your template with this contents.

Here is the code example. Just add it near the bottom of the results_details.php page just above the bottom line where it says: echo $str;

ob_start();
include("../path/to/review_insert.php?item_id=117");
$my_file = ob_get_contents();
ob_end_clean();
$str=str_replace("{myinclude}",$my_file,$str);

Give this a try and see if it will work for you. It worked just fine in my testing on our server.

Hope this helps!
Tim Mousel
Hello,

That worked perfectly!!!

Thank you so much for the excellent customer service!

Tim Mousel
http://www.Review-Script.com
Tim Mousel
After 2 1/2 years, I'm back with the same question!

Your latest version has changed since the last time I worked with it and I'm having trouble.

At the very end of result_details.tpl I inserted this code:

CODE
{php}
include('/home/public_html/review/review_insert.php');
{/php}


When I have that code there, results_details.php shows my include but a view of the browser source shows that the first tag on the page is the body onLoad tag instead of the expected "<!DOCTYPE HTML............".

Any idea how I can use my include without it messing up the html output? My include is basically showing some data laid out in a few tables. I have no <html> or <body> tags in my include file.

Thanks in advance,

Tim
Brian
Tim,

If you are viewing the source code and there is no open HTML or BODY tag, then it may be missing from the index.tpl file. Have a look in it and see if it is at the top. By default, we use this and it should be getting used over and over an all pages of output.

Actually, everything in the header section and the footer section of the index.tpl template gets reused.

Have a look and let me know your findings. Also, please provide a link so I can take a peek too.
Tim Mousel
Hi,

The open HTML tag is there when I don't use the include. When I do use it, the open HTML tag stops appearing. I don't understand why that would happen when the include is a few tables. The server is currently down with issues but when it is back, I'll post the link.

Thanks,

Tim
Tim Mousel
I've got the HTML tag issue resolved.

Next question:

At the bottom of result_details.tpl I have this:

CODE
{php}
include("http://www.knowyouragent.net/review/review_insert.php?item_id={$location.id}");
{/php}


Since that is inside the {php} tags it's not getting parsed.

How can I get the $location.id appended to the end of my url?

Thanks,

Tim
Brian
I am not a Smarty Template Engine expert by any means, but I remember doing a custom job for a client a few months back and I ran across this exact same scenario. I never did figure out how to get a Smarty Variable to cross over into my custom php code. And therefore had to find another approach.

I will look and try to remember which client it was and see if I can recall the code. I can't make any promises as I see alot of code and it is hard for me to remember which 'folder' to find it in out of the hundreds I have.

In the meantime, visit the smarty site http://smarty.php.net
Brian
Try something like this in your template:

{include_php file='../review/review_insert.php?item_id=$location.id'}
Tim Mousel
QUOTE(Brian @ Feb 17 2008, 07:06 AM) *
Try something like this in your template:

{include_php file='../review/review_insert.php?item_id=$location.id'}


Thanks Brian.

When I use this:

CODE
{include_php file='http://www.knowyouragent.net/review/review_insert.php?item_id={$location.id}'}


I get this:

CODE
Fatal error: Smarty error: [in result_details.tpl line 277]: syntax error: invalid attribute name: '=' (Smarty_Compiler.class.php, line 1531) in /homepages/htdocs/locator/libs/Smarty.class.php on line 1095


When I use this:

CODE
{include_php file='../review/review_insert.php?item_id=$location.id'}


I get this:

CODE
Warning: Smarty error: file:../review/review_insert.php?item_id=$location.id is not readable in /homepages/htdocs/locator/libs/Smarty.class.php on line 1095 Warning: _include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/local/lib/php') in /homepages/htdocs/locator/libs/Smarty.class.php on line 1922



When I use this:

CODE
{include_php file='http://www.knowyouragent.net/review/review_insert.php?item_id=$location.id'}


I get this:

CODE
Warning: Smarty error: http://www.knowyouragent.net/review/review_insert.php?item_id=$location.id is not readable in /homepages/htdocs/locator/libs/Smarty.class.php on line 1095


The permissions on review_insert.php are 644.

Any other ideas?

Thanks for your help.

Tim
Brian
When I see Not Readable error message, the first thing to mind is permissions. Have you tried other permission settings? Such as 755 or 777 on the review script?
Tim Mousel
QUOTE(Brian @ Feb 18 2008, 02:44 AM) *
When I see Not Readable error message, the first thing to mind is permissions. Have you tried other permission settings? Such as 755 or 777 on the review script?


Hi,

The permission is set to 777 on the review_insert.php file and same problems persist.

If I use this the page will display:

CODE
{include_php file='../review/review_insert.php'}


But that does no good without the item_id as this gives an error:

CODE
{include_php file='../review/review_insert.php?item_id=28'}


Error:
CODE
Warning: Smarty error: file:../review/review_insert.php?item_id=28 is not readable in /homepages/htdocs/locator/libs/Smarty.class.php on line 1095

Warning: _include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/local/lib/php') in /homepages/htdocs/locator/libs/Smarty.class.php on line 1922


Thanks for any additional advice,

Tim
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.