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

Link to comment
Share on other sites

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; 
} 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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