Using PHP as an include file
Posted: Wed Jul 30, 2003 12:08 am
I have a web page that includes a PHP script to display news in the main frame of the site.
The current setup worked fine with my previous web host. However since moving my site to a new host it has stopped working. Was hoping someone here might be able to shed some light on this, is it a configuration problem possibly?
When you access the news script directly:
http://www.shatteredsosaria.com/forums/pluhnewz.php
It works fine.
However, including it in a web page using:
<--#include file="forums/pluhnewz.php"-->
Results in this:
http://www.shatteredsosaria.com/News.shtml
The base PHP file seems to be included, but it is not filling variables or parsing correctly.
Here is the original news script. The required files contain values for most of the variables. The web page rests in the root directory, the pluhnewz.php file and the required files are in the forums directory. However, I don't think the problem is the script since the script itself works fine and I could include it as above on a previous web host.
<?php
require("./global.php");
require("./pluhconfig.php");
require("./admin/config.php");
//include the header
include("./pluhheader.txt");
//connect
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");
//select database
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");
// create sql statement
$sql = "SELECT threadid, title, forumid, replycount, postusername, postuserid, lastposter, dateline, iconid FROM thread WHERE forumid = \"$roleplaynewsforums\" OR forumid = \"$oocnewsforums\" ORDER BY threadid DESC LIMIT $newsitems";
//execute sql query
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");
if (!$sql_result) {
echo "<p>Could not get record.";
}
while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$title = $row["title"];
$forumid = $row["forumid"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
$iconid = $row["iconid"];
$dateline = $row["dateline"];
//create the second SQL statement to pull the post from the thread it resides in
$sql2 = "SELECT postid, threadid, username, userid, title, dateline, pagetext, iconid FROM post WHERE threadid = \"$threadid\" ORDER BY postid ASC LIMIT 1";
//execute second sql query
$sql_result2 = mysql_query($sql2, $connection) or die ("Could not execute query in second sql statement.");
if (!$sql_result2) {
echo "<p>Could not get record in second statement.";
}
while ($row2 = mysql_fetch_array($sql_result2)) {
$pagetext = $row2["pagetext"];
//gotta convert that damn unix time crap
$dateposted = date("D j M Y, g:i A",$dateline);
//end the goodies
if ($replycount==1) {
$commenttext = "Comment";
}
else {
$commenttext = "Comments";
}
$bericht=bbcodeparse2($pagetext,"1","1","1","1");
// **********************
//Edit the HTML here (keep in mind that any double quote that is HTML requires a backslash in front of it)
if ($forumid==$roleplaynewsforums) {
$forumidicon = "WorldNewsIcon.jpg";
$forumidtext = "Town Cryer News ";
}
else {
$forumidicon = "DevNewsIcon.jpg";
$forumidtext = "Developer News ";
}
$baricon = "bar.jpg";
echo "
<img src=$forumidicon align=left hspace=10>
<a href=\"$forumspath/showthread.php?s=&threadid=$threadid\"><b><font color=#FFFFC0>$title</b></a></font><font size=1><br>
<font color=#CCCCFF>$forumidtext posted By <a href=\"$forumspath/member.php?s=&action=getinfo&userid=$postuserid\"><b>$postusername</b></a> on <i>$dateposted</i> <a href=\"$forumspath/showthread.php?s=&threadid=$threadid\">($replycount $commenttext)</a></font></font>
</center>
</a><p>$bericht<center><a href=\"$forumspath/showthread.php?s=&threadid=$threadid\"><p><font color=#CCCCFF>Comment on news</font></a> (Last comment was by <font color=#CCCCFF><b>$lastposter</b>)</font></center> <center><hr noshade height=\"1\" width=\"60%\"><p></center><br>
";
}
}
//add news search stuff (this is optional - delete if you do not wish to include this, or edit it to meet your needs
//echo "<center><a href=\"$forumspath/search.php?s=\">Search the News</a> | <a href=\"$forumspath/forumdisplay.php?s=&forumid=$newsforums\">View All News Posts</a></center>";
//end HTML edit
//**********************
//include the footer
include("./pluhfooter.txt");
//disconnect
mysql_free_result($sql_result);
mysql_close($connection);
?>
The current setup worked fine with my previous web host. However since moving my site to a new host it has stopped working. Was hoping someone here might be able to shed some light on this, is it a configuration problem possibly?
When you access the news script directly:
http://www.shatteredsosaria.com/forums/pluhnewz.php
It works fine.
However, including it in a web page using:
<--#include file="forums/pluhnewz.php"-->
Results in this:
http://www.shatteredsosaria.com/News.shtml
The base PHP file seems to be included, but it is not filling variables or parsing correctly.
Here is the original news script. The required files contain values for most of the variables. The web page rests in the root directory, the pluhnewz.php file and the required files are in the forums directory. However, I don't think the problem is the script since the script itself works fine and I could include it as above on a previous web host.
<?php
require("./global.php");
require("./pluhconfig.php");
require("./admin/config.php");
//include the header
include("./pluhheader.txt");
//connect
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");
//select database
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");
// create sql statement
$sql = "SELECT threadid, title, forumid, replycount, postusername, postuserid, lastposter, dateline, iconid FROM thread WHERE forumid = \"$roleplaynewsforums\" OR forumid = \"$oocnewsforums\" ORDER BY threadid DESC LIMIT $newsitems";
//execute sql query
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");
if (!$sql_result) {
echo "<p>Could not get record.";
}
while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$title = $row["title"];
$forumid = $row["forumid"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
$iconid = $row["iconid"];
$dateline = $row["dateline"];
//create the second SQL statement to pull the post from the thread it resides in
$sql2 = "SELECT postid, threadid, username, userid, title, dateline, pagetext, iconid FROM post WHERE threadid = \"$threadid\" ORDER BY postid ASC LIMIT 1";
//execute second sql query
$sql_result2 = mysql_query($sql2, $connection) or die ("Could not execute query in second sql statement.");
if (!$sql_result2) {
echo "<p>Could not get record in second statement.";
}
while ($row2 = mysql_fetch_array($sql_result2)) {
$pagetext = $row2["pagetext"];
//gotta convert that damn unix time crap
$dateposted = date("D j M Y, g:i A",$dateline);
//end the goodies
if ($replycount==1) {
$commenttext = "Comment";
}
else {
$commenttext = "Comments";
}
$bericht=bbcodeparse2($pagetext,"1","1","1","1");
// **********************
//Edit the HTML here (keep in mind that any double quote that is HTML requires a backslash in front of it)
if ($forumid==$roleplaynewsforums) {
$forumidicon = "WorldNewsIcon.jpg";
$forumidtext = "Town Cryer News ";
}
else {
$forumidicon = "DevNewsIcon.jpg";
$forumidtext = "Developer News ";
}
$baricon = "bar.jpg";
echo "
<img src=$forumidicon align=left hspace=10>
<a href=\"$forumspath/showthread.php?s=&threadid=$threadid\"><b><font color=#FFFFC0>$title</b></a></font><font size=1><br>
<font color=#CCCCFF>$forumidtext posted By <a href=\"$forumspath/member.php?s=&action=getinfo&userid=$postuserid\"><b>$postusername</b></a> on <i>$dateposted</i> <a href=\"$forumspath/showthread.php?s=&threadid=$threadid\">($replycount $commenttext)</a></font></font>
</center>
</a><p>$bericht<center><a href=\"$forumspath/showthread.php?s=&threadid=$threadid\"><p><font color=#CCCCFF>Comment on news</font></a> (Last comment was by <font color=#CCCCFF><b>$lastposter</b>)</font></center> <center><hr noshade height=\"1\" width=\"60%\"><p></center><br>
";
}
}
//add news search stuff (this is optional - delete if you do not wish to include this, or edit it to meet your needs
//echo "<center><a href=\"$forumspath/search.php?s=\">Search the News</a> | <a href=\"$forumspath/forumdisplay.php?s=&forumid=$newsforums\">View All News Posts</a></center>";
//end HTML edit
//**********************
//include the footer
include("./pluhfooter.txt");
//disconnect
mysql_free_result($sql_result);
mysql_close($connection);
?>