PDA

View Full Version : Need a little help... please


01-18-2001, 03:51 AM
Hey guys... having a little trouble here, and hopefully somebody can shed some light on the problem...

I'm trying to include some vB login info in the header of my new site, which I'm coding in PHP, and I can't seem to get it working correctly.

The script I'm including, basically checks to see if the visitor is logged in, and displays the appropriate template. It's the only vB related code on the page. It worked fine when I was including it into an html page... but when I tried including it into a PHP page, it displayed the follow errors:

Warning: Cannot add header information - headers already sent in /usr/local/etc/httpd/htdocs/forums/global.php on line 705

Warning: Cannot add header information - headers already sent in /usr/local/etc/httpd/htdocs/forums/global.php on line 712

I'm not sure what the problem is, since I'm not very familiar with all of the things global.php does when it's required in a script. Perhaps somebody could help me figure this out? Here's the actual script I'm including:

<?
require("/usr/local/etc/httpd/htdocs/forums/global.php");
if ($bbuserid == 0){
eval( "echo dovars(\"" . gettemplate( "guestloggedin" ) . "\");" );
} else {
if ($bbusername == "" || (isset($bbusername))==0){
$getusername=$DB_site->query_first("SELECT username FROM user WHERE userid=$bbuserid");
$username=$getusername[username];
$bbusername = $username;
eval( "echo dovars(\"" . gettemplate( "userloggedin" ) . "\");" );
} else {
$username = $bbusername;
eval( "echo dovars(\"" . gettemplate( "userloggedin" ) . "\");" );
}
}
?>

Thanks in advance!

-Tom

01-18-2001, 04:36 AM
If you put your code at the top of the page as a test it will work fine.

I have this issue also and don't know how to fix it correctly.

01-18-2001, 06:57 AM
Yeah, I've noticed that too. It's nice to know I'm not the only one having this problem at least. I hope somebody can figure out a fix for this problem... I've been trying this thing working for a couple of days now, and I've had no progress at all :(

One way to fix the problem might be to make a copy of global.php and remove any extra code that isn't needed for the script to work. I don't know what all is needed though, so I haven't tried this.

-Tom

01-20-2001, 01:16 AM
Please check your global.php for whitespaces.

next to the first <?

and after the last ?>

delete ALL whitespaces :)

cu

01-20-2001, 03:25 AM
Thanks for the tip, but this is not a white space issue.

It has something to do with the user not having a cookie the global.php file is looking for?

Or that you already did other html before you did the options file.

01-20-2001, 03:45 AM
<?php
require("file");
?>
Whatever you were printing out before the code block
<?php

if ($bbuserid == 0){
eval( "echo dovars(\"" . gettemplate( "guestloggedin" ) . "\");" );
} else {
if ($bbusername == "" || (isset($bbusername))==0){
$getusername=$DB_site->query_first("SELECT username FROM user WHERE userid=$bbuserid");
$username=$getusername[username];
$bbusername = $username;
eval( "echo dovars(\"" . gettemplate( "userloggedin" ) . "\");" );
} else {
$username = $bbusername;
eval( "echo dovars(\"" . gettemplate( "userloggedin" ) . "\");" );
}
}
?>

01-20-2001, 03:52 AM
Yeah, it's not a whitespace problem... that was one of the first things I looked for. It seems to happen only when code requiring global.php it put after html. I finally gave up on it and just put the code above all of the html on the page.

I'm having another problem now where global.php is 'breaking' some database query code that I'm using to display newest additions to the database. The code works fine by itself, but when I add it to my template (which has the require(global.php) stuff at the top, it no longer works. It's making it really difficult to integrate the user authentication system with the rest of my site :(

If I knew what was needed from global.php for the user authentication and cookie management to work, I'd just cut and paste that stuff into a seperate file and use that. The extra code that sets headers, checks if the board is active, etc.. probably isn't needed for the rest to work.

-Tom

01-20-2001, 03:59 AM
You quite possibly aren't using the right database:

<?
require("global.php")
//blah blah

mysql_query("USE otherdb");

//blah blah
?>

01-20-2001, 04:24 AM
I'm not accessing the vBulletin database.. I'm accessing the database that stores my sites dynamic content. It works fine until I place the code inside the template that has the require(global.php) code... when I do that, it gives me the "0 is not a mysql result index" error message.

Is it possible my code has variables or something that conflict with variables defined in global.php?

-Tom

01-20-2001, 04:29 AM
Oh, I think I see what you mean... are you saying that it might be trying to access the vBulletin database?

I have the database selected using mysql_db_select()... I would think it would work with no problems.

-Tom

01-22-2001, 01:29 AM
Still struggling with this... I can't figure out why my script is conflicting with global.php. Here is the block of code that's having problems (keep in mind, it works fine when global.php is NOT required in the header of the script):

$connect=mysql_connect();
$db=mysql_select_db("forum",$connect) or die("Couldn't select database");

$results=mysql_query("SELECT favorites FROM user WHERE userid = '$uid'",$db);
list($favs)=mysql_fetch_row($results);
if ($favs == "") {
Die("You don't have any items in your favorites folder");
}

$favarray = explode("," ,$favs);
$total = count($favarray) - 1;
$db2=mysql_select_db("data",$connect) or die("Couldn't select database");

for ($i = 0; $i <= $total; $i++) {
$lid = $favarray[$i];
$getfavs=mysql_query("SELECT * FROM items WHERE id = '$lid'",$db2);
$result=mysql_fetch_array($getfavs);

I get the "0 is not a mysql result index" error on that last line of that code, where it fetches an array from the database query. Anyone have an idea of what part of that code is conflicting with global.php? Thanks.

-Tom

P.S. I know the code is probably a bit sloppy... I'm new to PHP and MySQL, so I'm still learning. It does work by iteself though :)