Stuck with Defined('') protection want to understand

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
galvar2bos
Forum Newbie
Posts: 5
Joined: Fri Aug 03, 2007 8:47 pm

Stuck with Defined('') protection want to understand

Post by galvar2bos »

Hi all,
I am sure all of you are great programers but First i am no code programmer i am just trying to learn to run my sites, will the problem is i got a code from the web to protect my files ,1st i want to know how to work it out then i will try other things but can't let it go without a fight thanx all

***** PLEASE USE

Code: Select all

TAG WHEN POSTING CODE *****[/color]

Code: Select all

<?php

if ( ! defined( 'myname' ) )
{
	print "You cannot access this file directly.";
	exit();
}

customer data here
?>
now i can't access my files :?: :roll: what is the method to access them

all i want is to protect the file not to be opened directly but how to implement it in a frame or something like

display the contents in a frame or echo the source code as the file is a customer data please i am stuck and can't launch this small site

thanx in advance
Last edited by galvar2bos on Fri Aug 03, 2007 9:52 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Descriptive Subjects

Post by hawleyjr »

Hello and welcome to the forum.

You may want to look into using session variables.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if ( ! defined( 'myname' ) )
Tests whether a constant myname exists.
Another php file can define that constant prior to including the protected file

Code: Select all

define('myname', true);
require 'protected/file.php';
But the browser cannot set the constant in the http request. If you want to protect your files from being called outside your (html) frame set this is the wrong approach.
Post Reply