...

View Full Version : Include function



CaptainB
07-10-2007, 03:12 PM
Hi!

I have tried to include my guestbook with the php include function. However it dosn't work as it should.

This is my code:


<?php include("guestbook/index.php"); ?>

But when I then browse the page where it should be included on I get following : http://www.xflightx.port10.com/guestbook_view.php

The file IS in the same directory and permissions are set. So how would I get around that? I can't see why it can't find it..

PappaJohn
07-10-2007, 03:37 PM
It's saying it can't find a file named ardgb18.dat. So it would seem the problem is with that file, or with your guestbook code trying to open that file.

CaptainB
07-10-2007, 03:46 PM
The file you name is the file which stores all the data for the guestbook (all the comments). I have tried to re-upload it, but it still dosn't work.

richrich
07-10-2007, 03:51 PM
that is not a standard include error, can you locate the place where that bit of code is echoed and see what it is trying to do.

Take it right back to basics, see if you can print your name to the screen with the simplest echo ever. If that works you know it is not a permissions problem or something daft.

PappaJohn
07-10-2007, 03:51 PM
Then it would seem the problem is in the included guestbook code. A little hard to say without seeing the code, but possibly a path problem?

richrich
07-10-2007, 03:56 PM
$dir = "";
$root = $_SERVER['DOCUMENT_ROOT'];
$path = "$root$dir";

// Get Header Type
include("$path/includes/header.php");

If you want to see if the path is correct, echo each part above.

Mwnciau
07-10-2007, 04:08 PM
The problem is that the guestbook is trying to get ardgb18.dat in the current directory, whereas it is actually in your guestbook directory.

CaptainB
07-10-2007, 06:04 PM
Guys, thanks for the replies!

Mwnciau, u were right. It made a difference to put the file in the same directory (the root actually) as my index page. However isn't it possible to make it work with the file in my "guestbook" folder?

Also, not it returns some new errors:

Following is the code for the guestbook file: http://www.xflightx.port10.com/guestbook_view.php (Holy ****, it's too long to be here. I'll just post the code near to the error line:



<?
session_start();
$newline = (strtoupper($os) == "WIN") ? "\r\n" : "\n";
switch ($do) {
case "":
$record = file($data_file);
rsort($record);
$jmlrec = count($record);
?>

_Aerospace_Eng_
07-10-2007, 06:22 PM
You would need to change this line

$record = file($data_file);
to something like this

$record = file($_SERVER['DOCUMENT_ROOT'].'/guestbook/'.$data_file);

CaptainB
07-10-2007, 07:05 PM
Aerospace, that didn't make a difference (at least not one I can spot)?

_Aerospace_Eng_
07-10-2007, 07:07 PM
Aerospace, that didn't make a difference (at least not one I can spot)?

Which is why we need to see the rest of the code. Find some way to post it here.

CaptainB
07-10-2007, 07:18 PM
The site dosn't allow that many letters here...So I have zipped the index.php file with the code. Can be downloaded from here: http://www.xflightx.port10.com/index.zip

(I hope that's okay?)

_Aerospace_Eng_
07-10-2007, 07:47 PM
Change this

//Name of file used to store your entry, change it if necessary
$data_file = "ardgb18.dat";
to this

//Name of file used to store your entry, change it if necessary
$data_file = $_SERVER['DOCUMENT_ROOT']."/guestbook/ardgb18.dat";

guvenck
07-10-2007, 08:12 PM
Maybe the file needs to be uploaded in ASCII format?

CaptainB
07-11-2007, 12:32 PM
Aerospace, I changed what you said but that showed me more errors + the comments didn't show up. I then changed back with we did in the first post, and now I only have a few errors back + the posts show up.

You can still see the page here: http://www.xflightx.port10.com/guestbook_view.php

@ guvenck, how would I do that? I use SmartFTP...Could be the reason?

_Aerospace_Eng_
07-11-2007, 07:59 PM
Remove this

session_start();
on the index.php page for the guestbook. Should be around line 95.

Then make sure you are using session_start() at the very top of the guestbook_view.php page.

CaptainB
07-11-2007, 09:06 PM
Done, new errors:


Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/sites/port10.com/public_html/xflightx/guestbook_view.php:8) in /home/sites/port10.com/public_html/xflightx/guestbook/index.php on line 1

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sites/port10.com/public_html/xflightx/guestbook_view.php:8) in /home/sites/port10.com/public_html/xflightx/guestbook/index.php on line 1

However, could it be the binary-mode thing? That it isn't uploaded in that mode? (I don't know much about it)

_Aerospace_Eng_
07-11-2007, 09:20 PM
No these are php errors due to sessions being set after the page has sent code to the browser.
Post the code for guestbook_view.php

CaptainB
07-11-2007, 10:00 PM
There's no view.php. (Note that the error is still there when you are on the sign page).

The only php files the guestbook consists of is an index.php and an image.php (the file which generates the image code to prevent spambots)

I have zipped all the files included with the guestbook. Can be downloaded here: http://www.xflightx.port10.com/guestbook.zip

_Aerospace_Eng_
07-11-2007, 10:08 PM
Why do you have this on your index page for the guestbook?
session_start();
I told you to add that to guestbook_view.php which is why I asked for the code for guestbook_view.php NOT view.php.
Read what people post carefully please.

CaptainB
07-11-2007, 11:06 PM
Ow, I'm really sorry! I really gotta study the answears more than I already do - thanks for telling me! :)

Now it works!!

However...My image thing dosn't work. None of my images do actually work. I tried to delete the "session_start();" from the file, made no difference, so I added it again. I think that it might be something with the path to the images or something like that? But where can I correct it? I tried to search in the file, but I couldn't find the place (Maybe because I'm not good at php).

This is what I have in my image.php file, though I think that it would be somewhere in the index.php file that should be corrected?:

<?php
session_start();
$string = $_SESSION['secc'];
$str1 = substr($string,0,2);
$str2 = substr($string,2,2);
header("Content-type: image/jpeg");
$ardimg = @imagecreate(40, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($ardimg,150,150,150);
$text_color = imagecolorallocate($ardimg,0,0,0);
imagestring($ardimg,5,2,0,$str1,$text_color);
$text_color = imagecolorallocate($ardimg,255,255,255);
imagestring($ardimg,6,19,5,$str2,$text_color);
imagejpeg($ardimg);
imagedestroy($ardimg);
?>

_Aerospace_Eng_
07-12-2007, 11:08 AM
Find

<img src="image.php?<?=time()?>" border="1"><br>
Replace with

<img src="/guestbook/image.php?<?=time()?>" border="1"><br>

that probably won't get the image working. The image works if you have session_start() somewhere on the page that calls the index page which is why I've been telling you to post guestbook_view.php for the past 2 or 3 posts.

CaptainB
07-12-2007, 12:10 PM
..that probably won't get the image working. The image works if you have session_start() somewhere on the page that calls the index page which is why I've been telling you to post guestbook_view.php for the past 2 or 3 posts.

U were right.

Ok, here goes the code for the guestbook_view.php:


<?php include("lp_source.php"); ?>
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="title" content="XflightX" />
<meta name="author" content="CaptainB" />
<meta name="copyright" content=" 2007 - XflightX | All Rights Reserved" />
<meta name="keywords" content="XflightX, Flight, Planes, Airports, Forums, Graphic, Design, Website, Web, Simulation, FS9, FSX, FS2004, 2004, 9, 2007, 2006, Microsoft, Simulator, Live, ATC, Air, Traffic, Control, Community, Club, VA, Virtual, Airline, Multiplayer, Free, Downloads, Download, Scenery, Sceneries, Airplanes, Aeroplanes, Plane, Glider, Soaring, Soar, Condor, Misc, Helicopter, Helicopters, Vintage, Runway, Land, Cleared, Utilities, Utility, Panel, Panels, CaptainB" />
<meta name="description" content="A friendly flightsim community for Microsoft Flight Simulator 2004 and X + Condor - The Competition Soaring Simulator! You are cleared to land..." />
<meta name="audience" content="all" />
<link rel="shortcut icon" href="http://www.xflightx.port10.com/favicon.ico" type="image/x-icon" />
<!--[if !IE]>REMEMBER TO CHANGE TITLE<![endif]-->
<title>Home - XflightX - You are cleared to land...</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="calendar/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascripts.js"></script>
</head>
<body>
<div id="container">
<!--[if !IE]>HEADER BEGIN<![endif]-->
<div id="header"><a href="index.php"><img src="images/xflightx-header.gif" alt="XflightX" border="0" width="981" /></a></div>
<!--[if !IE]>HEADER END<![endif]-->
<div id="left">
<!--[if !IE]>MENU BEGIN<![endif]-->
<div id="uppermenu"></div>
<div id="menu"><img src="knapper/Home.gif" alt="Home" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu0, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Downloads.gif" alt="Downloads" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu1, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Guestbook.gif" alt="Guestbook" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu2, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/FlightClub.gif" alt="Flight Club" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu3, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Gallery.gif" alt="Gallery" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu4, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Forums.gif" alt="Forums" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu5, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Contact.gif" alt="Contact" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu6, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Links.gif" alt="Links" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu7, '168px')" onmouseout="delayhidemenu()"/><img src="knapper/KnowledgeBase.gif" alt="Knowledge Base" style="border-top-width:1px; border-bottom-width:0px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu8, '165px')" onmouseout="delayhidemenu()"/><img src="knapper/Design.gif" alt="Design" style="border-top-width:1px; border-bottom-width:1px; border-right-width:0px; border-left-width:0px; border-style:solid;" onmouseover="dropdownmenu(this, event, menu9, '165px')" onmouseout="delayhidemenu()"/></div><div id="lowermenu"></div>
<!--[if !IE]>MENU END<![endif]-->
<!--[if !IE]>LEFT SIDE BOXES BEGIN<![endif]-->
<!--[if !IE]>CALENDAR BEGIN<![endif]-->
<div id="calender"><h1>Calendar</h1>
<?php include('calendar/calendar.php');
$calendar = new WingedCalendar();

// to display a single calendar
$calendar->show_calendar();

// where PREVIOUS and NEXT are the number of months
// before and after the current month respectively.
?><h2><b>Feel free to add</b></h2>
</div>
<!--[if !IE]>CALENDAR END<![endif]-->
<div id="box_partners"><h1>Partners</h1><a href="http://www.freedomain.co.nr/" target="_blank"><img src="partners/co.nr.gif" alt="co.nr domains" width="150" height="30" border="0" /></a>
<a href="http://www.mysafetycards.piczo.com" target="_blank"><img src="partners/mysafetycards.gif" alt="Mysafetycards" width="150" height="30" border="0" /></a>
<a href="http://www.worldwidetopsites.com/php/in.php?id=Kasio" target="_blank"><img src="partners/topsitesvote.gif" alt="Vote for XflightX" width="150" height="30" border="0" /></a></div>
</div>
<!--[if !IE]>LEFT SIDE BOXES END<![endif]-->
<!--[if !IE]>MAIN CONTENT BEGIN<![endif]-->
<div id="main">
<center> <?php include("guestbook/index.php"); ?></center>
</div>
<!--[if !IE]>MAIN CONTENT END<![endif]--> <!--[if !IE]>RIGHT SIDE BOXES BEGIN<![endif]-->
<div id="right">
<!--[if !IE]>CLOCK BEGIN<![endif]-->
<div id="clock">
<script type="text/javascript">dT();</script>
</div>
<!--[if !IE]>CLOCK END<![endif]-->
<div id="box_announcement"><h1>Welcome</h1>
<h2>Hi and welcome to <b>XflightX!</b>
<br />
The site has now got an "extreme makeover", so feel free to browse around and see what's new!
Enjoy your stay and please feel free to <br /><a href="contact.php">contact me</a><br /> if you have any queries.</h2>
</div>
<!--[if !IE]>WEATHER BEGIN<![endif]-->
<div id="weather"><h1>Weather</h1><div id="paddingdiv">
<form name="frm" method="post" action="http://adds.aviationweather.noaa.gov/metars/index.php" target="popup" onsubmit="return createPopup(this.target);">
<input size="14" name="station_ids" type="text" style="font-size: 8pt; font-family: Arial" value="Enter ICAO" />
<br />
<input type="radio" name="std_trans" value="standard" checked="checked"/> Raw Format
<br />
<input type="radio" name="std_trans" value="translated"/> Translated
<br />
<input type="checkbox" name="chk_metars" checked="checked"/> METARs
<input type="checkbox" name="chk_tafs"/> TAFs
<br />
<select name="hoursStr">
<option selected="selected"> most recent only</option>
<option> past 1 hours</option>
<option> past 2 hours</option>
<option> past 3 hours</option>
<option> past 4 hours</option>
<option> past 5 hours</option>
<option> past 6 hours</option>
<option> past 12 hours</option>
<option> past 18 hours</option>
<option> past 24 hours</option>
<option> past 36 hours</option>
</select>
<br />
<br />

<input name="btnSubmit" style="font-size: 8pt; font-family: Arial" type="submit" value="Submit" />
<input type="reset" style="font-size: 8pt; font-family: Arial" value="Reset Form" />
</form></div></div>
<!--[if !IE]>WEATHER END<![endif]-->
<!--[if !IE]>POLL BEGIN<![endif]-->
<div id="box_poll"><h1>Poll</h1>
<div id="paddingdiv1"><?php echo($question); ?>
<br />
<?php if($votingstep==1) { echo($step1str); }
if($votingstep==2) { echo($step2str); }
if($votingstep==3) { echo($step3str); }?>
Total votes: <?php echo($totalvotes); ?>
</div>
</div>
<!--[if !IE]>POLL END<![endif]-->
</div>
<!--[if !IE]>RIGHT SIDE BOXES END<![endif]-->
<!--[if !IE]>FOOTER BEGIN<![endif]-->
<div id="footer"><h3><a class="footerlink" href="copyright.php"> 2007 - XflightX | All Rights Reserved</a><br/><a class="footerlink" href="about.php">About</a></h3>
</div>
<!--[if !IE]>FOOTER END<![endif]-->
</div>
</body>
</html>

aedrin
07-12-2007, 03:42 PM
Change this

//Name of file used to store your entry, change it if necessary
$data_file = "ardgb18.dat";
to this

//Name of file used to store your entry, change it if necessary
$data_file = $_SERVER['DOCUMENT_ROOT']."/guestbook/ardgb18.dat";

You could also just use:


$data_file = 'guestbook/ardgb18.dat';

There's no reason to include the entire path.

_Aerospace_Eng_
07-12-2007, 06:56 PM
You could also just use:


$data_file = 'guestbook/ardgb18.dat';

There's no reason to include the entire path.
Yes there is because someone can still access the guestbook by itself at least right now therefore guestbook/ardgb18.dat would become incorrect because their would be no guestbook folder inside of the guestbook folder.

@CaptainB What is in lp_source.php?

CaptainB
07-12-2007, 07:53 PM
@CaptainB What is in lp_source.php?

That's just a file for a poll (little poll) with following:

<?php

include("lp_settings.inc"); //include file containing general settings
import_request_variables("p", "p_"); //import POST variables
import_request_variables("c", "c_"); //import cookie variables

if (!isset($c_votingstep)) {
$votingstep=1;
} else { $votingstep = $c_votingstep; }

function SumArray($arr) {
$h=count($arr); $in=0; $m=0;
while ($in<$h) { $m += $arr[$in]; $in++; }
return $m;
}

function getIP() {
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else $ip = "UNKNOWN";
return $ip;
}

function write2log ($linetoadd) {
$rightnow=date("F j, Y, g:i a");
$fplog=fopen('lp_log.dat', "a");
fputs($fplog, getIP()."|".$rightnow."|".$linetoadd."\n");
fclose($fplog);
}

function ReadElements() {
global $filename;
$fp=fopen($filename, "r");
$file_contents=fread($fp,filesize($filename)-1);
fclose($fp);
$elements=explode(":",$file_contents);
$h=(count($elements)-1)/2;
$question=stripslashes($elements[0]);
$in=0;
while ($h>$in) {
$item[$in]=$elements[(2*$in+1)];
$itemvoted[$in]=$elements[(2*$in+2)];
$in++;
}
return array ($item, $itemvoted, $question);
}

list ($item, $itemvoted, $question) = ReadElements();

if(isset($c_pollidcookie)) {
if ($question != stripslashes($c_pollidcookie)) {
$votingstep=1;
}
}
setcookie("pollidcookie", $question, time()+$time_between_votes);

if (isset($votingstep)) {
function ShowTheStuff($item, $itemvoted, $graph_width, $graph_height) {
$hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr='';
$totalvotes=SumArray($itemvoted);
$in=0;
if ($totalvotes==0) { $totalvotes=0.0001; }
while ($in<$hector) {
$stepstr=$stepstr.stripslashes($item[$in]).': '.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br/>';
$timesred=(int)((($itemvoted[$in]/$totalvotes))*$graph_width);
$stepstr=$stepstr.'<img height='.$graph_height.' width='.$timesred.' src="lp_1.gif"><img height='.$graph_height.' width='.($graph_width-$timesred).' src="lp_0.gif"><br/><br/>';
$in++;
}
return $stepstr;
}
}

if (!isset($votingstep)) {
$votingstep=1;
}

if ($votingstep==2) {
if(!isset($p_radios)){
$votingstep=1;
write2log("Clicked vote button without choosing an item");
} // detect if someone has clicked the voting button without choosing an item
}

if ($votingstep==1) {
write2log("Enters Poll");
setcookie("votingstep","2",time()+$time_between_votes);
$mainstr=$message1;
$step1str='<form action="'.$callingfile.'" method="post" name="form1">';
$totalvotes=SumArray($itemvoted);
$in=0;
$datop=count($item);
while($in<$datop){
$step1str=$step1str.'<input type="radio" name="radios" value="'.$in.'"/> '.stripslashes($item[$in]).'<br/>';
$in++;
}
$step1str=$step1str.'<br/><input style="'.$buttonstyle.'" type="submit" value="'.$vote_str.'"/></form>';
}

if ($votingstep==2) {
setcookie("votingstep","3",time()+$time_between_votes);
$mainstr=$message2;
$itemvoted[$p_radios]=$itemvoted[$p_radios]+1;
$totalvotes=SumArray($itemvoted);
$fp=fopen($filename, "w");
$hector=count($item);
$in=0;
$linetoadd=$question.':';
fputs($fp, $linetoadd);
while($in<$hector) {
$linetoadd=$item[$in].':'.$itemvoted[$in].':';
fputs($fp, $linetoadd);
$in++;
}
fclose($fp);
write2log("Vote received on ".$item[$p_radios]);
$step2str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}
if ($votingstep==3) {
$mainstr=$message3;
$totalvotes=SumArray($itemvoted);
write2log("Views results");
$step3str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}

?>

_Aerospace_Eng_
07-12-2007, 08:10 PM
On guestbook_view.php move session_start(); to the VERY top of the page just after the opening <?php tag.

CaptainB
07-12-2007, 08:48 PM
On guestbook_view.php move session_start(); to the VERY top of the page just after the opening <?php tag.

Nope, it still dosn't show.

(I tried both of these:


<?php session_start(); ?>
<?php include("lp_source.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

and this:


<?php session_start(); include("lp_source.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> )

_Aerospace_Eng_
07-12-2007, 08:57 PM
You haven't even changed the code yet. You still have this in guestbook/index.php

<font size="1">Please retype this code below :</font>
<img src="image.php?1184270197" border="1"><br>
I told you to change that a few posts up.

CaptainB
07-12-2007, 10:13 PM
I had changed it but changed it back as it didn't made a difference = it still didn't work. However I have now changed it again to what you said - still no difference other than I now get a completely gray image where the image with the numbers/letters should have been. http://www.xflightx.port10.com/guestbook_view.php?do=add_form&page=1

_Aerospace_Eng_
07-12-2007, 11:14 PM
Hmm I think it might be your poll script causing the issue. As you can see just the guestbook script it works fine
http://prod.isgreat.org/guestbook_view.php?do=add_form&page=1

CaptainB
07-13-2007, 11:45 AM
Well, I'm not to sure about it, but I can see that it works for you (except with the pictures on the view page).

I tried to delete all traces of the poll from the guestbook_view page, no difference :confused:

_Aerospace_Eng_
07-13-2007, 05:46 PM
I'm attaching the files I have that currently work on my server. Be sure to make a backup of your current guestbook_view.php file. See if the attached files work for you. If they don't work then it seems like the the php GD image library may not have been installed correctly.

CaptainB
07-13-2007, 06:08 PM
That's incredible Aero, again you solved the problem like was it the easiest thing in the world!

Thanks a bunch!!!! (I was almost ready to give it up)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum