ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

A small PHP problem

July 03, 2007 8:56am

Subscribe [4]
  • #1 / Jul 03, 2007 8:56am

    gregwood

    19 posts

    Hi there,

    I’m having trouble using a PHP function within a template. The function in question works fine as a .php file on its own (http://www.team-sangreal.co.uk/teamspeak/demo.php) but I want to use this as part of the sidebar on the main site.

    I’ve created a new template for the function, copied the code from the demo.php and enabled PHP for the template. However when I embed the template to display in the sidebar, I get the following error message:

    Fatal error: Call to a member function on a non-object in /home/team1452/public_html/admin/core/core.functions.php(629) : eval()'d code on line 36

    I don’t know anything about PHP really, so apologies if I’m being dumb, but any pointers would be appreciated.

    Cheers

  • #2 / Jul 03, 2007 9:46am

    silenz

    1651 posts

    Well, perhaps some class member variable isn’t set correctly. But if it works it’s own ... a naming conflict with an EE class ...

    I guess the actual code would be helpful. But remove the login information, in case you post it 😉

  • #3 / Jul 03, 2007 10:06am

    Derek Jones

    7561 posts

    What is the code on and around line 36 on the template containing your PHP?

  • #4 / Jul 03, 2007 10:10am

    gregwood

    19 posts

    here’s the code from the demo.php file, the one that works on its own. When copy and pasting this code into a template I obviously removed html and header tags and stuff.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <title>Teamspeak Display Demo</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <link href="http://www.team-sangreal.co.uk/css/style.css" rel="stylesheet" type="text/css">
    <?php
        if (isset($_GET['autorefresh'])) {
            $autorefresh = $_GET['autorefresh'];
        } else {
            $autorefresh = 0;
        }
        if ($autorefresh == 1) {
            echo("        <meta http-equiv=\"refresh\" content=\"10; URL=" . $_SERVER["PHP_SELF"] . "?autorefresh=1\">\n");
        }
    ?>
        </head>
        <body>
    
    <?php
        // The code between the 2 lines below turns on PHPs error handlers.
        // Uncomment it for debugging purposes, but leave commented in live
        // environments. Having your script running in a live environment with the
        // error handlers turned on, decreases your sites security as a warning may
        // reveal information used to exploit security holes in your site.
        //================== BEGIN OF ERROR REPORTING CODE ====================
        //echo("<span>Error reporting ");
        //echo("is currently on. Turn it off in live environments !</span>
    
    \n");
        //error_reporting(E_ALL);
        //ini_set("display_errors", "1");
        //ini_set("display_startup_errors", "1");
        //ini_set("ignore_repeated_errors", "0");
        //ini_set("ignore_repeated_source", "0");
        //ini_set("report_memleaks", "1");
        //ini_set("track_errors", "1");
        //ini_set("html_errors", "1");
        //ini_set("warn_plus_overloading", "1");
        //================== END OF ERROR REPORTING CODE ======================
        
        // Load the Teamspeak Display:
        require("http://www.team-sangreal.co.uk/teamspeak/teamspeakdisplay/teamspeakdisplay.php");
        
        // Get the default settings
        $settings = $teamspeakDisplay->getDefaultSettings();
        
        //================== BEGIN OF CONFIGURATION CODE ======================
        
        // Set the teamspeak server IP or Hostname below (DO NOT INCLUDE THE
        // PORT NUMBER):
        $settings["serveraddress"] = "195.20.109.16";
        
        // If your you use another port than 8767 to connect to your teamspeak
        // server using a teamspeak client, then uncomment the line below and
        // set the correct teamspeak port:
        //$settings["serverudpport"] = 8767;
        
        // If your teamspeak server uses another query port than 51234, then
        // uncomment the line below and set the teamspeak query port of your
        // server (look in the server.ini of your teamspeak server for this
        // portnumber):
        //$settings["serverqueryport"] = 51234;
        
        // If you want to limit the display to only one channel including it's
        // players and subchannels, uncomment the following line and set the
        // exact name of the channel. This feature is case-sensitive!
        //$settings["limitchannel"] = "";
        
        // If your teamspeak server uses another set of forbidden nickname
        // characters than "()[]{}" (look in your server.ini for this setting),
        // then uncomment the following line and set the correct set of
        // forbidden nickname characters:
        //$settings["forbiddennicknamechars"] = "()[]{}";
        
        //================== END OF CONFIGURATION CODE ========================
        
        // Is the script improperly configured?
        if ($settings["serveraddress"] == "") { die("You need to configure this script as described inside the CONFIGURATION CODE block in " . $_SERVER["PHP_SELF"] . "
    \n"); }
        
        // Display the Teamspeak server
        $teamspeakDisplay->displayTeamspeakEx($settings);
        
    ?>
    
    </body>
    
    </html>

    I’ve noticed that this code links or ‘requires’ another PHP function, where the functionality happens, but the document’s quite large. You can download it and open it in your text editor to save me making this thread three miles long (http://www.team-sangreal.co.uk/teamspeak/teamspeakdisplay/teamspeakdisplay.php - save link as)

    Cheers!

  • #5 / Jul 03, 2007 10:18am

    gregwood

    19 posts

    What is the code on and around line 36 on the template containing your PHP?

    lines 32 - 36 in the template:

    // Load the Teamspeak Display:
        require("http://www.team-sangreal.co.uk/teamspeak/teamspeakdisplay/teamspeakdisplay.php");
        
        // Get the default settings
        $settings = $teamspeakDisplay->getDefaultSettings();
  • #6 / Jul 03, 2007 10:40am

    Derek Jones

    7561 posts

    And where is the $teamspeakDisplay object instantiated?

  • #7 / Jul 03, 2007 11:00am

    silenz

    1651 posts

    I bet if you change this

    require("http://www.team-sangreal.co.uk/teamspeak/teamspeakdisplay/teamspeakdisplay.php");

    to the server path

    require("/your/path/to/teamspeak/teamspeakdisplay/teamspeakdisplay.php");

    it will work.

    If you don’t have the path at hand look it up under
    CP Home ›  Admin ›  Weblog Administration ›  File Upload Preferences > Main Upload Directory

  • #8 / Jul 03, 2007 11:06am

    Derek Jones

    7561 posts

    Due to the way eval() works (which is how PHP is parsed in your templates), there are sometimes some interactions that have to be accounted for.  Variable scope is one, of course, and I would not have expected URL wrappers to affect it, but this comment on the PHP docs makes sense, and the combination with eval() causes the object to be locally scoped to the teamspeakdisplay.php file and not available to the template.

    It’s possible that global $teamspeakDisplay; immediately after the require in your template would allow it to work, but silenz is absolutely right, you shouldn’t be using URL wrappers if the file is on your own server.

  • #9 / Jul 03, 2007 3:21pm

    gregwood

    19 posts

    thanks guys I’ll give these a shot then get back to you

  • #10 / Jul 03, 2007 5:43pm

    gregwood

    19 posts

    I bet if you change this

    require("http://www.team-sangreal.co.uk/teamspeak/teamspeakdisplay/teamspeakdisplay.php");

    to the server path

    require("/your/path/to/teamspeak/teamspeakdisplay/teamspeakdisplay.php");

    it will work.

    If you don’t have the path at hand look it up under
    CP Home ›  Admin ›  Weblog Administration ›  File Upload Preferences > Main Upload Directory

    perfect, thanks a lot

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases