PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 28 votes, 4.54 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #76  
Old January 4th, 2002, 03:32 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 12
Send a message via AIM to rod k
rycamor,

You make a valid point AFA open source, distributed applications go. However, for code that is not open source, who would know that $PATH_INCLUDE is a session variable? Granted it's not good practice and I'm certainly not advocating leaving such holes, but without access to the source it is pretty much a non-issue as far as security goes.
__________________
FSBO (For Sale By Owner) Realty

Reply With Quote
  #77  
Old January 4th, 2002, 03:42 AM
jdk's Avatar
jdk jdk is offline
phpkid ~~~~~~ :o)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Nov 2000
Location: NJ, USA
Posts: 2,535 jdk User rank is Lance Corporal (50 - 100 Reputation Level)jdk User rank is Lance Corporal (50 - 100 Reputation Level)jdk User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 11 m 11 sec
Reputation Power: 10
Send a message via Yahoo to jdk
Still thats a nice thing he pointed out.

I am myself not using constants.

I will now think about incorporating it some or other way.

JD
__________________
_____________________________
d.k.jariwala (JD)
~ simple thought, simple act ~
I blog @ http://jdk.phpkid.org

Reply With Quote
  #78  
Old January 4th, 2002, 07:39 AM
pezzer pezzer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 35 pezzer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to pezzer
The problem with register_globals is that it makes all GPC variables available as globals, aswell as your variables. Thus someone can set a get variable, which if your code hasnt set, may be used as one of your globals. Without register_globals it means that if you access a global variable $auth, it cannot have been set by the user. Ofcourse if you write it carefully you can write secure code with register_globals on, but the majority (in my experience) of php programmers pay little or no attention to making their code secure. This has shown to be a problem in big open source projects like phpmyadmin, aswell as small websites that some amateur hacker destroys by fiddling with urls. In the last few years i've heard so many stories in the news of people changin urls on BIG companies websites, and getting other peoples bank details, creditcard details, messing with databases, etc (ok, so mostly these probably werent php sites, but same applies). People will mess with urls and post/cookie data, especially wanna-be hackers!

I think that register_globals is a very useful feature of php, and makes programming quicker and less messy, but, it is also a feature that without care leads to a lot of insecurity in code, which would otherwise be more secure.

Reply With Quote
  #79  
Old January 4th, 2002, 07:47 AM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Quote:
Originally posted by merkinmuffley
also, why is it so important to develop with max warning level? i can't believe how annoying it is to always get a warning when i call a function with fewer parameters than it declares, for example.


I use E_ALL as a tool, to simplify my coding. It warns me when I've forgotten to declare a variable, it warns me when I've forgotten to declare default values for functions that accept a variable number of parameters (which IMHO is a good practice), and it generally *helps* me in doing my job.

The live version of the site should naturally run with no error reporting at all and good logging facilities aswell as internal error handling routines.
__________________
--
Regards
André Nęss

Puritanism: The haunting fear that someone, somewhere may be having fun

Reply With Quote
  #80  
Old January 4th, 2002, 07:52 AM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Developing with register_globals off is a must if you want to make portable code, just like you have to handle magic_qutoes and other .ini settings in a portable way. If you write code to sell or redistribute somehow, these portability issues should be the first you resolve.

Reply With Quote
  #81  
Old January 6th, 2002, 04:18 PM
jason_d2 jason_d2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 0 jason_d2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to jason_d2
Lightbulb .inc files etc.

This is just a quick post about what the original author said about .inc files being viewable by anyone who types in the name in their browser.
What I do is i put my PHP library/utilitiy scripts below the document root, which stops people getting at them from apache.

For example
assume document root is /home/someuser/www.example.com
and all the .inc's are in /home/someuser/include
you would do a php include like this:

include($DOCUMENT_ROOT."/../include/example.inc");

that way the only thing exposed to the outside world via apache are the php files for the pages in your site, which they can't see anyway.

Anyway, this might be of interest to some people who have a problem with people viewing .inc's or the like, or who dont like having example.inc.php type files round the place.

Jason

Reply With Quote
  #82  
Old January 6th, 2002, 04:34 PM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
That's fine for library files, but I use a lot of includes when building my sites and putting them outside the webtree would make things messy, so we have our webserver set up to deny request for .inc files, simple as that.

Reply With Quote
  #83  
Old January 6th, 2002, 04:55 PM
jason_d2 jason_d2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 0 jason_d2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to jason_d2
Yep, thats a good solution as well.
Although i dont like to have .pll's (my version of .inc) scattered across the site tree. I like to have everything structured.
I.E.
all libs and includes go in DOC_ROOT/../include
rest of the actual php pages go in DOC_ROOT/whatever

I just call a wrapper function: fc_include("example.pll") and it takes care of everything. So in the document root I would have only page1.php, page2.php, page3.php etc etc.

I just think that this way is cleaner, but each to his own I guess.

Jason

Reply With Quote
  #84  
Old January 6th, 2002, 07:54 PM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
Re: .inc files etc.

Quote:
Originally posted by jason_d2
This is just a quick post about what the original author said about .inc files being viewable by anyone who types in the name in their browser.
What I do is i put my PHP library/utilitiy scripts below the document root, which stops people getting at them from apache.

For example
assume document root is /home/someuser/www.example.com
and all the .inc's are in /home/someuser/include
you would do a php include like this:

include($DOCUMENT_ROOT."/../include/example.inc");

that way the only thing exposed to the outside world via apache are the php files for the pages in your site, which they can't see anyway.

Anyway, this might be of interest to some people who have a problem with people viewing .inc's or the like, or who dont like having example.inc.php type files round the place.

Jason


I keep hearing people say .inc.php files are just as bad but no one has provided an example other than the kind of thing Jason said that people don't "like" them, whatever that means. Heh.

I see no reason to name them .inc and go through the trouble of setting up Apache to deny them, or moving them outside of your doc root. Why not just do it right the first time so you don't have to hack up a solution to get around the original problem? And what about portability? You can't expect all of your users to take the kind of care you do with your inc files, many of them may not even set up Apache to deny requests for .inc files and they may not [be able to] put them outside of their doc root. If you simply name the file .inc.php you eliminate the problem.. So I don't know why this discussion keeps being brought up like we need to hack up solutions to this problem when it's so easy to solve.

Reply With Quote
  #85  
Old January 7th, 2002, 08:34 AM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Well, the most important reason is that I don't want my .inc files to be run outside of their context. If they are named .inc.php that's possible, and I don't want it to be. Maybe I'm just being paranoid, but that's my reason.

Reply With Quote
  #86  
Old January 7th, 2002, 09:54 AM
Schnotz Schnotz is offline
hmm...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Nashville
Posts: 50 Schnotz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 18 sec
Reputation Power: 7
Functions

Encapsulate all your code in functions so the code won't be executed if the page is called. Good practice aswell.
Lots of thanks to JeffCT fo his thoughts,,,

Reply With Quote
  #87  
Old January 7th, 2002, 11:18 AM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
Quote:
Originally posted by andnaess
Well, the most important reason is that I don't want my .inc files to be run outside of their context. If they are named .inc.php that's possible, and I don't want it to be. Maybe I'm just being paranoid, but that's my reason.


There shouldn't be any executable code in a .inc file anyway. How are they going to be run outside of their "context"? Explain.

Reply With Quote
  #88  
Old January 7th, 2002, 04:43 PM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I generally build my sites using included files, so normally the only .php file is index.php, the rest is built from this file. This means that I have a lot of executable code in .inc files, and because of this I don't want them to be run outside of their context (by that I mean outside of where they are supposed to be included). This goes regardless of whether I name the files .inc or .php, I simply don't want them to be executed alone, and to do this I name them .inc and deny access to them.

Reply With Quote
  #89  
Old January 8th, 2002, 10:20 AM
Schnotz Schnotz is offline
hmm...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Nashville
Posts: 50 Schnotz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 18 sec
Reputation Power: 7
A way of writing your applications using only the index page (the way you like it) could be somthing like this....This way you will avoid all the trouble you are going through with denying files...

index.php


PHP Code:
include("includes/baseclass.php");

if(
$action='email')
{
   include(
"includes/email.php");
   
$email = new email();
   
$email->printheader();
   
$email->printbody();
   
$email->printfooter();
} else {
    
$main = new baseclass()
    
$main->printheader();
    
$main->printbody();
    
$main->printfooter();



baseclass.php

PHP Code:
class baseclass
{
    function 
printheader()
    {
        ...
format your header for your page
    
}

    function 
printbody()
    {
         ...
your main page or so
    
}

    function 
printfooter()
    {
         ...
your footer
    
}


email.php
PHP Code:
class email extends baseclass
{
    function 
printbody()
    {
        ....
format your body for your email page
    
}


Try it if you like it...Makes your pages very easy to modify

Reply With Quote
  #90  
Old January 8th, 2002, 04:44 PM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Eh... All the trouble? It's one bloody line in the apache config, and once it's done I never have to worry about it...

Anyway, I don't like creating classes and functions that are used one single time for one single purpose -- it seems like such a waste and IMO is not a good use of classes. The classes will also be very messy because I need to put all the HTML in there, and I will have to somehow pass all the data to the functions (either using parameters or using globals).
Remember that my pages contain mostly dynamic data, and all this data is usually loaded by one segment of code.

I did use a similiar approach on one website I did, but I found that the extra work didn't really pay off, the most important thing is to get repeated work factored out as separate components, and to have a neat physical structure on everything. My current solution which uses mainly includes to do the physical organization works quite nicely, it still has the disadvantage of each display component demanding certain data from the dataloader component, and they both have to agree on the naming of this data.

I'm always thinking of ways to improve on this organization, and in future projects I will hopefully come up with even better ways...

Reply With Quote