react and php and mobile - php

I am using react for my frontend, PHP and MySQL for the backend. React is running on localhost, port 3000 and xampp server is in localhost, port 80.
I am getting data from MySQL to php parse to json format. For the frontend, I used axios API to call the data.
While I am in browser, I am able to see the data, but when I access the same page from mobile, I can see only the tables not the json data.

Its probably because you are running your application locally, and wont be able to access localhost on your mobile (because as the word itself suggests its LOCALhost). If your mobile is on the same network as your desktop you can access the site from your computers local ip address.

I guess your front-end is configured to use http://localhost as the back-end url ? Which means that when running on your phone, its using the phone host as the back-end url :)
Try setting the back-end url to http://192.168.1.99 on the front-end.

Change API url to:
http://192.168.1.99/assets/data.php
You used localhost/assets/data.php, but your xampp was installed on your PC, not on your mobile, so your mobile can't access to this.

Hi to test it on mobile you could also used Remote Device from chrome developer tools.
For details you can check on this Link
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews

Related

Laravel localhost server not working on ios devices

I host my laravel project using my network ip address and it's working using android phone, but when i use ios device the page is accessed but only blank display.
What is the problem for this situation and how to solve it?

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

Use MacBook as Mysql Local Server

I have a MacBook and I am currently working on a web-app for our school. I am using PHP, MySQL, and Apache, all provided through the XAMMP stack.
When testing the website via localhost it works fine. Now, some of my teachers wanted to try out the web-app via their phones. Can I configure my MacBook to work like some sort of a 'local server' (e.g. probably through the internal network) to which other devices on the same internal network can connect via their phone browsers?
Is this possible?
You need to understand in using a Website, the client itself doesn't need to contact the database server. The web server is the one who communicate with database server and send/serve html pages to the client.
Phpmyadmin is a website not a database itself. So you simply need to allow access to your web server,you can use your laptop as web server. Test directly using your laptop as a web server, open the website instead using localhost change it to your laptop ip address. If it's not working then tell us the error so we can help you from there.

Instagram redirect-uri fails for localhost

I am writing a PHP app to fetch all my photos with Instagram using their API. However, what puzzles me is, I run the app on my hosted server it works perfectly fine and the same app running locally does not work.
Here are some points on the app workflow:
The user sees the homepage and he will be prompted with 'sign-in with Instagram'
User signs in with Instagram and authorizes the app.
Instagram redirects the user.
The app then makes a request for access_token and receives it.
Using the access_token, the app will send further requests for user media
The response is parsed and the links to the images are now provided to the user.
All the above mentioned process works fine on my hosted server but fails at 'Step 3.' and redirects user to home page of my app.
The problem is localhost being the redirect_uri. Does anyone have a solution to this problem to use the app locally?
P.S: I have registered two separate clients on Instagram: one for locally hosted development and the other on a web server.
Also, I have tried localtunnel. Did not help either.
I know its a very very very old Question. but for those who get to this page hoping a solution:
instagram currently does not allow to use something like localhost or myvhost.test in redirection url, whats more it requires the url to be certified (https).
so the only working solution I could find is using ngrok. you should download it from the url, open it and type a localhost virtual domain name along with a specific port number like ngrok http myLocalUrl.test/app 80, hit enter and it will gives you two temporary public links.
it will remain valid until you close the ngrok command line. you can direct the link to a specific port number and direct the port number to specific folder path of the application in your localhost.
the tutorials provided by ngrok is simple enough if you did not understand my hints.
I was dealing with this issue trying to develop an Instagram App using NodeJS/Express.
I got around this by using my computer's external local IP rather than localhost, which you can grep for. I assume you're on a *nix machine, so do a very simple (and crude)
$ ifconfig | grep inet
which will return you a few ip and MAC addresses, one of them being your external IP. However this is lousy because it means every time you switch IPs you'll have to update your application's redirect_url with Instagram as well as update any code that relies on it.
Thankfully, there exists services like no-ip that will basically provide free DDNS service to you, so you need simply register a hostname with them and then drop that into your DEV env code as well as your development client's redirect url and you're set to go!

create local server on android

I want a develop a web application with php, and I want a run my apps with a android device. But my device will not be connected to internet, so I must create a local server on the device to run my php code. Is it possible? And if it's possible how?
Based on this page, developing Web Server for mobile devices is still on the research phase. Most probably you would need to use some kind of simulator for Android and develop your App on powerful desktop PC.
EDIT: Looks like such a server exists for Android.
Please use KSWEB.apk. This app supports PHP, SQL, html, csc, but it requires 3 android devices. The first serves as router, the 2nd device is a local server and the 3rd devices is a monitor.
I'm not sure about your need to have a web server running on your phone, but if you have a wireless router and your phone can connect to it, can you not install an Apache server with PHP support on your development PC and access it via your phone's wireless connection?

Categories