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);
?>
Using PHP as an include file
Moderator: General Moderators
I dont know how much help I can be but remember, when you include a file into another file, the included file is now basically in the same location on the server as the other file.
So, if the first file is in / and the included file is in /forums, and inside the included file is references to locations relevent to /forums, they must be changed so that the references are relevent to /
So, if the first file is in / and the included file is in /forums, and inside the included file is references to locations relevent to /forums, they must be changed so that the references are relevent to /
I'm fairly sure that the problem is that the PHP code is not executing from within my .shtml file.
Embedding this code in the web page:
<?php
$color = 'green';
$fruit = 'apple';
echo "A $color $fruit";
?>
Results in nothing being displayed.
Any way to overcome this? (Without renaming the page with a .php extension that is?)
Embedding this code in the web page:
<?php
$color = 'green';
$fruit = 'apple';
echo "A $color $fruit";
?>
Results in nothing being displayed.
Any way to overcome this? (Without renaming the page with a .php extension that is?)
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
...
I guess the SSI include isnt working properly.
Why not just change this page to .php and include the news page with include();
Why not just change this page to .php and include the news page with include();
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Unless .shtml pages are setup to parse as PHP then it won't parse any PHP. If you want to use PHP code in a page it needs an extension that is recognised as PHP - including a .php page into a .shtml page doesn't work because the server is looking at the parent page (.shtml) and doesn't care about the extension of the included page.
Mac
Mac