I am developing a mobile application in phonegap. My app works in a way that when a user submits a form, the data gets posted to a file called functions.php (present in the root folder) and functions.php parses data and sends to my rest application using curl. When I run this application in a web server, it works perfectly fine but when i run it in phonegap and post data to functions.php, instead of running functions.php as a function, it displays all the code of functions.php on the mobile screen and stops there. Does anyone know whats going on?
The situation you describe is what happens when you try to run a php file from a webserver that does not have php installed, so it sounds like you are trying to load the functions.php locally from within your phonegap app. Phonegap has its own webserver, which is not a php server, so it won't run php files. If you need to interact with php/sql/other remote stuff, you should be using ajax requests to interact with the remote (non-phonegap) server. https://forum.jquery.com/topic/how-do-i-get-ajax-working-with-phonegap
Related
I am working on a project which require sessions. I have my PHP files on a server and I am coding the front end in Angular, locally at the moment.
I am creating a $_SESSION in my php file for when a user logs in. Creating the post request on my local angular project, any $_SESSION property is returned as empty (e.g. $_SESSION['key'] is empty). However, it works fine when testing on Postman, and also works fine when I compile my angular app and put it on the server... So it works on Postman, and on the angular app on the server, but not the angular app locally (with the exact same code).
I have added CORS to my PHP files, and can use many other post/get requests locally, just not the session.
Is there any particular reason this doesn't work, or a way to get it working locally? As I don't want to compile and upload the project every time to test it out.
Any other information needed, please let me know.
Thank you in advance.
I am 'new' to PHP so this question probably has a very obvious answer, so Ill apologize in advance.
Situation:
I am running a VueJS project, running it with npm run serve and then deploying it with npm run build to a laragon apache server with PHP 7 on it.
That all works great.
I am now moving from using our C# API which we have hosted and you hit it as a URL. To a PHP Api, this API is just set up with a straight connection to SQL using sqlsrv_connect. This is also working when I host it on apache/laragon in its own folder and hitting it on its own URL extension.
But what I was wanting to do ( and not sure if this is possible )
Is in my VueJS project put the .php files in a data folder and hit them like this fetch("src\data\GetSQLData.php?table=Clients&columns=top%2010ClientID"")
Is this possible, or should I rather have them hosted separately and use the URL method?
Buddy,
Vuejs is a front-end framework.What it means is, When you do npm run build then it will create bunch of js and html/css/image files on the server.Then you require a web server to server these files.
When you hit the url on your web-browser then all these files will download into
the web-browser and then execute over there.This is how front-end framework works in a nutshell.
PHP is a back-end scripting language.Which means it require back-end php engine to run and execute the code logic.So it has nothing to do with vuejs that is running on your web-browser.
Best possible way to connect these 2 applications is via API.You should request data from a php API which is running on back-end web server.
fetch('http://localhost/GetSQLData.php?table=Clients&columns=top%2010ClientID')
Was trying to play around with my brothers on this app, the goal of making this app is just for fun, not going to achieve anything on the security aspect, nothing much.
The last thing that I want to achieve is that I want to call a php file from my app.
From the tutorial I watched on youtube,
HttpWebRequest.Create(string.Format(#"http://192.168.0.101/load.php"))
This works fine as I call 'load.php' from my server(another machine on same network), then the file will establish the connection to an online database(freemysqlhosting), then the file will run some queries and display the return results on my app.
So my question is, what if I want to call the load.php somewhere but not from my server ?
Is it possible for the app to call the file directly from its directory ? Does app works in that way like php/c++ ?
Or must I buy some web hosting accounts to upload a single php file online so that my app can call it ?
You should load the PHP file from a server.
If you want to load a web server inside your app, first you have to code (or include) the web server code and then include the PHP binaries in your app for the architecture of your app
I created an app using PHP and it runs fine using the HTTP address in the Webview object.
When using locally, the PHP script does not work (putting all files in assets).
Is there a way for PHP pages to be loaded locally but to define the actual PHP part to be used at the webserver?
To clarify, all HTML content of the .php page will be used locally but when needed PHP code it will connect the webserver.
Thanks!
If you use a php content you should have Internet connection because php codes work on server side not local devices(some apk's install mysql+php in your android device but if you want to publish your apk this way wont work in all devices on local.)
Also if you want to make an offline project why dont you use javascript "To clarify, all HTML content of the .php page will be used locally"
Here you can download phpforandroid.apk to work on the local Click Here
I am working on a Android Application that has web view where i need to load html, jquery and js and php also. Now i am able to load html jquery css javascript , But my problem is i am unable to load php in web view in offline is there any way to execute php in web view
Please Help Me Thanks In Advance
You almost certainly don't want to run PHP on your Android. But in case you do, then you would want http://code.google.com/p/php-for-android/. Better link: http://phpforandroid.net/
PHP is a server side language. It cannot run inside the browser. It helps you to build the dynamic web pages.
You can call any web page in the webview when you are online. it doesn't matter what is the server side language.
When you are offline, you cannot send request to any server. so no question of executing any page.
You can do it easyly with AndroPhp, just search it in Google play and install.
Its like WampServer for Php+Mysql. You should run it than just create your PHP project under www/ folder and call it from Android webview 127.0.0.1:80/yourproject
This way you you have local server on your Android, you shouldnt code in Java for Android all you can code in PHP. Maybe it is not a elegant way to code for Android but works !!