-
Information Architect
php include problem - please help!
I have a funny php problem:
PHP Code:
$output .= include("http://www.rogotworld.com/header.inc");
$output .= " <-- This is a ghost number. I can not find this in the php script. LOL ;-)";
As you see I use include to add a header to a php script. Funny thing is that it adds a "1" after the header. As you see I added an extra line to check if the number is coming from the script that follows after the include or not ... it's defenitly from the include line. I normaly use require on my other pages, but this is not working in this script. Hmmm ... any ideas?
Fredi
PS: You can have a look at the working script here: http://www.rogotworld.com/headlines
-
Hi,
I never used include in that way....
The include function has a return value itself (success / failure), so you are probably just adding the success status to your output.
Try declaring a function in the included file and calling that function later.
BTW: why are you accessing a file on your own server via http?
Musicman
-
Information Architect
Originally posted by Musicman
BTW: why are you accessing a file on your own server via http?
Musicman
I'm not using http on the real script, I use the server path. I just replaced it with http as I not wanna show my server structure here.
Anyway, I'm not really the PHP pro, so is there an easy way to hide the return value?
Fredi
-
Greets Subway
If I recall correctly, you installed one of my original chats in your site many moons ago...long time no hear.
Anyway, include is for outputting and interpreting PHP code in the included file. If that's all you need to do, put the include statement (sans '$output=') at the top of the script and walk away.
If you need to store the content of the file into a variable (without interpretation), I'd use a function that uses fopen() to open the file and fgets() to store it's contents to a variable.
If you need to store the content of a file AND have the file interpreted, you have to use output buffering controls. I've done this with a function and it actually worked.
If there are easier ways to do the above, I can't think of them.
-
Information Architect
Thx, will try it out.
Fredi
PS: Yup, I tryd your chat script out, really a long time ago.
-
Information Architect
Ok, the easyer way works, but will output an error message:
Warning: Cannot add header information - headers already sent by ...
I will try now the other way around the problem.
Fredi
Edit: Ok, not the perfect solution, but a very easy solution. I just colored the return output white.
Last edited by Subway; 12-10-2002 at 06:49 AM.
-
The output header error can mean several things need to be done to make the simple include work.
However, if you don't need interpretation, this simple function will return the contents of your file.
PHP Code:
function getFileContents($filename) {
$c = '';
$fp = fopen($filename, 'r');
while (!feof($fp)) {
$c .= fgets($fp, 1024);
}
fclose($fp);
return $c;
}
[Example]
$output = getFileContents('header.inc');
Will store header.inc text in $output
-
So what's new with your design work?
Got anything good going on? I could use some work done if you don't mind. Maybe I'll send you an email.
-
Information Architect
Re: So what's new with your design work?
Originally posted by torray
Got anything good going on? I could use some work done if you don't mind. Maybe I'll send you an email.
Rogot World is my actual project, finished two chapters for a book and I have to do some small client projects. Anyway, just send me the mail.
Fredi
-
Hi,
if header.inc is just a plain html file and does not contain any code (this is the impression I get when I open www.rogotworld.com/header.inc in the browser) you should just rearrange your code so that any headers are sent first, then include that file, then do the remainder of the page
Musicman
-
Information Architect
I tryd it before, but it's not working. Anyway, here's the code of the index file:
PHP Code:
<?php
//The config file holds the DB and Admin login information
include_once("config.php");
//Test for Admin Access
global $pwd;
if(!isset($pwd)){//the Password is either part of the url, or has been passed by a form.
//If is is not submitted then set the PWD var to the value of the admin cookie...
//if the admin cookie does not exist on the user system then $pwd will surely be wrong...
global $HTTP_COOKIE_VARS;
$pwd = base64_decode($HTTP_COOKIE_VARS["myhAdmin"]);
}
$isAdmin=0; //assume this is not admin, until proven otherwise.
if($pwd==$MyHeadlines_Admin_PWD){ //if the password is correct then set isAdmin
$isAdmin=1;
setcookie("myhAdmin",base64_encode($pwd),time()+900); //set timeout for cookie to 15 minutes
}else{
setcookie("myhAdmin","00",time()-3600); //delete the cookie if it exists...
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// Display Functions...
function loginPrompt(){
$output ="<sub><a href=index.php?op=login>login</a></sub><p>";
return $output;
}
///////////////////////////////////////////////////////
// Main Code Fragment
global $op;
if($op=="login"){ //if the user wants to login, show login form, otherwise show MyHeadlines
$output = "<form action=index.php method=post>";
$output .= "Password:";
$output .= "<input type=password name=pwd><p><input type=submit>";
}else{
$headlines = new MyHeadlines; //create a MyHeadlines Object
$headlines->MYH_INIT("index.php?y=0", "myh4_", $isAdmin,0,0,0); //init the object... (see API.txt)
$headlines->registerMenuURL("Option:","Admin Login","index.php?op=login");
$output .= include("/home/rogotwld/public_html/headlineheader.inc");//header
//$output .= " <-- This is a ghost number. I can not find this in the php script. LOL ;-)";
$output .= "<font face=\"Arial, Helvetica, sans-serif\">";
$output .= "<table border=0 width=646><td>";
$output .= $headlines->showGUI();//main MyHeadlines screen
$output .= $headlines->userSubscriptionScreen();//display your subscriptions
$output .= "</td></table><br><center>";
}
$output .= "</font>";
echo $output; //send it to the browser....
echo include("/home/rogotwld/public_html/footer.inc");//footer
?>
Maybe you can see why. I never really learned php, so I'm happy if I can find the right places to replace html code or add the header/footer.
Fredi
-
Hi,
just including the file should be fine in this place, since the $output variable has not yet been used. Also, you could just include the footer - without that echo command that adds a ghost 1 at the very end of your file.
The first time the $output is used ($output = "<font face....) there should not be a .= but a plain =
Musicman
-
Information Architect
Thx for the footer one. (I don't think anyone would notice it, but better without it)
The header: I can't just add the header to the top (right after the php tag). It will generate this output:
Warning: Cannot add header information - headers already sent by (output started at /home/rogotwld/public_html/headlineheader.inc:6) in /home/rogotwld/public_html/headlines/index.php on line 19
Hmmm ... I had the same problem with a poll some time ago, but can't remember how I did it.
Fredi
-
Hi,
I cannot see what is going on there - it says that code on line 19 (which is the setcookie unless you have removed some parts of the script) is called after the header already was output
Musicman
-
Information Architect
Originally posted by torray
The output header error can mean several things need to be done to make the simple include work.
However, if you don't need interpretation, this simple function will return the contents of your file.
PHP Code:
function getFileContents($filename) {
$c = '';
$fp = fopen($filename, 'r');
while (!feof($fp)) {
$c .= fgets($fp, 1024);
}
fclose($fp);
return $c;
}
[Example]
$output = getFileContents('header.inc');
Will store header.inc text in $output
If I use this function, then I get back an error message: Parse error: parse error, unexpected T_STRING in /home/rogotwld/public_html/headlines/index.php on line 30
Line 30 is the first line of the script. (function ...)
Anyway, I will add a picture next to the ghost number, so the wasted space will get a usefull function.
Fredi
-
Look elsewhere
There is an error elsewhere in the script prior to the function. Perhaps a missing quotation mark...
-
Information Architect
Ok, thx for the help. It's now working without ghost numbers.
Thx to Musicman for the working code. Here's the solution:
The old code
PHP Code:
$output = include("headlineheader.inc");
$output .= "<img src=\"....
The new code
PHP Code:
include("headlineheader.inc");
$output = "<img src=\"....
Fredi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|