Jump to content

Function to kick users on the page


EchoFool

Recommended Posts

Hey,

 

I can't remember the name of the function to get the name of the script the user is viewing directly?

 

For example:

 

Say users should view include.php directly... they have to view index.php which has it included, i need to some how on include.php add a line to check if the user is viewing it directly, and if so - header them back to index.php.

 

I used to know it but i forgot the function! Hope you can help me here!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/
Share on other sites

You can achieve this like this:

 


<?

//Set Variables
$file = $_SERVER['SCRIPT_NAME'];

//Check for location to file path.
if($file=="/en/1.php") { header('Location: index.php'); }  //replace /en/1.php with location to file from your root directory

else {}

?>

 

Let me know if that works, if not you will need to use another SERVER tag.

This doesn't work sorry - if i have this in an include named include.php

 

When viewing index.php $file still equals  /include.php

 

I still get "no no!"

 

index.php

<?php
include("include.php");
Echo 'hello';
?>

 

include.php

<?php
$file = $_SERVER['SCRIPT_NAME'];
if($file == "/include.php") {
Echo 'no no!';
die; 
} 
?>

On your page that includes the file, place above the include();

$view_perm = 'yes';

 

At the top of the page you dont want viewed unincluded

if ($view_perm != 'yes' )

{header('Location: index.php');}

 

 

HTH

Teamatomic

 

Works a charm! Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.