Jump to content

[SOLVED] URL detection


Ken2k7

Recommended Posts

Ohk, so I'm just wondering about one thing.

 

Is there a way to use PHP to detect where its script is used from?

 

Example:

I put: <script src='test.php'></script> in a page located index.html (same directory for now, but may not always be the case). Can test.php detect that it's being called from index.html?

Link to comment
https://forums.phpfreaks.com/topic/84558-solved-url-detection/
Share on other sites

I guess I don't understand your question.

 

Heres what I understood you wanted.

 

User vists site - Is forwarded to index.html

index.html uses <script> to include 'test.php'

test.php receives index.html as the referer.

 

What do you mean "display that URL out on index.html" ?

"index.html" is the referer...

Link to comment
https://forums.phpfreaks.com/topic/84558-solved-url-detection/#findComment-430845
Share on other sites

Yes. Your other question does not.

 

For example, if you only wanted test.php to run if its included from index.html you could do something like:

 

<?
# this is just pseudo code
if($referer == "index.html"){
  // Your script goes here
}else{
  echo "Sorry, you cant use this file elsewhere";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/84558-solved-url-detection/#findComment-430848
Share on other sites

So I would do something like this?

 

index.html

<script src='test.php'></script>

 

test.php

<?php
if ($referer == "index.html") echo "true";
else echo "false";
?>

 

I tried that but when I go to index.html, it displays a blank page :S

 

Edit: nevermind, solved. Stupid me. XD

Link to comment
https://forums.phpfreaks.com/topic/84558-solved-url-detection/#findComment-430855
Share on other sites

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.