I'm running a simple php script that loops through a list of URLs and does a DNS lookup and saves the A record in a database. Runs perfectly on my local server but when I put it on my live server, the records are all internal 192... because its using the internal DNS server.
I'm using Net_DNS2 and have told it to use google DNS:
$r = new Net_DNS2_Resolver(array('nameservers' => array('8.8.8.8')));
but this doesnt seem to be working, I still get back 192 internal addresses.
Any ideas how to resolve this? I already moved to Net_DNS2 from the php dns_get_record function so that I could set a nameserver, but it doesnt seem to be working.
Related
I have a project need to server migration, the new server deployed by docker. but in docker, the file_get_contents() cannot fetch the result from self domain. and I can't use others way (for example reqire_once) to load this file ( this project is too old and code is... you know ).
code:
$json = file_get_content("http://this.site.com/xxx/yyy/get_result.php?params=xxx¶ms2=yyy")
If I use it, will get a warning connect refuese, if I replace the domain to http://127.0.0.1 or http://localhost, will get the same warning, or replace to http://nginx ( nginx is another container's name ) will get content, but not my site's content ( it will get contents the same by using 127.0.0.1 in the broswer, not using http://this.site.com )
So it
Your code is running with a docker on another instance so is 127.0.0.1 address is different from your computer's address.
You must enter the external IP address of the container
Try using host.docker.internal...
The problem:
My /min/ files are in different places for my local and live server:
localhost/min/
/mnt/foo/bar/hello/example.com/web/content/min/ (from $_SERVER['DOCUMENT_ROOT'])
Min works fine on my localhost but after uploading the same files via ftp to my live server I get a 400 bad request error. This is clearly due the different document roots.
What I've tried:
Changing the $min_documentRoot = '' variable in config.php file to
$min_documentRoot = '/mnt/foo/bar/hello/example.com/web/content/'
Still gives the same errors.
Additional info:
My requests look like this:
src="/min/b=js&f=jquery.min.js,bootstrap.min.js,site.js"
What am I doing wrong?
how are you minifying? is it with zip?
make sure that the live and local servers both have the same setup. especially, make sure that they both have the required minification functions available to them. for example, the Zip PHP functions are not installed by default in Fedora installations.
check the online server's httpd error log
Well. I read some topics in SO but I not found a very specific answer.
I need to check with PHP if a PHP code is running in local or remote host. Currently I check with $_SERVER['SERVER_NAME'] but it is inconsistent. In this case, if I run PHP with listed IPs like 127.0.0.1 or localhost it'll consider local, otherwise remote. If I share my IP with a friend, my code still local, but it consider remote because the shared IP isn't listed.
Well, I think that check IP for localhost is not a good idea (except if you know a good method). I tried methods like gethostbyaddr() and gethostbyname() but don't work correctly too.
I don't have a PHP code to show, but my code is basically that:
// true = localhost
return $_SERVER['SERVER_NAME'] === '127.0.0.1';
The fundamental question is: what can determine that PHP is running local? What is "local" for PHP? I think that it can solve the problem.
Obs.: I don't have access to CMD/Shell with PHP.
You could do what most PHP frameworks do and set a flag during your app's bootstrap phase that defines which environment the code is running in. In it's simplest form:
// the setting when run on a dev machine
define('ENV', 'local');
Then it's a simple case of:
if ( ENV == 'local' )
{
// do stuff
}
This is how I do it, which I find more reliable than trying to detect for 127.0.0.1:
if( strpos(gethostname(), '.local') !== false ) { }
Basically, the hostname's on my workstations all have .local appended to it. You can change this to match your workstation's hostname entirely.
Check $_SERVER['REMOTE_ADDR']=='127.0.0.1'. This will only be true if running locally. Be aware that this means local to the server as well. So if you have any scripts running on the server which make requests to your PHP pages, they will satisfy this condition too.
If someone is visiting your site via the web, the IP address you see will never be 127.0.0.1 (or ::1 for IPV6), regardless of the usage of a proxy. (Unless of course you're running the proxy yourself on the same server ;)
As far as I know, only you will be able to know what addresses are local or not. Your network could be set up with IP addresses that don't look local at all. PHP cannot as far as I know determine this by itself.
I've been googling this one a lot but I still could not make it work. I have a MAMP web server installed on my mac and I've created some a web service. It work fine when I call it from the browser on my mac when I use localhost:8888/myfile.php and also when I use 192.168.0.108/~martin/myfile.php.
The problem is when I try to call the 192.168.0.108/~martin/myfile.php from my iPhone to do some testing, the requests time out. It is really weird because this was working 2 days ago. I'm not sure what has changed. I'm not very familiar with httpd.conf and htaccess files, but I did not change things there manually.
Any help would be appreciated!
Have you tried going to http://192.168.0.108:8888/myfile.php on your iPhone? If MAMP is running on 8888 you will need to specify the port to access it there.
Be sure to check your computer's IP too. It's possible that it changed over the last few days depending on your router's setup.
Also, make sure the iPhone is indeed on the same network as your local machine. Depending on your network setup, a subnet might not work either. I've driven myself crazy trying to connect to a box that was actually connected on a separate subnet.
Don't know if this helps anyone but I got this working by simply removing the ip host address and changing this to the wildcard. It started working straight away after this
I had success opening my local-folder by opening the host by the computer’s local hostname.
Solution 1: computer’s local hostname
Find your computer’s local hostname: macOS->System Preferences->Sharing->File Sharing
https://support.apple.com/et-ee/guide/mac-help/mchlp1177/mac
Near the "Computer's Name" you can find the info:
"Computers on your local network can access your computer at:
"mymac.local"
Opening the compuerts name "your_computers_name.local" in iOS-Safari worked for me:
http://[your_computers_name.local]
For example:
http://mymac.local
Solution 2: computer’s network address
Try it with the computer’s network address. If you select and activate file-sharing in the preferences you can find the network address. Looks like: "smb://name.example.com". Replace "smb" with "http".
Open the network address in iOS-Safari (connected via USB-Cable or Wifi):
http://[insert_your_computer_network_address]
For example you can access your files like:
http://name.example.com/myfile.php
This worked for me, too.
As an alternativ way to find the address write "hostname" in terminal of the host-computer:
$ hostname
This will return the host's name / network address.
Doesn't work?
Maybe you have to allow file sharing first? I don't know ...
macOS->System Preferences->Sharing->File Sharing: On
I have spent 2 days on this and are now stumped, having tried dozens of different methods and lots and lots of googling.
I need to retrieve data generated by a php page running on apache, using the GET command. This works fine when I am connecting with the LAN, but if I connect remotely then I am unable to get any response when there are variables in the path.
This works bot locally and remotely and I get the expected output from the php page.
GET /myfolder/mypage.php<CR><LF>
However, add a variable to the path and I get the correct response on the LAN but connecting remotely I get no response whatsoever:
GET /myfolder/mypage.php?var1=1&var2=2<CR><LF>
Just to reiterate, this works fine when accessing from the LAN and works fine in a web browser, but when I send as effectively a Telnet request I get nothing at all.
Any ideas ??
EDIT
The request is being sent to Linux Apache web server via a serial > tcpip gateway with a carriage return and linefeed at the end. The syntax works perfectly on the LAN with the ?var1= etc but as soon as I add ?var=1 when connecting externally nothing at all is returned, in fact apache logs don't show any record of the connection request.
I ## SUSPECT ## this may be something related to apache mod rewrite ?
May be can try something like below and specify the host and also the ver of HTTP being used.
GET /myfolder/mypage.php?var1=1&var2=2 HTTP/1.1
Host: 127.0.0.1