Skip to main content

How to make restricted access to included files in php

Suppose you have 2 php files, say base.php and included.php


included.php is included in, base.php.


So you dont want included.php has been called directly from url.


So in such a case, the solution is


#########
#base.php
#########


<?php


    define ("ACCESS",1); #defining a constant
    include ('included.php');
   
?>


#############
#included.php
#############


<?php


    if(!defined("ACCESS")): #checking the constant


        die ('Direct call is restricted";


    endif;   


    echo "I am included";
?>

Comments

Popular posts from this blog

Wowza Streaming Engine REST API - Monitoring The Status of a STREAM File

This is a small PHP-CURL script, initiates a JSON request to Wowza API to get the realtime status of a STREAM file. Note that the request is protected by Wowza 'AUTHENTICATION - DIGEST' Mechanism. ********************************************************************** $wowzaip = '192.168.166.68'; //replace with your wowza ip address $application = 'live'; //replace with your application name $streamfile = '10-20160527134707366114.stream'; //replace with your streamfile //initiate a curl session $ch = curl_init(); //set http header to json curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json')); //set wowza request url curl_setopt($ch, CURLOPT_URL, 'http://'.$wowzaip.':8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/'.$application.'/instances/_definst_/incomingstreams/'.$streamfile.'/monitoring/current'); //set RETURNTRANSFER true. Now return as string instead of output curl_setop...

MySql command line - Print query output containing large number of rows and columns

To print large dataset of records in user friendly way, use any of these options. Option1# (open the records in linux 'less' editor - line by line format)      mysql> pager less;      mysql> select * from table\G; Option2# (open the records in linux 'less' editor - table format)      mysql> pager less -SFX;      mysql> select * from table; Escape character of 'less' is 'q'