Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Rendering PHP in dynamic and static

Quote Reply
Rendering PHP in dynamic and static
Hi,

I need to render some php code in my category and link descriptions. Is this possible? If so, how do I go about doing so?

I've tried changing the following in Build Settings:

build_index to index.php

and

build_extension to .php

Also, I would want it to work in both static and dynamic.

Lastly, if implement this, is there a way to do an rewrite so that my dynamic and static pages still look like index.html and *.html?

Thanks in advance for any help or insight anyone can offer!
Quote Reply
Re: [ATKOgirl] Rendering PHP in dynamic and static In reply to
Hi,
I'm including php with a global

Code:
sub {
return `php /full_path/file.php`;
}

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Rendering PHP in dynamic and static In reply to
...and I pull in a PHP script which displays thumbnails on my home page by inserting this into my home page template. This is on a dynamic site.
Code:
<%LWP::Simple::get('http://www.yoursite.com/photos/thumbs.php')%>


Cheers,

Piers

Last edited by:

Piers1: May 12, 2008, 4:01 PM
Quote Reply
Re: [Piers1] Rendering PHP in dynamic and static In reply to
Hi Piers,

Thank you so much! I will give it a try.

Cheers,
ATKOgirl
Quote Reply
Re: [ATKOgirl] Rendering PHP in dynamic and static In reply to
I tried this, but it won't work for my needs.

I need to include different php code for each category and link rather than one external script I can reference across the board in my templates.

Ideally, I would like to insert the php into the description field.

Any further suggestions are greatly appreciated!
Quote Reply
Re: [ATKOgirl] Rendering PHP in dynamic and static In reply to
Hi,

You probably would need to add a new field via Database > Category > Properties > Add Field

Name: PHP_Script
Type: CHAR
Size: 255
Form Size: 10

Then, add a new global - called exec_php, with this:

Code:
sub {
return `php $_[0]`;
}

The, in your category.html add something like this:

Code:
<%if PHP_Script%>
<%exec_php($PHP_Script)%>
<%endif%>

..wherever you want the output to go.

For each of the categories, put a value in the PHP_Script field, like:

/ful//path/to/script.php

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!
Quote Reply
Re: [Andy] Rendering PHP in dynamic and static In reply to
Hi Andy,

Thanks so much for your reply.

Is there a way to reference the script directly in the field rather than referencing it exterenally? We will need to do this for several thousand categories and links, so it is not feasible to have the external reference.

Again, any information you can offer is greatly appreciated!
Quote Reply
Re: [ATKOgirl] Rendering PHP in dynamic and static In reply to
Hi,

Quote:
Is there a way to reference the script directly in the field rather than referencing it exterenally? We will need to do this for several thousand categories and links, so it is not feasible to have the external reference.

Not sure what you mean. Are you saying can you simply just put

php /path/to/script.php

...into the PHP_Script field?

If so, then no - I don't think that'll be possible, cos it still needs to run through the global, to get the output =)

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!
Quote Reply
Re: [Andy] Rendering PHP in dynamic and static In reply to
Hi Andy,

Thanks again for your response.

To clarify, I want to put the actual code in a database field and then have it render on my page. This would allow me to bulk upload my information, since there are several thousand categories and links. It would look something like this for each category and link:

<?php
# Determine the current base URL
if(!isset($_SERVER['REQUEST_URI'])) {
$psps_base_url = $_SERVER['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $psps_base_url .= $HTTP_SERVER_VARS['QUERY_STRING']; }
} else {
$psps_base_url = $_SERVER['REQUEST_URI'];
}
$psps_parameters = '';
foreach ($_REQUEST as $key => $value) {
if (strpos($key,"psps_") > -1 ) {
$psps_parameters .= '&'.$key.'='.urlencode($value);
$psps_base_url = str_replace('&'.$key.'='.urlencode($value), "", $psps_base_url);
$psps_base_url = str_replace($key.'='.urlencode($value), "", $psps_base_url);
}
}
$psps_parameters .= "&psps_show_search=true";
$psps_parameters .= "&psps_show_navigation=true";
$psps_parameters .= "&psps_show_products=true";
$psps_url = "?psps_base_url=".urlencode($psps_base_url);
$psps_url="http://shops.sitename.com/..._url$psps_parameters";
# Include the shop
if (function_exists('curl_init')) {
$shop=curl_init();
curl_setopt($shop,CURLOPT_URL,$psps_url);
curl_exec($shop);
curl_close($shop);
} else {
readfile($psps_url);
}
?>

I also need to include the following at the top of my pages, but I can do that by either creating a global or by putting it in the header, I think:

<?php ob_start(); ?><?php if ($_REQUEST['psps_product']) header('Location:http://r.sitename.com/'.$_REQUEST['psps_product']); ?><?php ob_end_flush(); ?>


AGAIN, THANK YOU SO MUCH FOR RESPONDING!! Blush
Quote Reply
Re: [ATKOgirl] Rendering PHP in dynamic and static In reply to
Hi,

In short, I don't think thats possible :(

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!