php SERVER['REMOTE_PORT'] correctness
$_SERVER['REMOTE_PORT'] is the port making the request on the user's machine. That will be used to route back the page request to their router. This may look like a random number, but it's a port generated by the user's router.
$_SERVER['SERVER_PORT'] is the port on your web-server that is receiving the request. This will be either 80
or 443
depending on if the user is using https or not.
Here is another posted question on Super User
that explains this phenomenon of browsers requesting a webpage from a "random" port -> https://superuser.com/questions/1055281/do-web-browsers-use-different-outgoing-ports-for-different-tabs.
Also, router in between the client and web-server may change the port and then store the port-connections in the NAT (network address table) in order to route the response back to the browser. -> https://superuser.com/questions/105838/how-does-router-know-where-to-forward-packet
From: CompTIA Security+ Get Certified Get Ahead: SY0-501 Study Guide - 2017 by Darril Gibson
Client-side ports start at ports 49,152 and increment up to 65,535....
...When you use your web browser to request a page from a site, your
system will record an unused client port number such as 49,152 in an
internal table to handle the return traffic. When the web server
returns the web page, it includes the client port as a destination
port. When the client receives web page packets with a destination
port of 49,152, it sends these packets to the web browser application.
The browser processes the packets and displays the page.
Also, from the PHP manual: https://www.php.net/manual/en/reserved.variables.server.php
'SERVER_PORT'
The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for
instance, will change this to whatever your defined secure HTTP port
is.'REMOTE_PORT'
The port being used on the user's machine to communicate with the web server.
Can't Curl to PHP Page with $_SERVER Variables
The first script you posted has several syntax errors. When you call it via curl, you are getting an HTTP 500 error because it is throwing exceptions.
A few errors of note from testing:
- You do not close your
foreach
loop with a curly brace. - Your series of nested
if
statements are missing curly braces. - The
$_SERVER
superglobal will not be populated with all values when run from command line (just an FYI from my testing -- not necessarily an issue) resulting in severalundefined index
errors.
Work on that script separate and once it runs correctly, then you can call it from another one.
Related Topics
Mysqli Query to Loop Through Array and Update Multiple Rows
How to Use MySQLi Bind_Param Dynamically
How to Get Include Contents as a String
Mongodb Aggregate Query Using PHP Driver
Phalcon Performance Related Queries
Using Ajax/Jquery to Refresh an Image
Echo a Multi Dimensional Array
Set Cart Item Price from a Hidden Input Field Custom Price in Woocommerce 3
How to Format a PHP Include() Absolute (Rather Than Relative) Path
Google Recaptcha - Keep Getting 'Incorrect-Captcha-Sol'
What Is the Rfc Compliant and Working Regular Expression to Check If a String Is a Valid Url
I Want Get the Sum of Files Size in Folder by PHP
PHP Get Height and Width in PDF File Proprieties
Count Word Frequency in a Text
Http Referer Not Always Being Passed