Log in

View Full Version : [SOLVED]Garbage text getting printed on top of every custom page


nirvana43
07-21-2009, 05:04 AM
--------------------------------------------------------------------------------------------------------------------

PLEASE SCROLL DOWN AND SEE LAST REPLY

Update : Here is solution! (https://vborg.vbsupport.ru/showpost.php?p=1857069&postcount=16)
--------------------------------------------------------------------------------------------------------------------


Hello

Please check screen shot below :
http://img243.imageshack.us/img243/4039/sssssl.jpg

I'm designing 1 mod for vb 3.7.3 and there is garbage text getting printed on top of every custom page i've designed for mod.
However i've gone through every bit of code i've written, for like zillion times. But i'm not able to figure out what possibly could be causing above garbage.

The thing is, i just wanna know what kinda possible conditions could cause above garbage??
like custom redirection? <if> <else> condition? etc. etc.

I've followed all vbulletin API rules while coding and also double checked.
So if someone evah faced above thing in life before then kindly let me know what was causing it.

P.S. I know its because of my mod so please tell me something beside disabling hooks & mods (already done that).. b'cuz i'm tryin to get rid of that garbage. :(

R1lover
07-21-2009, 05:08 AM
Very hard to tell, bad code it the issue though... without knowing what you changed its hard to tell though.

nirvana43
07-21-2009, 05:18 AM
Very hard to tell, bad code it the issue though... without knowing what you changed its hard to tell though.

I didn't changed anything directly in any vb file...
here is more detailed explanation on what exactly i've coded :

Lets say my file 1 contains :

error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test');
$globaltemplates = array('test',);
require('./global.php');
include('test/test.php');
$navbits = array();
$navbits[$parent] = 'TEST';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
if (!$vbulletin->userinfo['userid'])
{
print_no_permission();
}
else
{
eval('print_output("' . fetch_template('test') . '");');
}


Now my test.php located at test/test.php does following :

include(dirname(__FILE__)."/inc.php");
done=0;
$init==0;
initcond="$init==1";
if ($init==1)
{
$inmsg.="<center>$state<br /></center>";
}
else
{
/*
go on initializing php variables

For e.g. :
*/
$msg="some message";
$initialised_variable="<table class='tborder' align='center'><tr><td>$msg</td></tr></table>";

}

still editing...

My template test contains following code :

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>TEST</title>
$headinclude
<script type='text/javascript'>
<!--
var checkCount=0
var maxChecks=$num
function setChecks(obj){
if(obj.checked){
checkCount=checkCount+1
}else{
checkCount=checkCount-1
}
if (checkCount>maxChecks){
obj.checked=false
checkCount=checkCount-1
alert('You have only $num left!')
}
}
//-->
</script>
<if condition="$adicondition">
<script language='Javascript'>
window.location='next.php'
</script>
<else />
</if>
</head>
<body>
$header
$navbar
<if condition="initcond">
$inmsg
<else/>
$initialised_variable
</if>
<br />
$footer
</body>
</html>


--------------- Added 1248171228 at 1248171228 ---------------

I fixed the problem somehow but still need lil clarification!

I reffered this tutorial (https://vborg.vbsupport.ru/showthread.php?t=98009) to create my custom pages.
When i removed require_once('./global.php'); from my main file, it fixed the problem.
The mod seems to work fine without that file though.
Can somebody tell me, will it cause any future problems?
And why exactly global.php was required there?
If it was for checking whether user is logged in or not then after removing global.php, my mod is still keeping non logged in users out. :confused:
then why global.php was there?

My file contains following code now :
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test');
$globaltemplates = array('test',);
//require('./global.php');
include('test/test.php');
$navbits = array();
$navbits[$parent] = 'TEST';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
if (!$vbulletin->userinfo['userid'])
{
print_no_permission();
}
else
{
eval('print_output("' . fetch_template('test') . '");');
}

Lynne
07-21-2009, 03:09 PM
In test.php you are including inc.php. What is in there? I would guess one of the other files getting included somewhere in your page is including global.php already.

Antivirus
07-21-2009, 11:53 PM
I think Lynne may be correct, IIRC this happened to be a couple months ago when i accidentally included global.php twice

nirvana43
07-22-2009, 11:51 AM
thats gr8 help guyes!!! now i understood where i'm missing it..
I did included global.php many times!!
Thanks a million again for gr8 help!!! i will fix it tomorrow morning and will let you know guyes..
thanks! :)

nirvana43
07-27-2009, 02:06 AM
Still not solved yet...
I tried everything... And now i think its not due to global.php getting called multiple times. :confused:

I turned on debug mode to see what files are getting called...
Here is debug information of page with garbage :
http://img182.imageshack.us/img182/7580/14572635.jpg

Here is debug information of page without garbage :
http://img154.imageshack.us/img154/5880/52205182.jpg

Why does it saying uncached template: orkut on garbage page and there is only php_sapi_name(): cgi-fcgi on page without garbage?????
Is that the cause of problem?

My template orkut contains following code :
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>Orkut Contacts Inviter</title>
$headinclude
</head>
<body>
<if condition="$adicondition">
<script language='Javascript'>
window.location='next.php'
</script>
<else />
</if>
$header
$navbar
<if condition="$adiinitcond">
$inviterplugs
<else/>
$contents
</if>
<br />
$footer
</body>
</html>

I tried removing java scripts from <head> section and it also didn't worked.

My orkut.php custom page contains following code :
require_once('global.php');
include('adiinviter/orkut.php');
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'orkut'); // change this depending on your filename

$globaltemplates = array('orkut');
$navbits = array();
$navbits[$parent] = 'Orkut Contacts Importer';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
if (!$vbulletin->userinfo['userid'])
{
print_no_permission();
}
else
{
eval('print_output("' . fetch_template('orkut') . '");');
}
?>
I tried commenting "include('adiinviter/orkut.php');" and writing $contents="test"; but it also didn't worked.

somebody please help me with this issue... :confused:

Lynne
07-27-2009, 02:17 AM
Try following this article in creating your custom page - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009). You have things in a different order - global called before some variables are defined. I had noticed before on my own pages that I had problems when I didn't include all the different pre-cached template groups and data arrays, even though they were empty.

nirvana43
07-27-2009, 02:26 AM
Try following this article in creating your custom page - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009). You have things in a different order - global called before some variables are defined. I had noticed before on my own pages that I had problems when I didn't include all the different pre-cached template groups and data arrays, even though they were empty.

Ohhh...
how do i change order in which templates are getting called?? I mean can you tell me where do i need to change exactly??? like in template? or in custom page code i've posted above?
because code order in both pages i've posted above is same...

I need to call my main template in vbulletin i.e. orkut rite before :
# navbar
# navbar_link
# navbar_notifications_menubit

and just after
# footer

thnaks a lot for noticing.... i followed API docs thread only while designing custom pages

Lynne
07-27-2009, 02:36 AM
I'm not talking about the order of the templates, I'm talking about how you call global.php before you define some variables that are needed in global.php (like THIS_SCRIPT and error_reporting, etc.).

nirvana43
07-27-2009, 03:06 AM
I'm not talking about the order of the templates, I'm talking about how you call global.php before you define some variables that are needed in global.php (like THIS_SCRIPT and error_reporting, etc.).

Tried everything in custom page...
but i can't find a way to get my "orkut" template executed just after "headinclude" :(
can you tell me how do i change it??

here is what i meant :
http://img269.imageshack.us/img269/4897/85275995.jpg

I also tried to remove every navbar ref from my custom page php as well as template but it aint worked..

good news is, garbage is reduced.... its showing only : 

:o

--------------- Added 1248695991 at 1248695991 ---------------

i spent 6 hours working straight on this problem and i still can't solve it!!!!!!!!
its driving me crazy!! :mad:
please please help me :confused:
its not showing any garbage in IE but i tried for 9 different browsers and there is garbage!!!!!!!!! DAMN! :mad:
should i post it under paid request??? i know its just 1 line edit work but i still couldn't find out the solution!! how much will be the charge?

NLP-er
07-27-2009, 02:52 PM
Maybe I know what it is... Let me guess - your files are encoded in UTF-8? If yes then be aware that some text editors adds utf8 header to file - it is possible that garbage which you see in output is this header. Of course you will not see it in your text editor, because it is ok according to utf-8 format.

Just save each your file in other text editor which for sure is not adding header when saving in utf8 (i.e. in notepad2 you can choose utf8 and utf8 with signature – use it without signature).

Let me know does it help :)

Almotmaiz.Net
07-27-2009, 03:23 PM
hello .. first . on the template usage. this sort templates name on alphabetical order.

so all cached template on debug mode will work with your template

second .

u need to add your custom temp. on ($globaltemplates) before u include the global.php file to get this temp. cached.

test this :-
<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'orkut');
// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('orkut');
// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
include('adiinviter/orkut.php');
// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################
if (!$vbulletin->userinfo['userid'])
{
print_no_permission();
}
$navbits = array();
$navbits[$parent] = 'Orkut Contacts Importer';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('orkut') . '");');

nirvana43
07-27-2009, 11:47 PM
Maybe I know what it is... Let me guess - your files are encoded in UTF-8? If yes then be aware that some text editors adds utf8 header to file - it is possible that garbage which you see in output is this header. Of course you will not see it in your text editor, because it is ok according to utf-8 format.

Just save each your file in other text editor which for sure is not adding header when saving in utf8 (i.e. in notepad2 you can choose utf8 and utf8 with signature ? use it without signature).

Let me know does it help :)

First of all thanks a lot for replying man... i really appreciate that...
I just tried notepad2, Ultra Edit etc.
It didn't worked..
I did exactly what you said... :o

hello .. first . on the template usage. this sort templates name on alphabetical order.

so all cached template on debug mode will work with your template

second .

u need to add your custom temp. on ($globaltemplates) before u include the global.php file to get this temp. cached.

test this :-
<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'orkut');
// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('orkut');
// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
include('adiinviter/orkut.php');
// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################
if (!$vbulletin->userinfo['userid'])
{
print_no_permission();
}
$navbits = array();
$navbits[$parent] = 'Orkut Contacts Importer';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('orkut') . '");');


I really appreciate your reply man..
It didn't worked.... I also tried ob_flush() etc.
But nothin working.. :(

NLP-er
07-28-2009, 09:28 AM
Just quick question - are you using some template cache mod?

nirvana43
07-28-2009, 11:07 AM
Just quick question - are you using some template cache mod?
nop.... i haven't installed any mod at all...

btw i'm googling a lot for this and i found few resources :
http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=hsl&q=%C3%AF%C2%BB%C2%BF&btnG=Search&meta=&aq=f&oq=

--------------- Added 1248785203 at 1248785203 ---------------

PROBLEM SOLVED!!
posting solution for future coders ;)
I opened every file in notepad and saved it with ANSI encoding!!!
The problem was due to utf-8 BOM...
here is link to read more about it : http://en.wikipedia.org/wiki/Byte-order_mark

Thanks a million Lynne, mferguson, NLP-er, R1lover, Antivirus, Almotmaiz.Net for taking your precious time for replies...

strongly appreciate that :o

NLP-er
07-28-2009, 08:24 PM
The problem was due to utf-8 BOM...

Told you :D

--------------- Added 1248857339 at 1248857339 ---------------

First of all thanks a lot for replying man... i really appreciate that...
I just tried notepad2, Ultra Edit etc.
It didn't worked..
I did exactly what you said... :o


You had to miss something - as you wrote yourself the problem was with utf-8 header - just as I told you. I have portal with php pages written in utf-8 so I know this problem and I know that without signature it works fine :)

So for others who need utf8 because of some special characters in their languages - it is not necessary to go to ANSI. You can stay with UTF-8 - just write each file without signature :)