{"id":447,"date":"2010-03-04T14:55:44","date_gmt":"2010-03-04T19:55:44","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=447"},"modified":"2010-03-04T14:55:44","modified_gmt":"2010-03-04T19:55:44","slug":"prevent-direct-access-to-php","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2010\/03\/prevent-direct-access-to-php\/","title":{"rendered":"Prevent Direct Access To PHP"},"content":{"rendered":"<p>Not sure if this is the correct way of doing things (as I&#8217;m still &#8220;learning&#8221; PHP), but it worked for me.<br \/>\nBasically I wanted to include a php file, but not allow the user to be able to directly go to that same file.<\/p>\n<p>Example: index.php calls upload.php.  Blocking the end user from going straight to upload.php (or even viewing the contents) would have been a bad idea.<br \/>\nThis is running on a debian server with LAMP.<\/p>\n<p><code>nano index.php<\/code><\/p>\n<blockquote><p>$including = true;<\/p><\/blockquote>\n<p><code>nano upload.php<\/code><\/p>\n<blockquote><p>if (!$including) exit(&#8220;Direct access is not permitted.&#8221;);<\/p><\/blockquote>\n<p>That&#8217;s it.  Now navigate to upload.php and you&#8217;ll see it doesn&#8217;t allow it to work.  Navigate to index.php and you&#8217;ll see the call still works.  Great?  Probably not, but it still works.  Hopefully it doesn&#8217;t introduce any other bugs &#8211; but it&#8217;s a purely testing system anyway.  So hack away.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not sure if this is the correct way of doing things (as I&#8217;m still &#8220;learning&#8221; PHP), but it worked for me. Basically I wanted to include a php file, but not allow the user to be able to directly go to that same file. Example: index.php calls upload.php. Blocking the end user from going straight &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2010\/03\/prevent-direct-access-to-php\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Prevent Direct Access To PHP<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-447","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=447"}],"version-history":[{"count":1,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/447\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/447\/revisions\/448"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}