Confused by a PHP error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
erikas_boy
Forum Newbie
Posts: 3
Joined: Tue Mar 02, 2010 12:35 pm

Confused by a PHP error

Post by erikas_boy »

Hello,
Okay, I've done a heap of googling, trying to chase down the solution, but I'm out of ideas, so I'm bringing it to the pros.

I've got a Joomla! CMS installation with a Wordpress install running with it (they are seperate, though). I've got a Joomla! Module that grabs the most recent post from the Wordpress blog and posts a snippet of it with a link to it on the Joomla! mainpage. I realize that immediately people will be saying "Check both of their support forums", but I honestly think this is just a problem with the PHP code.

So you can see what is going wrong here:
http://www.orosend.com/joomla/ bottom right "recent blog post" column.

The error is:
Warning: file_get_contents(/kunden/homepages/39/d282264226/htdocs/?getmylink=15) [function.file-get-contents]: failed to open stream: No such file or directory in /homepages/39/d282264226/htdocs/joomla/modules/mod_recentwordpressposts/mod_recentwordpressposts.php on line 474

The code on line 474 is:
$link = file_get_contents($_SERVER['DOCUMENT_ROOT']."/joomla/blog/?getmylink=".$id);

The error is, of course, correct. That file does not exist in the directory it is listing. So I know that somewhere in the code, it's saying to look in the wrong directory, but I cannot figure out where.

Damn, I feel like such a noob.

Any help is much appreciated, I can provide more details as needed.
Thanks,
Chris

I realize I could probably just get the host ot turn off errors, but I would really like to get this module working.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Confused by a PHP error

Post by AbraCadaver »

It's the line you posted. Do you have a ?getmylink=15 file in any directory?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: Confused by a PHP error

Post by davex »

Hi,

You're attempting to open the file as a local file on the filesystem. In this case you're also trying to open a file called ?getmylink=15.

Even if you opened the correct (probably index.php) file in this method you would get the PHP source code. You need to get PHP to execute it first to generate the code and also to have getmylink passed as a variable.

I would suggest simply changing the link from /local/file/path/?getmylink=15 to http://www.full.host/http/path/?getmylink=15

Which will get the page via HTTP with Apache/PHP parsing the code first.

Regards,

Dave.
erikas_boy
Forum Newbie
Posts: 3
Joined: Tue Mar 02, 2010 12:35 pm

Re: Confused by a PHP error

Post by erikas_boy »

?getmylink=15 is actually calling on another PHP script (this one imbedded in Wordpress as a widget) which generates an absolute link to the most recent blog post. So yes, technically it exists, it would be generated when called on. It would be found in htdocs/joomla/blog/

If I understand correctly, by using that widget script, the PHP would then get executed.

When I change the line to the absolute path, I get the usual "URL file-access is disabled in the server configuration in..." and "no wrapper" errors.

Sorry, I'm realizing that I left out some of the question when I posted yesterday (I'm not a programmer, in case this hadn't become apparent, my brain gets foggy trying to figure this stuff out).

The code is actually working, you'll note the blog post that I'm trying to get is there, it's just preceeded by the error, I have no idea why. Also, why is it looking for the file or directory in /htdocs/joomla/modules/mod_recentwordpressposts/mod_recentwordpressposts.php when I specifically tell it in the code that the file is at /htdocs/joomla/blog/ ?

Thanks for the help so far.
Chris
erikas_boy
Forum Newbie
Posts: 3
Joined: Tue Mar 02, 2010 12:35 pm

Re: Confused by a PHP error

Post by erikas_boy »

Just in case, this is the PHP in the Wordpress blog that is being called by "getmylink"

<?php
function getmylink () {
$url = get_pagenum_link();
$req = $_REQUEST['getmylink'];
if($req != ""){
echo get_permalink($req);
die;
}
}
add_action("parse_request", "getmylink");
?>

Thanks again!
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: Confused by a PHP error

Post by davex »

Hi,

If you do file_get_contents() on a local path I'm pretty sure you will get just that - the contents of the file, in this case some PHP code NOT the processed HTML output.

If URL opening is disabled then I'm not sure how to proceed. I am also not sure how/why a post is showing underneath though I notice it links back to Joomla - is it definately coming from the wordpress installation?

How about trying a:

Code: Select all

<?php
$output="";
exec("php /path/to/your/script.php",$output);
// output is now an array of lines which were output
foreach($output as $out_line) echo $out_line."<br />";
You will need to modify your script to take a command-line argument but that should work.

Regards,

Dave.
Post Reply