Does localhost refer to the client or the server? - php

I have a Dart application, which communicates to the server with POST-requests. At the moment, the server is on my local machine where I also test the application in the browser, so obviously, I have to send the POST-Req to localhost. But when the server is on one computer and the client anywhere else, it seems not to work with localhost even though both the webapp and the server are hosted on the same machine.
For example, I have to replace localhost:8080/web/info.php with 192.168.0.6/web/info.phpif the client machine is my phone that is in the same Wlan as the server. So does that mean that a request to localhostfrom dart code refers to the client machine? I assume so but want to be sure.

Localhost is just an easy way of identifying the current computer. It does not work when trying to access another server unless you view it from the server itself. If you want to access it from another server, you should either refer to your server by IP, or by a domain name.

According to James McLaughlin's answer, the localhost (http://127.0.0.1) could be server and client.
Other explanation for using the localhost for the client and server testing is at the localhost question.

Related

My ionic app wont connect to a MYSQL database running on the phone but on the PC with localhost it will run

I made an ionic app with a connection to MYSQL using a PHP API which I put on another computer on Xampp, using it as a remote server in the same network, when I run it on the computer with ionic serve , it works fine but when I generate the APK, it wont connect to the BD, even tho Im on the same network, does someone knows any way around this?
this is how it looks on the desktop
and this is how it looks on the cellphone
What I would conclude is that it connects to the nodejs server ("ionic serve") to load the assets from there but it cannot load data from the php/mysql API.
How did you reach the conclusion that MySQL is the problem? I mean your frontend (angular) does connect directly to MySQL right?
Hint: check your settings within ionic when you call the API -- it should point NOT to localhost/127.0.0.1 but to your computer's network IP. Apache should also be "open" to connections from "outside":
see here: Accessing localhost (xampp) from another computer over LAN network - how to?
I had the same problem in the past, it is because when you run the application on your pc it is working on localhost, just like your backend. When you run your application on a mobile device, it does not have access to your pc using localhost to access the backend.
In this case you must set the IP that your pc has on your local network as the backend address and in this way your mobile application can access it

Unable to access localhost using android mobile

Hello I have a problem in accessing the localhost in my android device. I can't open my localhost in my browser. I installed an application that supports httpd, php and mysql. But when I have a connection in the Internet there's no error in displaying the localhost. But if I disable it, I can't open the localhost. Is there a configuration file that I need to configure in my device? I am using ICS. I am using 127.0.0.1 as my localhost I also did 127.0.0.1:8080 but it doesn't work also.
If you're trying to access your web server over your local network, then you'll need to bind the web server to an IP address that the device can access - this is not 127.0.0.1. Assuming you're on wifi with your android, you'll want to have your web server listen to something along the lines of 192.168.1.X. If you use 0.0.0.0 it will accept on all interfaces, this should work as well. Either case, you'll need to access your web server from your device using your web server's local IP address, not localhost and not 127.0.0.1
Localhost as the url in a browser should access the server running on that device.it sounds to me maybe you are connected to a remote desktop or something. Tcp/ip utilities in particular try tracert localhoast or route. config /release maybe your touting tables are messed up,weird
The localhost refers to the device on which the code is running, in this case the emulator.
If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead 127.0.0.1. You can read more from here.
I encountered the same problem while working with my localhost too. The problem turns out to be with the antivirus that i was using. I was able to access my locahost again after turning the antivirus off. But because i cannot continue using my machine without an antivirus I just have to change the antivirus to another one. It worked for me, Hope it will for you too.

What does PHP do when calling a URL located on the same Apache server?

I have two PHP applications on the same Apache server. At some point, application A needs to call a URL on application B.
So let's say a script located at http://somedomain.com/app1/action need to download http://somedomain.com/app2/action using file_get_contents() (the domain is the same for both applications)
I was wondering how does PHP handle this? Is the request going through the whole internet, as if it was a call to an external URL? Or is it somehow optimizing it and accessing the application on the server directly?
I think it depends from your DNS resolution and is not related to PHP.
If your network is properly configured, you should be able to access the site on your local network even by calling the public url.
To be sure about your request not leaving the server, you could use the localhost ( or 127.0.0.1 ) address. You can also use the local ip address to access it over the local network.
It uses the whole TCP/IP stack of the operating system, if that's what you want to know.
If it's in the same server, it wouldn't have to resolve the DNS name if you use 127.0.0.1 instead of somedomainname.com.
Usually request do not "go out" of your server, so application B is accessed quicly by application A.
Requests can "go out" in the wild and then being routed back to your server (and that's not so good for performance) if your server DNS are not configured well (pratically, your server can't recognize itself as somedomain.com).
The whole internet is big. But it would unlikely leave the server, depending on the network layout.
The request goes through every server between the source and the destination. Since they are the same, that is no servers.

Why is Tomcat refusing a connection from my other server?

I have server A making a request to server B. I've tried both php's file_get_contents and curl; both refuse the connection. I'm trying to connect to a tomcat application on server B.
The connection does work if I make a request to google.com, or to another application on server B that is not in the Tomcat application.
This leads me to believe there's something specific to my tomcat installation that is rejecting the request from server A. Thoughts? Any more info I can provide to help with the problem?
Is there a way to whitelist my server A in tomcat so the connection is accepted? Or as a last resort how would I accept all requests?
Edit: I also wanted to add that the connection to server B works just fine when I'm connecting from my local development machine.
Your test from server A to google.com or other apps on server B probably use port 80. Many firewalls don't allow traffic on strange ports like 8089.
If you can't change the firewall rule to allow access to serverB:8089, I think the right way to do it is to proxy the request through the server B web server. So server A would request "serverB:80/yourproxyurl" and the web server on server B would talk to the tomcat server on localhost, and output the response.
This is what Tomcat Connectors are for, as I understand it.

Want to see a wordpress site which runs in localhost at server computer from client computer

I build a webisite with wordpress and i want to show my website to other client computers
I run xampp server at server computer
How can i do for that?
plz answer quickly..**
Assuming the web server is accessible from the client's computer, you'll need to give connect from the client using the machine's IP address or hostname.
You will have to use a dynamic hostname, dyndns offers them.
Or put xampp it in sync folder of Dropbox. I'm using it like that. Synced from home, then when i open it from work, i got it there too.

Categories