Forum Moderators: coopster

Message Too Old, No Replies

Where is PHP script called from?

         

Lupi

12:52 pm on Nov 11, 2010 (gmt 0)

10+ Year Member



Hi,

I have an external PHP script, script.php - this script is called from the site mainsite.php in one of two possible ways:

1) From mainsite via include: include('script.php');

2) AJAX: XMLHttpRequest().open('GET','script.php',true)

Depending on where it's called from, the output from the script should be different.

What I'm looking for is thus a way to check where the script was called from (1 or 2) inside an if statement.

Any pointers for me?

Thanks, Chris

Readie

1:07 pm on Nov 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Declare a variable above the include, then just run an if(isset($some_variable))

jecasc

1:12 pm on Nov 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Haven't tried it, but would something like this work?

1) via include: include('script.php');

2) AJAX: XMLHttpRequest().open('GET','script.php?id=1',true)

and then:
if ($_GET['id']==1){}
else {}

I know you can't do this:
include('script.php?id=1');
but since the other is a http request you should be able to use a query string.

Lupi

1:16 pm on Nov 11, 2010 (gmt 0)

10+ Year Member



Readie, jecasc, thanks for your help! There is indeed a variable that is only passed with the XMLHttpRequest, so I'm running a if(isset($some_variable)) and it's working fine.