Jump to content

Security question


racer x

Recommended Posts

I am learning about php security and having some trouble understanding the hackers accessing a file directly such as a validation script.

 

I was looking at CodeIgniter validation to see how they do it and noticed they put this line at the top:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 

I am thinking BASEPATH refers to a file path from the root to the normal page request?

 

How could I implement such a code in my scripts or is there a better method?

 

Gosh! How do you ever get to the point where you feel secure enough that you can put your code out there in the real world!

Thanks!!

Link to comment
Share on other sites

The best security tip i can give you is to never let any user inputted information to go unvalidated. With any user submitted information always use strip_tags() or htmlentities() and for inputting in a database always use mysql_real_escape_string(). User inputted information is the biggest security hole in php there is.

 

Link to comment
Share on other sites

User inputted information is the biggest security hole in php there is.

 

It's not a security of PHP.  It's a common security hole in programs written by oblivious coders.

 

 

 

As for that if(!defined()) thing, it's a fairly common thing to check for a defined var on an included page to make sure the page was reached via another page.

 

Example:

 

page1.php

<?php
define('SOME_DEF', true);
include 'page2.php';

 

page2.php

<?php
if(!defined('SOME_DEF')) {
    //not accessed through page1.php
    exit;
}

Link to comment
Share on other sites

Thanks you guys for your input. I am working hard at learning php and there's rarely a day that goes by where I don't read at least a couple articles on security.

 

To me, everything I learn about php is worthless if I don't secure my scripts properly! 

 

Would that defined rule not allow a person to reach a page through a bookmark like pasting:

www.site/vendors?page=7 

 

Thanks again for the input!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.