Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 117,270 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,810 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



include files

 
Reply to this topicStart new topic

include files

chili5
post 9 Jul, 2008 - 02:01 PM
Post #1


D.I.C Regular

***
Joined: 28 Dec, 2007
Posts: 481



Thanked 4 times
My Contributions


Hello all!

I'm working on a small web site right now, with PHP and I'm using includes on the site. One thing I want to do, is prevent people from directly seeing the pages that I'm including such as header.php

I had some code as an attempt but all it does is put firefox in an endless loop of being redirected.

header.php
CODE

<?php
if ((basename("header.php") != "header.php")) {
echo "Hi";
} else {
header("Location: index.php");
}
?>


index.php

CODE

<?php
require("header.php");
?>


any ideas of preventing the user from directly seeing header.php but still seeing it when it's included?
User is offlineProfile CardPM

Go to the top of the page


girasquid
post 9 Jul, 2008 - 02:18 PM
Post #2


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 1,202



Thanked 9 times

Dream Kudos: 625
My Contributions


Are you talking about users visiting index.php and noticing that you're using header.php? Or something else?

If you're just talking about having them visit index.php, then you don't need to worry about it - by including header.php you'll have the code appear but not actually display to a user as being from header.php.
User is offlineProfile CardPM

Go to the top of the page

chili5
post 9 Jul, 2008 - 02:22 PM
Post #3


D.I.C Regular

***
Joined: 28 Dec, 2007
Posts: 481



Thanked 4 times
My Contributions


Yeah but they could come visit header.php which wouldn't work the best. What i want is so they cannot type header.php into the address bar and see the contents but when you go to index.php you can see the contents of header.php included in the page.

So when you type header.php into the address bar, you won't see anything but when you type index.php you will see the contents of header.php
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 9 Jul, 2008 - 02:52 PM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 289



Thanked 9 times

Dream Kudos: 250
My Contributions


You can check for the file name of the running script and if it's header.php or whatever you don't like to execute use exit();

For example:

header.php
php
<?php

if(eregi("header.php",$_SERVER['PHP_SELF'])) exit();

// The rest of your code
?>


PS: You can use header() to redirect instead of exit() if you want. It's up to you wink2.gif

This post has been edited by MitkOK: 9 Jul, 2008 - 02:58 PM
User is offlineProfile CardPM

Go to the top of the page

Akelo
post 9 Jul, 2008 - 03:42 PM
Post #5


D.I.C Head

**
Joined: 12 Dec, 2007
Posts: 73


My Contributions


if it's files you absolutely want to keep away from the public, put the include file in a directory others don't have access to (like the mysql connect file people normally make and store in a directory outside of the web directory).
User is offlineProfile CardPM

Go to the top of the page

chili5
post 9 Jul, 2008 - 03:57 PM
Post #6


D.I.C Regular

***
Joined: 28 Dec, 2007
Posts: 481



Thanked 4 times
My Contributions


If I was using a file that included mysql passwords I wouldn't put it in htdocs but for header.php and other included files this works great. biggrin.gif

Thanks a bunch smile.gif
User is offlineProfile CardPM

Go to the top of the page

woodjom
post 24 Jul, 2008 - 12:15 PM
Post #7


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


QUOTE(Akelo @ 9 Jul, 2008 - 05:42 PM) *

if it's files you absolutely want to keep away from the public, put the include file in a directory others don't have access to (like the mysql connect file people normally make and store in a directory outside of the web directory).


Akelo...

What chmod should i put on the directory so that joe_smoe public wont be able to even browse to that location.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/6/08 10:23PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month