TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,913
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 592
  • Total: 593
  • @rjen

Custom php code in a php block

Started by dataspiller, November 30, 2009, 12:28:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dataspiller

This has got me baffled...

I have written a php script that my friend will be using to activate different flash files - you can see it in action here: http://nahroc.com/radiotest.php?debug=true

this radiotest.php file is very simple: all it contains is


<?php
eval("include (\"scripts/radionet/radio.php\");");
?>




And it is located in the main website folder (same as index.php for smf).

The script and data files reside in scripts/radionet/....

It is working perfectly.


Now - I want to put that in a block on the front page.

So I make a new block, specified as a phpscript block.

I enter in for the php code:


include ("scripts/radionet/radio.php");



And instead of working, I get this error in the block:

Fatal error: Call to a member function addChild() on a non-object in /home/nahrocc/public_html/scripts/radionet/radio.php on line 205

The line giving the error is related to simplexml - its not loading the xml files.


Question:

Why does it work in a simple PHP file, yet not in a php block located on the front page of the site? - both are located in exactly the same folder..

any ideas??

it almost seems like the paths get mixed up, but even spelling out exactly where all the datafiles are for the script didn't fix it.


data

JPDeni

QuoteWhy does it work in a simple PHP file, yet not in a php block located on the front page of the site? - both are located in exactly the same folder..

Because the folder that the file is in which evaluates the block is the /Sources/ folder, so that's where the file "thinks" it is.

dataspiller

k - that answers where it is evaluated in...

Assuming that the sources folder is in

public_html/sources/

and my script files are in

public_html/scripts/radionet/


then specifying the path as

../scripts/radionet/radios.xml

should tell the script where to access the file... which it didn't.

I had it spelled out exactly where it is on the server - the full /home/<username>/public_html/scripts/radionet/radios.xml

Still didn't work.

Any other ideas? been working with this for a couple weeks now - getting ready to just drop the idea of using xml files and switch over to mysql database, which would require coding an entery form...


Thanks for the help so far,

data

JPDeni

I would try the external file in the /Sources/ directory. Or are there supplementary files in the /scripts/radionet/ directory?

I'm assuming that the function addChild() is in the radionet.php file. Yes? It's a little hard to work it out without knowing all the details.

dataspiller

Function addchild() is part of simplexml's class - it adds an xml node to a parent node.


In side radio.php I have these lines:


echo "Path: " . $path_to_status_file;
    $tmp1xml = file_get_contents($path_to_status_file);
    echo "File contents: " . $tmp1xml;
    $sxml = simplexml_load_string($tmp1xml);

The echo statements are there for debugging - When i run the script through a tiny portal block, the variable $path_to_status file is empty, thus file_get_contents can't read in the xml data, causing simplexml to fail.

$path_to_status_file is declared at the start of radio.php, and as this bit of code is in a function I do have "global $path_to_status_file" at the start of the function.
The only files that that the script accesses in side of radionet are 2 xml files - radios.xml and status.xml.


Break through, while typing up the above... Passing $path_to_status_file to the function via paramater instead of
using global $path_to_status_file fixed the issue....


eval can't handle the global statement or am I missing some thing there...

Data

JPDeni

QuotePassing $path_to_status_file to the function via paramater instead of
using global $path_to_status_file fixed the issue...

Cool! Whatever works. :)

This website is proudly hosted on Crocweb Cloud Website Hosting.