0

I have path like this : "C:/xampp/htdocs/root/my-test/defined-values.php"

that I want to include like this in my index.php

if (is_readable($path)) {
    require($path);    
}

and it just simple, it doesn't work. I have die('test') at the top of defined-values.php file, and it is not being picked at all. PHP it doesn't include this file. Require path doesn't return false. So it is working/

I have setup vhosts, everything, and I'm trying to access index file from url : http://my-test.ttt

It was working before on older version of xampp, and with php 5.3.

What could be the problem? Any idea? It is definitely something wrong with PHP.ini file

user147
  • 1,312
  • 5
  • 22
  • 41

2 Answers2

0

Try using a relative path. It's a better solution, this way you can move your solution to another server without changing the absolute path.

To get the current path use dirname(__FILE__)
So your code would look like

$path = dirname(__FILE__);
require_once($path.'/otherFile.php');

If the file to require was a directory below the current file you can use dirname() again:

$path = dirname(dirname(__FILE__));
Boundless
  • 2,444
  • 2
  • 25
  • 40
  • hi try that already, and it doesn't work, when I print our path, and paste it in browser url(C:\xampp\htdocs\root\my-test\defined-values.php), I could see plain text of my php file. so path is fine, but it is not included. maybe something with apache settings? Trying to google it right now, but without any luck. – user147 Jun 05 '13 at 11:41
  • Alright, if you're getting the file but it isn't executing it's due to you not running it on a 'server'. Read my reply here: http://stackoverflow.com/questions/14803348/wampserver-page-is-displaying-differently-depending-on-how-i-visit-it/14803428#14803428 – Boundless Jun 05 '13 at 11:54
  • hi, I know that, I have just use path in url to make sure that it is correct, and it is correct. I'm not running php file like that. :) – user147 Jun 05 '13 at 11:58
  • Alright, so your path starts with either `localhost` or `127.0.0.1` ? – Boundless Jun 05 '13 at 12:07
  • @Bondless, hi my url is : http://my-test.ttt, and my path that I'm trying to include is : C:\xampp\htdocs\root\my-test\defined-values.php and the path is ok, but it is not working, like it is not being included. There is no error, nothing. – user147 Jun 05 '13 at 12:10
  • Don't do an include that starts with `c:` your include should be either relative to your current path (as in my answer) or should start with `localhost` or `127.0.0.1` (this will be your xampp directory) Look at my comment in the link above one more time. – Boundless Jun 05 '13 at 12:13
  • hi, sorry, I tried that, and no luck, I tried with localhost, 127.0.0.1 and with my-test.ttt and nothing. Same problem. – user147 Jun 05 '13 at 12:22
  • hi, it is include function problem. http://stackoverflow.com/questions/16234545/include-function-in-php-behaves-differently-on-xampp-update but no solution for this – user147 Jun 05 '13 at 14:00
0

Problem was with include path, and short open tag, short_open_tag = On, and include path should be set like this : include_path = ".;C:\xampp\php\PEAR" for windows.

user147
  • 1,312
  • 5
  • 22
  • 41