/    Sign up×
Community /Pin to ProfileBookmark

restrict access

i want noone to access a php file
i mean no direct access
but i want a php file to access it

something like:
<?
$url =”[mysite]”;
if ($_SERVER[‘HTTP_REFERER’] != $url) {
echo “hey its working ?”; // code i want to access
}
else{
exit();
}
?>

i want that file only accessible with only my other file

like site1.com/file1.php contain my code

site2.con/file2.php is on another website
i want to access file 1 from another domain witm html code (iframe etc..)
& i want to restrict all direct access from browser

hope u guyz get what i am saying

& please reply fast i have to submit this after after 5hours ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 28.2014 — [code=php]
<?php
if(realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {
header('HTTP/1.0 404 Not Found');
exit;
}
[/code]
Copy linkTweet thisAlerts:
@ginerjmOct 28.2014 — Or - simply place it in a folder outside the web tree.?
Copy linkTweet thisAlerts:
@yhiauthorOct 28.2014 — NogDog dude will u please explain what that script do ?

i mean how it will protect file from direct access ?
Copy linkTweet thisAlerts:
@NogDogOct 28.2014 — If the full path-name of that file (built in constant __FILE__) is the same as the file that was invoked by the web server per the HTTP request, then a "Not Found" HTTP response will be sent and the script will be terminated. If it is included/required by another script, then those two path-names will be different.
Copy linkTweet thisAlerts:
@yhiauthorOct 28.2014 — ok thxx it solved direct access problem ?

but how to access it ?

i want a frame of it on another website
×

Success!

Help @yhi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...