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
- http://localhost:80 is not working on running Apache server through UniServer ZeroXIII
- How can I use an .htaccess file in Nginx?
- .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
- Getting an error when I visit http://localhost
- What is the difference between Local Server and a Web Server?
- Chrome net::ERR_INCOMPLETE_CHUNKED_ENCODING error
- Localhost is not working
- Simplest two-way encryption using PHP
- Redirect vs RedirectMatch
- What is the difference between the ‘www’ folder and ‘htdocs’ folder?
- What is Options +FollowSymLinks?
- SVN Error E175002 while checking out code from repository
- Are PDO prepared statements sufficient to prevent SQL injection?
- XAMPP, Apache – Error: Apache shutdown unexpectedly
- SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- htaccess – Redirect to subfolder without changing browser URL
- How can I prevent SQL injection in PHP?
- client denied by server configuration
- What is HTTPD exactly?
- What does it mean to escape a string?
- XAMPP: Connecting to localhost fix? [Persistent]
- Request exceeded the limit of 10 internal redirects due to probable configuration error
- MAMP “Apache couldn’t be started because port is in use.” AND “Can’t connect to local MySQL server through /tmp/mysql.sock
- PHP and mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
- How do you redirect HTTPS to HTTP?
- Adding a user on .htpasswd
- Only variable references should be returned by reference – Codeigniter
- Connection reset by peer: mod_fcgid: error reading data from FastCGI server
- a2enmod command not found in apache server using cpanel in linux vps
- How do I disable directory browsing?
- file_get_contents( ) not working
- Apache and Node.js on the Same Server
- XAMPP, using port:81, cannot run localhost:81/mywebsite
- How to view PHP on live site
- lbmethod_heartbeat:notice – No slotmem from mod_heartmonitor –error after installing apache2.4.2 [closed]
- Difference between Systemctl and service command
- “End of script output before headers” error in Apache
- “End of script output before headers” in Apache + PHP
- XAMPP installation on Win 8.1 with UAC Warning
- org.apache.jasper.JasperException
- Https to http redirect using htaccess
- How can I force users to access my page over HTTPS instead of HTTP?
- Site does not exist error for a2ensite
- Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
- Using PHP 7 with WAMP
- How to remove index.php from WordPress site URL
- 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
- Redirect old php link to wordpress link in .htaccess
- Redirect old php link to wordpress link in .htaccess
- WordPress broken app to try wpscan kali tool
- wordpress login wp-login.php change url
- Cant login to wp-admin (redirecting to homepage), But CAN login to wp-login.php
- Cant login to wp-admin (redirecting to homepage), But CAN login to wp-login.php
- esc_attr() right way and use
- Enforcing password complexity
- Does My Child-Theme Functions.php Need if{die} Security In It? [duplicate]
- 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 Attackers write script into my php files?
- How to run multiple Async HTTP requests in WordPress?
- WP CLI info showing correct PHP binary but wrong version of PHP
- Does the debug.log do log rotation?
- Correct Approach for Validating Custom Field Input
- 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”?
- WordPress V2 REST-API: Endpoints 404?
- Security – Ajax and Nonce use [closed]
- Which ways can be used to log in to WordPress?
- Installing WordPress in a Sub-Folder (not in root) on Localhost
- Can I write ‘RewriteCond’ using ‘functions.php’?
- 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?
- Which Apache-modules must I enable?
- What are some good Apache settings to use with wordpress?
- How Restrict access to admin dashboard by specific static ip?
- Sanitize get_query_var() url parameters
- apache cpu over 70% on localhost
- Why Better WP security plugin returns 418 I’m a Teapot “error”?
- Is it possible to move wordpress out of webroot?
- login wp impossible
- wp-admin/index.php gives a “500 Internal Server Error [closed]
- When must I use and verify nonce?
- Memory errors with media upload, WordPress can’t use more than 96M (while there’s 512 available!)
- Escape when echoed
- Hiding WordPress Plugin Source Code
- Is this code malidcous