failed to open stream

Problems with the Windows version of XAMPP, questions, comments, and anything related.

failed to open stream

Postby viajante » 23. August 2007 14:41

Warning: include(.php) [function.include]: failed to open stream: No such file or directory in D:\xampp\htdocs\silencor\geral\index.php on line 14

Warning: include() [function.include]: Failed opening '.php' for inclusion (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\silencor\geral\index.php on line 14

What could be wrong?

The file exist, in this case i want to include in the index.php the file index1.php and footer.php but it gives me the errors above.
The database is in the place and is working in the phpmyadmin, so i don´t understand what am i missing, or doing wrong.
The code i used to in the index.php for the include function was this:

echo"

<tr>

<td>";include("$currentpage.php");echo"</td></tr>
<tr><td>";include("footer.php");echo"</td>
</tr>
";


Any help?
viajante
 
Posts: 6
Joined: 24. January 2007 22:09

Postby Wiedmann » 23. August 2007 14:45

Warning: include() [function.include]: Failed opening '.php' for inclusion (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\silencor\geral\index.php on line 14
What could be wrong?

There is no file with the name ".php" in the directory "D:\xampp\htdocs\silencor\geral":
Code: Select all
<td>";include("$currentpage.php");echo"</td></tr>

The variable $currentpage have no value or is not defined.

(Please use a better error_reporting level during writing/testing your scripts.)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby viajante » 23. August 2007 15:22

The variable "$currentpage" is defined in the links of the webapage like this:
<a href=\"index.php?lang=$lang&currentpage=index1\" class=\"current\">$res_campo[11]</a>
The variable "$lang" is to choose the language in the database.
There are ".php" files in the directory "D:\xampp\htdocs\silencor\geral" like the "index1.php" to be included in the "index.php"
I don´t see what am i missing or doing wrong.
I´m sorry about my english :oops:
viajante
 
Posts: 6
Joined: 24. January 2007 22:09

Postby Wiedmann » 23. August 2007 15:28

The variable "$currentpage" is defined in the links of the webapage like this:

A link does not define a variable. Maybe you mean $_GET['currentpage'] and not $currentpage.

There are ".php" files in the directory "D:\xampp\htdocs\silencor\geral" like the "index1.php"

Maybe there are "*.php" files in this directory. But in the above post from you, PHP tries to open exact the filename ".php". And not "index.php" or similar (*.php).

I don´t see what am i missing or doing wrong.

You have not read the PHP manual how these things work ;-)
(chapter: using external variables)

BTW:
It's dangerous using includes in this way...
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby viajante » 23. August 2007 15:34

I´m gonna read better the chapter and try to solve these problems.

And what do you mean by "It's dangerous using includes in this way..."?
In what way would be more correct?
viajante
 
Posts: 6
Joined: 24. January 2007 22:09

Postby viajante » 28. August 2007 22:03

Hello again

I didn´t find anything wrong on my programing and with the instalation of apache, php and mysql separately it works fine, i didn´t find what is wrong with xampp so i start to search for another pack of php,apache and mysql instalation and i find appserv just to compare if would happen the same thing.
I installed it with no need of configuration just the root password and when i add the user that i use for the database in mysql my webpage starts to work properly without any problems.
So my conclusion is that there is something in xampp configuration, that i didin´t find yet, that prevents my webpage to work properly.
I prefer xampp really but for now i had no choice but stay with appserv because it works and my webpage works perfectly on my local machine.
I´m gonna try to fing what configuration in xampp is missing or wrong and if i find it i will post something.
But if you find it first i would be very pleased if you let me know.
Thank you again :)
viajante
 
Posts: 6
Joined: 24. January 2007 22:09

Postby viajante » 21. January 2008 18:04

Hi

I thought that maybe someone could find a solution for this problem but it seems that everything is just like the same as before :(

My programing works with appserv but doesn´t work with xampp so it´s not my code it´s something wrong with xampp configuration, and i can´t find what it is wrong.
Anyone had the same problem???
If yes what was the solution?
viajante
 
Posts: 6
Joined: 24. January 2007 22:09

Postby KallistaAEnvarou » 25. January 2008 00:24

What Wiedmann meant was that there's no file called D:\xampp\htdocs\silencor\geral\.php.

In order to get a variable from the URL, you need to use $_GET[$variable_name]. So, for example, you'd use $_GET['lang'] to get the language variable, such as $lang=$_GET['lang'].

Also, to get the file the way you want would mean that anybody can get access to any .php file, even if that file is in your admin folder and you don't want just anybody to get access to it. As well, if your file doesn't exist, you're going to get errors like that.

I personally think that the best way to do something like this, if you don't want them to know that you're using PHP, is to configure your .htaccess file to say:

Code: Select all
RewriteEngine On
RewriteRule .* index.php


Then, when you have people put in a URL, they can put something like:

http://site.com/file?lang=english.

Then, in your index.php file, do:

$question=strstr($_SERVER['REQUEST_URI'],'?');
$name=str_replace($question,"",$localhost);
$filename=strtolower(substr($name,1));
$language=$_GET[lang]uage;

This way, when you parse the URL, you get the name of the file. So, for instance:

http://website.com/blah?language=english

would return $filename='blah' and $language='english'.

Obviously you wouldn't be able to access http://website.com/index because then you'd have an infinite loop. So...You'd have to do something like:

Code: Select all
if(!$filename)
{
   $include='indexpage';
}
elseif(file_exists($filename)  && $filename!='index')
{
   $include='$filename';
}
else
{
   $include='/path/to/error/page';
}
include($include);


This way, as well, if somebody tries to determine the existence of a given file via http://validator.w3.org, he or she won't be able to determine the 404 error code.

Note: If you include any JavaScript, CSS, or image files, you'll need to test $filename for the presence of the extensions and then use header('application/javascript'), header('text/plain'), or header('image/' . $imagetype) [where $imagtype is the image extension] and then echo the file contents of the JS or CSS files, and then use image functions for the image files.

This type of code is especially convenient for hiding JavaScript, CSS, and image direct-link views (such as http://website.com/javascript.js or http://website.com/image.png) when you research how to do that kind of coding. I do it with my site, so if you want to learn how, just PM me, and I'll tell ya.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 139 guests