Forum Moderators: coopster

Message Too Old, No Replies

Including PHP in PHP includes :)

         

jeremymgp

12:10 pm on Sep 26, 2004 (gmt 0)

10+ Year Member



Hi,

Newbie PHP question this one - I'm using PHP includes in my HTML pages fine with this code:

<?php include("http://www.mysite.com/includes/footer.php");?>

However, in footer.php I can only use HTML - straight HTML works fine but if I include any PHP tags such as "<?php" or "<?" I get a "parse error".

The way my server is configured I can use includes from files ending in htm/html, I just add the include code and it works great - maybe this is relevant.

What I'm trying to do is have the include content rotatable. Each page accesses a footer include which in turn uses PHP to select 1 of several different HTML links. Here's what I'm using in my include:

-- Working HTML content here --

<?php
$url1="http://www.site1.com/">text1"
$url2="http://www.site1.com/">text2"
$url3="http://www.site1.com/">text3"
$charset="0321";
$random=$charset[rand(0,2)+1]
$urlname="url".$random
print "<a href="$urlname">";
?>

-- More Working HTML content here --

Also being such a newb I'm not sure if all the quotation marks in my code are correct (never mind the code itself :) ).

Any help much appreciated,

Thanks,

Jeremy

mincklerstraat

1:26 pm on Sep 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This might be because you're using the full url in the include. You can also use 'relative' url's, which is generally how you'll want to include php files and stuff that has php commands in it. E.g., if the page is at mysite.com/index.php, and you want to include the file mysite.com/includes/includefile.php, this would be:
include '/mysite.com/includes.php';
if it's in the same directory, drop the beginning slash and just put the name of the file between the quotes.
And check the php manual on 'include'. [be2.php.net...]

jeremymgp

8:21 pm on Sep 26, 2004 (gmt 0)

10+ Year Member



Hi,

Thanks for the response, I've never had problems before with absolute URLs and I tried your relative URL idea but no luck. Thanks anyway,

Ah hah, just tried using the simplest possible PHP code - one print statement. It worked, so it must be code that's wrong. I'll figure it out from here I guess. Thx again,

all the best,

Jeremy

lorax

2:06 am on Sep 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The most common mistake for beginning PHP programmers is forgetting to end a line of code with a semicolon ';' A missing semicolon will surely give you a parse error!

jeremymgp

12:55 pm on Sep 27, 2004 (gmt 0)

10+ Year Member



thx lorax,

Yep, I figured that after I sent, fixed all my semicolons and also learnt how to print quotation marks as well as using them in actual code. Thx

Jeremy

timster

3:28 pm on Sep 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php include("http://www.mysite.com/includes/footer.php");?>

If you like absolute URL's, I'd suggest something more like this:

include("/includes/footer.php");

Including the domain information is probably redundant, slightly slower, and may cause problems down the road.

beginner

4:03 pm on Sep 27, 2004 (gmt 0)

10+ Year Member



As a complete newbie, I want ot set up a local server to experiment with server-side scripts on my own machine without connecting to the internet.
I have Apache 2, but it asks for a connection through my dial-up (yes, I know!) before it will do anything.
Once I connect, the Apache page comes up OK, but I need to configure it so that I can get past this, and also set up a cgi bin etc for testing.
I know this may seem a bit ambitious for an obvious idiot, but I thought I may as well go for it big time!
Any advice would be much appreciated.