o_O
o_O

Reputation: 516

Is there a way for a PHP script to know the address of the site that it is used on?

I have a PHP script located on mysite.org and I use it to display images on sub sites of example.com (like example.com/foo/bar, example.com/foo/another-bar). I can only post links to that script there.

Tried $_SERVER['REQUEST_URI'], and $_SERVER['REMOTE_ADDR'] but there's no go.

So what i need is some way to know if its used on e.g. example.com/foo/bar.

Upvotes: 1

Views: 60

Answers (5)

Explosion Pills
Explosion Pills

Reputation: 191779

I think you are looking for $_SERVER['HTTP_REFERER']

Upvotes: 0

dreyercito
dreyercito

Reputation: 64

You may use $_SERVER['SERVER_NAME'], you can check other variables from the php documentation: http://php.net/manual/en/reserved.variables.server.php

Upvotes: 0

SLaks
SLaks

Reputation: 887767

It sounds like you're looking for the Referer header, which tells you the page that the request for an image came from.

Note that some browsers do not send this header.

Upvotes: 1

Michael Berkowski
Michael Berkowski

Reputation: 270677

You need a combination of $_SERVER['SERVER_NAME'] and $_SERVER['REQUEST_URI']. Or maybe I'm misinterpreting the question. $_SERVER['SERVER_NAME'] returns the domain name a script is running on.

Upvotes: 0

dwergkees
dwergkees

Reputation: 734

just create a test php script containing:

<?php
    phpinfo();
?>

It will give you very detailed list of php settings and global variables, the setting that you are looking for is bound to be there.

Upvotes: 0

Related Questions