Gossamer Forum
Quote Reply
Using PHP in templates
Hi!

I am trying to use php alongside the <%%> tags in my templates, but to little success.
Here is a small example of a template file that demonstrates what I want to do:

Code:
<!DOCTYPE html>
<html lang="en">
<head>
<title><%site_title%></title>
</head>
<body>
<?php echo "hello"; ?>
</body>
</html>
When I try this, the the php is simply converted to html comments. How do I get the php to parse?

Thanks
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Hi,

In order to get this working you must run your site in static mode (build static html pages) and change the extension in GLinks setup from .html to .php only then it will work.

Hope this helps.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
Thanks for the quick reply, Boris. I just need to make sure I follow your instructions correctly:

To change the extension, am I going to change the build_extension variable found under www.mysite.com/cgi-bin/section/admin/admin.cgi > Setup > Build Options ?

Thanks again Smile
Quote Reply
Re: [Coert] Using PHP in templates In reply to
That's correct!

Keep in mind though that any drastic changes (such as this one) will have negative impact on your site ranking in google!

If you already running your site in static mode it's worth trying to get your provider to reconfigure apache so php can parse .html files as well, this way google will continue to see your site as before, if you are running in dynamic mode you are out of luck I'm afraid.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
Thank you sir! I will keep this in mind. We are already running this site in static mode, so I will look into reconfiguring apache. 3 more quick questions:
1. Will reconfiguring apache to parse all .html files as php cause slower performance?
2. Will changing the build extension to .php cause slower performance?
3. After changing the build extension, will I need to change the file extensions of all my template files, or just those containing php code?

Thanks again
Coert
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Hi,

Coert wrote:
1. Will reconfiguring apache to parse all .html files as php cause slower performance?
- Yes, to what degree though depends on how big is the site, files and how powerful server is.

Coert wrote:
2. Will changing the build extension to .php cause slower performance?
- Same as 1.

Coert wrote:
3. After changing the build extension, will I need to change the file extensions of all my template files, or just those containing php code?
- After changing the extension in the admin panel on the next rebuild GLinks will re-create all files with .php extension. You don't have to change the extensions of the template files.

Is it something php specific you are trying to achieve? It might be worth looking at doing it in a native GLinks way first?

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
I changed the build extension, and everything works ok, except when I click a link to view a detailed page. I attached a screenshot of when it doesn't work. It seems like the urls of the links still point to the .html version of the page. I found the code that builds url, and it looks like this:
Code:
"<%config.build_detail_url%><%build_link_detail_url($photo_ID,'photos')%>"

Seems like I will need to fix the url generator.

My task is to get a previous developer's php application running on GLinks. It's a pretty big piece of code, and I want to make minimum changes. The problem is that the previous developer didn't really develop it within the GLinks environment. It is an isolated piece of php. I want to use his code, but still make use of the GLinks functionality.

Last edited by:

Coert: Aug 4, 2014, 4:43 AM
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Hi,

build_link_detail_url looks to me as glinks global you should look to it in admin panel where it produces the final code and change the extension if it's hardcoded.

As for how to integrate that PHP app ... depends on how it works, there might be other ways but hard to say without know how the code in question works. :(

Uh, oh ... i've seen this site it's been around for many years I think the google penalty might be too much in it's case :\

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
Thanks for the reply.


Am I right if I say that the only way I will use PHP on this site without crippling my google ranking too much is if I get apache reconfigured to parse all .html files as php? That way my structure won't look any different to the search engines, but it might affect my performance a little.

Thanks
Coert
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Yes, as far as i see it at this point.

Ofc the best option is to get that PHP code rewritten to be proper GLinks code (either via plugin or global).

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
I changed the build extension to .php to test it, and the php is still not being parsed...
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Hmmm, are you sure the site is not running in rewrite mode (still being dynamic but only looks like static for the sake of search engine rankings).

Just tested on dev install and it works fine for me without any adjustments.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
Hi
Where can I find the info to see if I am running in rewrite mode?
Thanks
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Well, do you have a bunch of .html files in your system?

Also look inside your .htaccess file if the directory is containing only .cgi files and .htaccess is full of rules then you are running it rewrite mode.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Using PHP in templates In reply to
Thanks Boris

It seems that that you are right about the site running in rewrite mode.

Would there be any other workaround that allows me to use php? I have used ajax to pull in php scripts client-side, but I'm hoping to find a way to do it server-side.

Regards
Coert
Quote Reply
Re: [Coert] Using PHP in templates In reply to
Hi,

You should be able to run the PHP commands via a global:

exec_php
Code:
sub {
return `php /path/to/command/foo.php`;
}

Then call with:

Code:
<%exec_php%>

Some servers require you to use /usr/bin/php (or whatever the full path to PHP is on your server)

Hope that helps

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!