Zachary Lassiter
Zachary Lassiter

Reputation: 181

Domain Specific URL include() exemption

I want to allow a URL to be put inside php's include(); but only certain domains - not every one. The other domains are owned by me, and on a separate server. If someone tries to include() any other domain bu these I want them disallowed.

If this is not possible, is there a work around?

Upvotes: 0

Views: 133

Answers (3)

ceejayoz
ceejayoz

Reputation: 180065

$allowed_domains = array(
      'stackoverflow.com',
      'www.stackoverflow.com',
      'facebook.com',
      'www.facebook.com',
      'google.com',
      'www.google.com',
    );

    if(!in_array(parse_url($url, PHP_URL_HOST), $allowed_domains)) {
      // throw an error
    }

Upvotes: 0

Kevin Schroeder
Kevin Schroeder

Reputation: 1295

My recommendation? Don't do it with includes. Executing code in that fashion is like swallowing a chocolate covered cherry bomb.

Upvotes: 1

Oliver Bayes-Shelton
Oliver Bayes-Shelton

Reputation: 6292

You could do it on the web server so you don't even let the domain which is not allowed to parse or get any files. you have to remember any request will go through the web server and server static content or be parsed which all takes time and then add the time for the PHP script to execute.

Upvotes: 0

Related Questions