Help with PHP Include


#1

Ok apparently dreamhost has disabled using includes the way i’ve always used them, so my whole site (www.esemdesign.com) is down and im having a hard time fixing the tangled web of includes throughout my page. can anyone help me out?


#2

how do you ususally include? what include method isn’t working?

I usually require/include like so:

require ($_SERVER[‘DOCUMENT_ROOT’].’/code/framework.inc’);
or of course
include ($_SERVER[‘DOCUMENT_ROOT’].’/code/framework.inc’);


#3

Dreamhost allows php includes in general, but has disabled the use of allow_url_fopen for security reasons.

If your site uses this function, you can (and should!) rewrite the code to use curl to fetch the offsite content, and make sure local files are included using paths instead of urls.

There is a lot of discussion on this in these forums, and on the Dreamhost wiki. If you have an example of specific code that is now broken and would like for us to look at it, please include that code in a post - otherwise, any help that we might offer would only be guessing :wink:

From looking at your site, the problem appears to be one of properly addressing your mysql server. If you are trying to “include” your connection info, it appears that it is being “read”, but that the info is not correct for your server (per the error message). This makes me think your problem is not with the include, but with your connection settings.

–rlparker


#4
<? include $_SERVER['DOCUMENT_ROOT']."/photoshop/tutorials/skycaptain/tuthits.php" ?>

that usually includes my script to add to the view count of that particular tutorial, the code for that script below

<?php $count_my_page = ("views.txt"); $hits = file($count_my_page); $fp = fopen($count_my_page , "r"); print $hits[0]; fclose($fp); ?>

(i know flat files may not be the best but im still recoding my site)

and the error i get is

Warning: file(views.txt) [function.file]: failed to open stream: No such file or directory in /home/.paxil/ehsehm/esemdesign.com/photoshop/tutorials/skycaptain/tuthits.php on line 3

Appreciate all the help i get


#5

I have had to use curl instead of url_fopen myself. kind of a pain but it works.


#6

nvm i got it, thank you all. im sure ill run into more than a few problems in the near future lol


#7

Maybe you could offer a bit of help with my fopen dilemma???

Here is my code:

load_template_colors($events[“path”]."/tmp".$tempfolder."/settings.xml",$data,$colors,$style);
$preview_xml = “\n”;
$preview_xml.= “”.htmlspecialchars(stripslashes($values[“title”]))."\n";
$preview_xml.= “”.htmlspecialchars(stripslashes($values[“description”]))."\n";
$preview_xml.= “”.htmlspecialchars(stripslashes($events[“url”]."/".$values[“folder”]))."\n";
$preview_xml.= “”.htmlspecialchars(extract_location($values[“country”],$values[“state”],$values[“city”]))."\n";
$preview_xml.= “”;

$f = fopen($events[“path”]."/tmp".$tempfolder."/preview.xml",“w”);
fwrite($f,$preview_xml);
fclose($f);

Since the allow_url_fopen is disabled, I am getting the following error:
Warning: file(): URL file-access is disabled in the server configuration in …

The code is used in a preview button function, which opens a _blank target, and I have verified that all variables are being passed correctly.

I’m not sure how to convert the fopen code to cURL in order to see if it allows me to pop-up a preview window. Is this enough information to evaluate?

Thanks,
Adam


#8

Well, it’s a start, but if I’m reading your code correctly (and I might not be, 'cause it’s late here :wink: ), I believe that the error is generated as a result of the following code:

$f = fopen($events[“path”]."/tmp".$tempfolder."/preview.xml",“w”);
fwrite($f,$preview_xml);

and, from that, I suspect the problem lies in the code that assigns $events, which you did not include. Basically, it looks like $events[“path”]."/tmp".$tempfolder." evaluates to a (partial) url, and the code that sets that up is not here.

You may not need to “cURL” it at all, if you can modify the appropriate strings/variables to produce a path on the server rather than an “http://” url. I’d start looking at the problem from that standpoint, and using that approach, before trying to “cURL” the whole thing, but that’s just me. There are others far more expert at PHP than me on the forum, and maybe one of them will have a better suggestion.

It also helps greatly if you provide the whole, rather than a truncated, error message - without the whole error message, we are kinda “debugging” in the dark. :wink:

–rlparker