Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 04-09-2005, 09:18 AM   #1 (permalink)
eurob
Registered User
 
Join Date: Apr 2005
Posts: 2
eurob is on a distinguished road
Question How to get the name of parent page ?

hi,

Newbie here.
I'd like to have php return the name of the page that is loaded, e.g.,
in a parent document, 'example.php' I do a <include("body.inc";> and then I'd like to put some code in 'body.inc' that can fetch the name of the parent, in this case, 'example.php'


Appreciate your help.

robert
__________________
eurob is offline   Reply With Quote
Old 04-09-2005, 09:35 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
use variable: $_SERVER['PHP_SELF']

you should really name all of your includes with a .php extention. since most web servers are not setup to parse .inc files in php, then someone could view your source code in case you are using php code in your .inc file.

if you must name it with a .inc, then name it body.inc.php. it is good practice and more secure.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 04-09-2005, 09:59 AM   #3 (permalink)
eurob
Registered User
 
Join Date: Apr 2005
Posts: 2
eurob is on a distinguished road
thanks

thanks a lot,

it works great

robert
__________________
eurob is offline   Reply With Quote
Old 04-09-2005, 11:48 AM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Lot's of servers support .phps, though. There's also a .htaccess directive you can use on apache based servers.
__________________
teknomage1 is offline   Reply With Quote
Old 04-09-2005, 12:42 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
still very bad practice IMO. there is absolutely no good reason why you should name files like that in the first place.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 04-09-2005, 12:55 PM   #6 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 637
DJMaze is on a distinguished road
a) prevent execution by using .inc extension (just shows source)
b) they must be loaded thru another php file

Showing the source of a .inc file is nothing bad.
If it's OS code i don't care a thing actualy.

If you have a bug in your OS file and it's .php instead of .inc then people can try to hack in (especialy when register_globals is on)

So i use .inc and untill my script becomes commercial i change.
__________________
DJMaze is offline   Reply With Quote
Old 04-09-2005, 04:25 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
what do you mean by "OS code" ?

Quote:
So i use .inc and untill my script becomes commercial i change.
sounds like just an extra piece of work to me. when you eventually change the file name, won't you have to test for the "hacking" you are using .inc files for in the first place?

b) you mean primarily for database security? if your connect script is not in the file you're concerned about, then they probably can't do much to your db by calling it by itself. on the other hand, a .inc file would give someone a good idea of what your db structure looks like if you're working with a db.

to each his own. however, considering this guy is "NEW" to php, you gotta agree it is definately not a good habbit for a newbie. there are books out there that tell you to make a db connection include named "connect.inc" .. really nice way to expose your db login info to the world.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 04-09-2005, 07:49 PM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,681
redhead is on a distinguished road
when using .inc anybody can view your source. if they encounter an error saying:
Error found in /web_space_user/include/my_php.inc they can try to fetch it directly,m viewing it as clear text, giving them a view in to your coding habit. If you like to use md5sum() or what ever...
It is very unsecure to call your include files .inc. or anything else that isn't executed by teh web server.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-09-2005, 07:51 PM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,681
redhead is on a distinguished road
****, i'm drunk now, but I still stand by my expression in the earlier post.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-09-2005, 07:57 PM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
Quote:
Originally Posted by redhead
****, i'm drunk now, but I still stand by my expression in the earlier post.
have one for me 2, cheers
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 04-10-2005, 07:35 AM   #11 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 637
DJMaze is on a distinguished road
Agreed that newbies should use .php as extension epecialy when it comes to sensitive information.

OS = OpenSource
OSS = OpenSource Software
__________________
DJMaze is offline   Reply With Quote
Old 04-10-2005, 08:56 AM   #12 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
I feel like a different extension is clarifying as to the purpose of the file, but you should not use a different extension if the server isn't set up to process it as php.

here is the apache code to execute .inc as php files
Code:
<IfModule mod_mime.c> AddType application/x-httpd-php .inc </IfModule>
Alternatively apache also recognizes application/x-httpd-php-source .
__________________
teknomage1 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking a flag in Opened ASP.net page Continously ! mechtech MS Technologies ( ASP, VB, C#, .NET ) 1 04-19-2005 12:37 PM
refresh page automaticlly lampoin HTML, XML, Javascript, AJAX 5 06-18-2004 08:13 AM
Trying to get number of e-mails in a txt file to appear on my main page netpants PHP 4 08-19-2003 08:46 PM
Validating Your Pages With the W3C Markup Validator verto HTML / CSS 0 08-11-2003 06:17 PM
Making a basic page in HTML MiLady Mirlyn HTML / CSS 0 02-16-2003 01:36 PM


All times are GMT -8. The time now is 11:46 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle