That’s probably everyone’s first thought. But it’s a little bit more difficult. See Chris Shiflett’s article SERVER_NAME
Versus HTTP_HOST
.
It seems that there is no silver bullet. Only when you force Apache to use the canonical name you will always get the right server name with SERVER_NAME
.
So you either go with that or you check the host name against a white list:
$allowed_hosts = array('foo.example.com', 'bar.example.com'); if (!isset($_SERVER['HTTP_HOST']) || !in_array($_SERVER['HTTP_HOST'], $allowed_hosts)) { header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request'); exit; }
Related Posts:
- How to run php files on my computer
- Whats the point of running Laravel with the command ‘php artisan serve’?
- Enable PHP Apache2
- Apache is downloading php files instead of displaying them
- PHP code is not being executed, but the code shows in the browser source code
- How to configure self hosted wordpress so that everything can be upgraded/installed from dashboard
- WordPress multisite causing Error 101 (net::ERR_CONNECTION_RESET): Unknown error [duplicate]
- Evaluations of two wordpress security plans against php code injection attack
- .htaccess redirect http to https
- How do I resolve a HTTP 414 “Request URI too long” error?
- 404 Not Found The requested URL was not found on this server
- Simplest two-way encryption using PHP
- What is the difference between the ‘www’ folder and ‘htdocs’ folder?
- XAMPP, Apache – Error: Apache shutdown unexpectedly
- SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- client denied by server configuration
- XAMPP: Connecting to localhost fix? [Persistent]
- Request exceeded the limit of 10 internal redirects due to probable configuration error
- How do you redirect HTTPS to HTTP?
- lbmethod_heartbeat:notice – No slotmem from mod_heartmonitor –error after installing apache2.4.2 [closed]
- XAMPP installation on Win 8.1 with UAC Warning
- org.apache.jasper.JasperException
- How can I force users to access my page over HTTPS instead of HTTP?
- Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
- WAMP won’t turn green. And the VCRUNTIME140.dll error
- .htaccess: Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration
- WordPress broken app to try wpscan kali tool
- wordpress login wp-login.php change url
- Enforcing password complexity
- cURL 28 error after switch from to brew php 7.2 on localhost
- How do I get the right permissions for WordPress running Apache on Debian
- How can I improve site/page performance of WordPress websites?
- How to run multiple Async HTTP requests in WordPress?
- WP CLI info showing correct PHP binary but wrong version of PHP
- Renaming wp-content folder dynamically
- How do I create a WP user outside of WordPress and auto login?
- Best practices for making a WordPress site “movable”?
- Which ways can be used to log in to WordPress?
- Installing WordPress in a Sub-Folder (not in root) on Localhost
- Is it unsafe to put php in the /wp-content/uploads directory?
- What’s the proper way to setup WP-CLI on Ubuntu so that I don’t have to use the flag –allow-root?
- Why Better WP security plugin returns 418 I’m a Teapot “error”?
- Is it possible to move wordpress out of webroot?
- login wp impossible
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- How do I test to ensure that my wp-config file is protected?
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- WordPress custom login form using Ajax
- Detect session/cookie variable in wordpress to prevent access to documents
- SQL Injection blocked by firewall
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Point root folder to blog.domain.com and subdirectory to domain.com possible?
- WordPress admin dashboard missing icons
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Correct and safe way to include php content in my page
- How to add API security keys into JS of wordpress securely
- Hardening uploads folder in IIS breaks images
- How does WP work in conjunction with a web server?
- Troll the hackers by redirecting them
- Permalinks are not working in WordPress in digitalocean
- Updating From Mobile App – Exposing Site to Hacking
- I Made WordPress Multisite. And Now Everything Doesn’t Display Properly
- Check against server time to display SQL entries – Radio Station DJ Rotator Plugin
- Plugin error after installation
- security concerns if using html data-* attribute for l10n?
- Problem with data collection in tables
- New wordpress keep redirecting to localhost/wp-admin/install.php
- How to point domain to wordpress page
- echo cutom css code to WordPress page template file ? is this safe?
- Is a local multisite installation equivalent to multiple VirtualHosts?
- How to rename a wordpress site from http://myserver.example.com/blog to http://myserver.example.com/somethingelse or just http://myserver.example.com
- WordPress in AWS Lightsail – restrict public IP
- $.ajax results in 403 forbidden
- How to edit content in WordPress and the Polylang – plugin? – with demosite
- Upgrade to PHP7.3 and Changing Apache from Prefork to Event Breaks WordPress
- Site infected by link
- Huge time to first byte on live site
- Deny php execution in /wp-includes – using .htaccess in /wp-includes VS root folder
- Move site root directory on debian
- Timthumb isn’t displaying any images. “A TimThumb error has occured
- Strange special character/Latin characters
- I got ERR_TOO_MANY_REDIRECTS on subdomain
- What is the best practice for restricting a section to logged in users?
- Rewrite /keyword1+keyword2.html to search page | .htaccess
- W3 Total Cache Can’t Really Detect Things
- Admin-area broken through weird issues
- Apache and Networks
- Blog only showing code
- Configure VirtualHost for a perfect WordPress Environment
- WordPress Memory limit not increasing
- Having an HTTP error 500 after migrating a website
- oEmbed work on localhost but not on distant server
- How to quickly/easily make an analysis (reverse engineering) of WordPress?
- session_start(): Cannot find save handler ‘mm’ – session startup failed in /sites
- Permalinks to Post name not working
- How to rename files during upload to a random string?
- WordPress – Unable to Create New Account – Windows/Apache/MySQL
- Serve static files via a subdomain on a wordpress
- Restricting access to a file for everyone except logged in users