selva24
selva24

Reputation: 11

URL file access in php

I am trying to include my header,footer and sidebar files like this,

include($str_url.'header.php');
include($str_url.'sidebar.php');
include($str_url.'footer.php');

i have defined $str_url = "http://www.example.com/"; in my constant file,

But is not working in my server. how can i fix it?

Please help me.

Thanks.

Upvotes: 0

Views: 130

Answers (3)

PtPazuzu
PtPazuzu

Reputation: 2537

You most probably don't want to include URLs into your main php file, but the local .php-files. include ('/path/to/a.php'); instead of include ('http://url/to/a.php');

(source: http://php.net/manual/en/function.include.php)

Upvotes: 5

raver
raver

Reputation: 129

You should never include files via an absolut URL, because you will not be including the actual code, but the result of it. Instead use relative paths or server paths (/home/user/public_html) Easiest way would be via relative paths. For example, if you have index.php and header.php in the same folder, you can just use: include('header.php'); If the files, are in another folder, for example you have header.php in an 'includes' folder, than you would use in your index.php: include('includes/header.php');

Upvotes: 1

hadvig
hadvig

Reputation: 1106

You probably need modify php.ini allow_url_include = On.

But better never include files via http.

Upvotes: 2

Related Questions