Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Including a PHP file in a page or article  (Read 6297 times)

rec9140

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Including a PHP file in a page or article
« on: November 20, 2007, 10:23:06 PM »

I have some content which pulls some data from another site via a custom PHP file, at present under my MediaWiki setup I use an extension which pulls this PHP file into the articles on the wiki with no issue.

I've tried a few ways like includes etc., but the only thing that seems to work for sNewsMU is iframe.

It does include the content, but....

On the page that this is used on then the "edit" line disappears, as soon as I take the iframe out all is well.

Is there a better way to include a PHP file, as its part of the content for the page, its dynamic data that is updated each time a user views it.
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: Including a PHP file in a page or article
« Reply #1 on: November 20, 2007, 11:21:57 PM »

There is [ include ] tag for including output from external php files directly in pages/articles content. Check the doc-s on site and forum.
Logged

rec9140

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Re: Including a PHP file in a page or article
« Reply #2 on: November 21, 2007, 12:06:00 AM »

There is [ include ] tag for including output from external php files directly in pages/articles content. Check the doc-s on site and forum.

Gives :
Include Error: Forbidden file name

I have line:

[include] /wash_co_hear.php[/include]

Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Including a PHP file in a page or article
« Reply #3 on: November 21, 2007, 01:47:38 AM »

When you use the [include] tag, you typically need to use another file format than .php. Try saving your php file --the one you want to include-- as .txt and include it instead.
Quote
[include]/wash_co_hear.txt[/include]
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: Including a PHP file in a page or article
« Reply #4 on: November 21, 2007, 07:19:33 AM »

My fault, might be so with 1.6 ;)

Logged

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
Re: Including a PHP file in a page or article
« Reply #5 on: November 21, 2007, 10:46:37 AM »

It should work, but may be you have to alter some system variables in snews_mu.php.

Look at the end of the language variables and find the following

Code: [Select]
$l['file_include_extensions'] = 'php,txt,inc,htm,html'; // list of file types available for inclusion routine
$l['allowed_files'] = 'php,htm,html,txt,inc,css,js,swf'; // list of file types available for upload/file list routine

With these variables you can set the files types that you can include and upload.
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

rec9140

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Re: Including a PHP file in a page or article
« Reply #6 on: November 21, 2007, 01:44:00 PM »

It should work, but may be you have to alter some system variables in snews_mu.php.

Look at the end of the language variables and find the following

Code: [Select]
$l['file_include_extensions'] = 'php,txt,inc,htm,html'; // list of file types available for inclusion routine
$l['allowed_files'] = 'php,htm,html,txt,inc,css,js,swf'; // list of file types available for upload/file list routine

With these variables you can set the files types that you can include and upload.


This is whats present:

Code: [Select]
$l['file_include_extensions'] = 'php,txt,inc,htm,html'; // list of file types available for inclusion routine
$l['allowed_files'] = 'php,htm,html,txt,inc,css,js,swf'; // list of file types available for upload/file list routine
$l['allowed_images'] = 'gif,jpg,jpeg,png'; // list of image types available for upload/file list routine


I tried all of them... same error. "Forbidden File Type"

Logged

rec9140

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Re: Including a PHP file in a page or article
« Reply #7 on: November 21, 2007, 06:55:20 PM »

Quote
[include] /wash_co_hear.php[/include]

I'm curious about the / in there.  Might be messing things up for you.  I tried it on my local install and had no problems without the /, when I tried with the /, it just said it couldn't find the file.

Using .php extensions shouldn't be a problem either.

And FWIW, this is the same function as used in the single user sNews.  Nothing was modified for file inclusion.

The / is there as the original file is in the root public_html directory, I moved a copy into the snewsMU directory to be sure, same thing. Forbidden File Type.

« Last Edit: November 21, 2007, 07:05:21 PM by bakercad »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Including a PHP file in a page or article
« Reply #8 on: November 21, 2007, 08:01:25 PM »

It's got to be a path problem.
Does the file have a function in it that you want executed? If so, why not try inserting the actual function-name into something. This approach might need to use Philmoz's Function Insert mod (a small mod)... which you use with a button in the Edit buttons group under the textarea to generate function insert tags... and the file itself will need to be included at the top of the index.php file (after the include for the engine file). It does work well for me.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: Including a PHP file in a page or article
« Reply #9 on: November 21, 2007, 09:37:54 PM »

Hello everybody.

Try include dot before /
[include]./wash_co_hear.php[/include]
Logged
Need a Job on Europe. Linkdin - Facebook / Group

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: Including a PHP file in a page or article
« Reply #10 on: November 21, 2007, 10:03:06 PM »

If error was include specific then probably it's falling over call to php file_exists() function. Check php doc-s for related issues with things like safe mode and proper paths for different environments. Don't know for sure, but is worth checking IMHO.
Logged

rec9140

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Re: Including a PHP file in a page or article
« Reply #11 on: November 22, 2007, 05:50:35 PM »

Well part of the problem is corrected by itself...

I created a blank test page to play with , and at least the Forbidden File error has stopped. Don't know why.

BUT it still will not display all the contents of the php file, I get one HR line from the file thats it. Additionally any content after this include is missing as is the addded by user edit line at the bottom.

I figure theres a code conflict somewhere. Possibly variable names?

I've included an example of the code, sanitized of names of links and stuff, its crude, it may not be the best, but it works.

code snippet removed
« Last Edit: November 23, 2007, 03:03:38 PM by rec9140 »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Including a PHP file in a page or article
« Reply #12 on: November 23, 2007, 12:18:38 AM »

afaik, when including php or html files, restrict yourself to only including the contents between <body>...</body> tags, and from your test case results I'd say that you probably should not use short php tags ( e.g. <?) but long php tags instead (e.g. <?php). At least if you're including stuff within the context of an sNews site/page/article.

Plus I still think that the easiest way to include php code within an article is to roll it into a txt file, but what do I know. ;)
Logged

rec9140

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Re: Including a PHP file in a page or article
« Reply #13 on: November 23, 2007, 03:08:30 PM »

The problem has been resolved by moving the other program into the same directory as Snews.


There is some type of an issue with paths and the include statement, but if everything is in the same directory all is well.



Logged

pearjam

  • Full Member
  • ***
  • Karma: 14
  • Posts: 152
Re: Including a PHP file in a page or article
« Reply #14 on: August 04, 2010, 12:08:16 AM »


I may be 3 years to late...   8)

I have my site files in different directories, and had an issue getting an [ included ] .php file to display everything....

Through trial and error, aka 'the hard way', I narrowed down to a path issue.

Although I can't explain it well, I believe it has something to do with mod rewrite, and the way the file is called (included) from within the cms. It wasn't able to resolve the path.

Switching what it sees as the path around, the file was able to display...

At the top of the included php file, I placed:
Code: [Select]
<base href="http://domain.com/gallery/my-jeep/" />(the directory where the included file resides)

...at the bottom of the file I placed:
Code: [Select]
<base href="http://domain.com/" />(switching back to the base href sNews wants)

It's kind of similar to holding WP's loop in a tmp cache.

So the way sNews is seeing it...

base=domain.com
...sNews generated content....
...sNews generated content....
...sNews generated content....
base=domain.com//path/to/file/
...included file content....
base=domain.com/
...sNews generated content....
...sNews generated content....
...sNews generated content....


I found this thread while researching a different problem, and there's a chance this may help someone else... so I'm posting it, and I'll keep looking for the answer to the problem I currently have ... :)


Logged
....I must go, for I am their leader - and they have gone.