cancel
Showing results for 
Search instead for 
Did you mean: 

PHP in HTML

DJ1UK
Grafter
Posts: 69
Registered: 14-04-2007

PHP in HTML

Hi All,

I have a php script working on my cgi server, but I want to use it on a HTML page on my homepages server.

What is the correct code to use to include php in my html pages.

Eg Like <a href="mnmn"></a> (I know thats not right for php though!)

Thanks
16 REPLIES
N/A

PHP in HTML

You can only use PHP on the CGI server...
DJ1UK
Grafter
Posts: 69
Registered: 14-04-2007

PHP in HTML

Ahh thats why it doesn't work.

Can you not though access the php (thats on the cgi server) and reference to it on a normal HTML page?

Would i instead use my ohp page and access it directly from a link on a html page?

Thanks
N/A

PHP in HTML

hendryonline, Did you ever get a reply to your last post?

I have a PHP script to read the most recent posts from an RSS feed and show links to them in HTML. It works fine on the CCGI server, but I'd like to include it as just a part of another web page.

I tried an include of the PHP file in the HTML but got [an error occurred while processing this directive] on my web page.

So I tried putting the HTML page on the CCGI server with an include in that - doesn't seem to do anything...

Does anybody know how to call a PHP script (on the CCGI server) as an include from HTML (on either CCGI or Homepages)?
DJ1UK
Grafter
Posts: 69
Registered: 14-04-2007

PHP in HTML

Sorry No I don't think I ever got a reply on this one.

I've since rebuilt my website and no longer need the features of cgi.

Hope you get a response soon.
deepfatfrier
Grafter
Posts: 99
Registered: 26-09-2007

PHP in HTML

From what you've said, it sounds like you're trying to include some PHP inside normal HTML. Basically, you can't do this unless you make an iframe where you want the PHP to be, and point the iframe at the PHP script. It sounds much easier for you to just stick the HTML into the PHP file as echo commands and run it all off CCGI. This is just because the iframe solution is messy and let's face it, iframes are annoying... Wink
N/A

PHP in HTML

deepfatfrier, thanks for your post - I was trying to avoid using an iframe (because they are not considered good practice) and need to keep the calling HTML page on the homepages server (becuase it's the index page for my www site) so it looks like I'm a bit stuck.

I've been trying various things including:

<!--#include virtual="http://ccgi.markwilson.co.uk/php/rss2html/rss2html.php" -->

in my HTML on the homepages server and

<!--#include virtual="http://ccgi.markwilson.co.uk/php/rss2html/rss2html.html" -->

to include an HTML page on the CCGI server (which calls out to a PHP page) in an HTML page on the homepages server.

The strange thing is, that even an HTML page on the CCGI server with the following code:

<?php

include "/php/rss2html/rss2html.php";

?>

doesn't seem to work...
orrery
Grafter
Posts: 138
Thanks: 1
Registered: 30-07-2007

PHP in HTML

Doesn't the PHP include automatically open the PHP tag.

I assume that you'd have to explicitly close the PHP tag in the incuded page before the HTML, and then open it again before the end of the page.

regards
Ian
deepfatfrier
Grafter
Posts: 99
Registered: 26-09-2007

PHP in HTML

No problemo!

Quote
I've been trying various things including:

<!--#include virtual="http://ccgi.markwilson.co.uk/php/rss2html/rss2html.php" -->

in my HTML on the homepages server and

<!--#include virtual="http://ccgi.markwilson.co.uk/php/rss2html/rss2html.html" -->

to include an HTML page on the CCGI server (which calls out to a PHP page) in an HTML page on the homepages server.

The first one sounds most likely to work, but I'm not that familiar with including like that (I've always just used php includes)

Quote
The strange thing is, that even an HTML page on the CCGI server with the following code:

<?php

include "/php/rss2html/rss2html.php";

?>

doesn't seem to work...

Is this literally an HTML page (ie. it ends in *.htm or *.html)? If so, I don't think it'll get recognised as a PHP page, and so it won't get parsed as PHP (it'll get ignored, basically). You'll need to give it a *.php extension. Smiley
N/A

PHP in HTML

Thanks Andy. It is literally a .htm (or .html - can't remember which), because an include of a PHP page (on the CCGI server) from index.htm (which for various resons I need to leave on the homepages server) doesn't seem to work, so what I was trying to do is get one HTML page (on the homepages server) to include another HTML page (on the CCGI server), which does a PHP include for the scripts I want to run! :?

This is all getting a bit complex, so to pull this back to basics, all I really need to do is somehow call a PHP script (on the CCGI server) from an HTML page (on the homepages server).

Not looking too hopeful at present though and I'm not going to move the whole site to the CCGI server Sad
orrery
Grafter
Posts: 138
Thanks: 1
Registered: 30-07-2007

PHP in HTML

Quote
...all I really need to do is somehow call a PHP script (on the CCGI server) from an HTML page (on the homepages server).


It certainly was the case that one server couldn't see the other - unless this has changed? If this is the case, then what you trying to do isn't possible.

Maybe get the index.html to do an automatic redirect to the other server, as this executes on the client side?

regards Ian
N/A

PHP in HTML

The crucial thing about the SSI include statement, virtual or no virtual, is that the file *must* be on the same server. So as far as I'm aware, including a file at a different URL is not correct. Also, absolute paths are not allowed when using the virtual attribute.

So it's illegal to do:

<!-- #include virtual="http://example.com/test.html" -->

or

<!-- #include virtual="/mysite/cgi-bin/some_page.php" -->

Check out http://httpd.apache.org/docs/2.1/mod/mod_include.html#element.include for full details.

So unfortunately this is 1 less weapon in your arsenal for solving this problem...
N/A

PHP in HTML

Thanks guys - even bad news is good as it at least stops me from trying to continue down this blind alley... Wink

I guess that's it then. I can't have a portion of my homepage which is run as a PHP script on another server unless I use an iframe with a redirect (all I wanted to do was highlight my latest blog posts in a small part of my home page...) Cry

Thanks for all the help anyway.
N/A

PHP in HTML

I don't think there's a clean way round this problem but one thing you could try is uploading your index.htm with the new headlines in a php script.

Let's say your main page contains very little dynamic info, so little that it doesn't justify moving your whole site to the cgi server. And lets say this little dynamic info is just the latest blog headlines from you blog pages on the cgi site.

Now what i'm suggesting is to have some code on your main page such as the following:

<div id="latestHeadlines"></div>


When you add a blog entry using the addBlogEntry.php script or function or whatever you use, you could put code in that GETs a local copy of the http://www.your_web_space.com/main_page.html (i'm sure you could do this failry quick in PHP) and looks for the code above, and replaces it with the following:

<div id="latestHeadlines"><span id="h1">Headline 1</span><!-- and so on... --></div>


Again, i'm sure php could parse the file fairly quick and do this substitution (Regex's will come in handy here). Once it's been replaced you upload (in your PHP code) the new file from the cgi server to the homepages server. Uploading in php I think is also pretty easy.

I'm a bit rusty and I can't say I've tested the above, or know your situation well enough to say that this is a possible solution but it might be worth looking into.

Check out http://www.tizag.com/phpT/fileupload.php for file upload stuff.

HTH,
AC
N/A

PHP in HTML

That sounds interesting... Smiley I think I'll give it a go - even just for the technical challenge!!! My web site is very much a spare time thing, so might take me a while to try this out but I'm really grateful for the pointers. I'll post something here when I give it a go.

</mark>