View Full Version : Add PHP code in navbar template
dabvastur
10-05-2014, 09:27 PM
Dears members of this community
I need help. I tried load php code in navbar template directly inserting code in template, to see that did not work, I started investigating.
When he was investigating, has led me to do the following:
https://vborg.vbsupport.ru/external/2014/10/17.png
and this is content of mostrarusers.php
<?php
require_once("samp_query.php");
define(SERVER_IP, "188.165.129.157");
define(SERVER_PORT, 7777);
$rQuery = new QueryServer(SERVER_IP, SERVER_PORT);
$ainfo = $rQuery->GetInfo();
$aServerRules = $rQuery->GetRules();
$aBasicPlayer = $rQuery->GetPlayers();
$aTotalPlayers = $rQuery->GetDetailedPlayers();
$playerlist = $aTotalPlayers;
echo "' . $aInformation['Players'] . '";
$rQuery->Close( );
?>
Regards and thanks
Try using hook location parse_templates instead.
dabvastur
10-05-2014, 09:59 PM
I tried, but not work.
I forgot mention that when I do, the forum shows white.
Thanks.
Do you also have a file called samp_query.php on your server? The code you posted tries to include that file. It looks like it's trying to get it from the same directory as the main script, so you might have to change the line in mostrarusers.php to something like:
require_once($_SERVER['DOCUMENT_ROOT'] . "/foro/samp_query.php");
dabvastur
10-06-2014, 12:44 PM
I upload samp_query.php in /forum/ but I don't add [document root] in requiere_once on mostrarusers.php.
I will comment when I get home.
Thanks.
I upload samp_query.php in /forum/ ...
That could be the right place, I'm not sure. If you add the path as above, then you'd want it in /foro, of course.
tbworld
10-06-2014, 05:47 PM
@Kh99, I do not want to interfere with your operation here, but this looks like "team speak" code (if you wanted to know) -- not that it directly relates to the problem being resolved. I leave him in your capable hands. :)
@Kh99, I do not want to interfere with your operation here, but this looks like "team speak" code (if you wanted to know) -- not that it directly relates to the problem being resolved. I leave him in your capable hands. :)
No, please help if you can.
dabvastur
10-06-2014, 09:30 PM
Hi,
I tried was said by @KH99 but does not work, the forum show white as before.
Content of mostrarusers.php
<?php
require_once("samp_query.php");
define(SERVER_IP, "188.165.129.157");
define(SERVER_PORT, 7777);
$rQuery = new QueryServer(SERVER_IP, SERVER_PORT);
$ainfo = $rQuery->GetInfo();
$aServerRules = $rQuery->GetRules();
$aBasicPlayer = $rQuery->GetPlayers();
$aTotalPlayers = $rQuery->GetDetailedPlayers();
$playerlist = $aTotalPlayers;
echo "' . $ainfo['Players'] . '";
$rQuery->Close( );
?>
Regards and thanks
dabvastur
10-08-2014, 04:04 PM
Not is my intention pressure for obtain answer more faster or double post, but please don't forget help me with my problem. Thanks.
Hmm...I don't see anything wrong with the code offhand. The only thing that I can think of is that if the require_once("samp_query.php") fails I think it would end the script. I also don't know what's in samp_query.php that might cause an error.
tbworld
10-08-2014, 11:50 PM
1. Check your PHP log to start with and make sure you do not have an error listed.
2. Disable the plugin and see if the "white" screen is resolved.
If the above two checks are okay, then enable the plugin and load the page on the default style. If the page loads, then most likely you have a coding issue in your modified template. At least that is where I would start.
I do not see anything wrong with what @Kh99 presented (as I would have expected), I am not saying your routine will work as I would have to review the team speak code.
Resolve the white screen problem and then you can go from there. There is no method we can resolve the white screen issue from here, all we can do is give you suggestions.
dabvastur
10-09-2014, 11:00 AM
When I load script the forum show white in any theme.
The samp_query.php is a good script, originally, tested by various communities of the game San Andreas MultiPlayer and this not contain any bug.
So are you saying that if you enable that plugin you get a white screen, but if you disable it the white screen goes away? In that case it must be that something in that code is causing an error. If you can look at your php error log as tbworld suggests, that might show you what the error is. You could also temporarily enable displaying of errors, if you've turned that off.
One thing, the echo line should probably be like this:
echo $ainfo['Players'];
but I don't think that would cause an error, it would just print something different than you intended.
tbworld
10-09-2014, 05:08 PM
Good catch @kh99
echo "' . $ainfo['Players'] . '";
Will absolutely cause an encoding error on the page, which most likely lead to a white page.
:)
--------------- Added 09 Oct 2014 at 11:27 ---------------
When I load script the forum show white in any theme.
The samp_query.php is a good script, originally, tested by various communities of the game San Andreas MultiPlayer and this not contain any bug.
@dabvastur:
This is not the current "samp" script, that is floating around and in that format it would have never worked. It would be helpful -- in the future -- if you provided us enough details so we could wrap our heads around what you are trying to do. :)
The best we can attempt to do (without knowing the application), is to fix what you have given us so it will run / interpret under PHP in connection with vbulletin.
dabvastur
10-12-2014, 02:13 AM
I try modifying echo line and let you know when I have the time for this.
Thanks you both for all help.
tbworld
10-12-2014, 02:29 AM
I did not do anything, it was all @kh99, but thanks for thanking us. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.