I want to develop a web application to read data from a MIFARE chip card. The idea is for a program of fidelization for a shop.
Is possible to read the data from within a browser? How could this possibly work?
A PHP web application's code is executed on the server side, so if you want to interact with a MIFARE card (through a contactless smartcard reader) on the client side, you will need to use something else besides PHP code to access that client side hardware.
Your web application will also consist of a web page (HTML, CSS, (Java) script) that is displayed and executed on the client side. This web page could, for instance, contain script code that is executed within the client web browser.
There is the upcoming NFC Web API to access client-side NFC hardware (that could possibly be used as MIFARE card reader), but this API is not yet available in most (any?) web browsers and it would only allow access to NDEF data on NFC tags. So you would need to use the MIFARE card as NDEF tag.
An alternative could be a Java applet embedded into the web page -- this is what most web applications do at the moment. If the MIFARE card reader is PC/SC compliant, you could use the Java SmartcardIO API within that applet to access the reader.
Another option could be a client-side application (you would need to create and provide that application) that acts as a web server and processes JSON (or whatever) GET/POST requests. That client-side application would then access the MIFARE card reader and your web application's (Java) script code could send JSON (or whatever) requests to it to retrieve card data.
Related
I have a web application that uses jQuery (via ajax) to PHP and from there to a MySQL database.
I need to do some ML using Python and reading from the database. My problem is that I am unable to figure out how to communicate from PHP to Python and back to PHP?
For more context, this will be a food recommendation system so on the website, if the user wants recommendations they can select filters (e.g. price range). Now at the moment, this will send a request to PHP and I am trying to pass data to Python run the recommender and get back to PHP with the returned data. Or is there a better way to do this? Like communicate from jquery to Python straight away. (I have Python running the recommender by itself communicating with the database, it just needs the filters that are in jquery)
You could use something like WebSockets to communicate from your front end to the Python backend. WebSockets are basically elevated HTTP sessions which allow for bidirectional transmission.
Mozilla docs have great information on WebSocket API that's built into modern browsers.
Here
This would be if you wanted to communicate straight from the front-end to python. If you wanted to do it from the backend (php), you could establish a socket connection from php to your python program. (TCP). But this might a bit overkill.
Maybe as a simpler alternative, you could create a small Flask web application with an endpoint that can be called by your PHP application (using an HTTP client).
The Flask web app can then make use of all regular Python functionality such as the ML libraries you require and return the result to your PHP application.
Or call the service directly through an ajax request.
This probably seems stupid question. But I'm new to ionic apps. I wanted to clear this before development.
Can we build ionic app without API? like we normally do for our website.
Example:
If you go to MySite.com, you will see the site running in php with normal rendering. Would Ionic work same way or it has to go through API Send/Receive request for data handling?
Ionic has no direct requirement on data access. It is built on AngularJS, which is in turn built on Javascript. Best practices would generally have you accessing JSON data from a server by using a mechanism that is Angular aware such as $http, $resource, Restangular, etc.
However, you can execute any javascript based browser command (or even load something like jQuery to perform the data access). However, as soon as you go outside of Angular, then you will have to deal with the additional complexity of making sure the digest cycle is run whenever you have updated values that may be reflected on your view because of data binding.
And, just to be clear, none of this has anything to do with what's happening on the server side. When you are asking about accessing "without API", do you mean accessing HTML files vs. JSON data? Ionic is built to be a SPA (single page application) that is installed on the mobile device and doesn't require internet access to run once it's installed.
Therefore, especially if external/live data isn't required (imagine some type of calculator where you enter values and results can be calculated with just the data in the app on the handset -- without the need for a live server at all), Ionic apps don't REQUIRE access to an external server at all.
You could provide traditional hyperlinks to other html files, but at that point it would no longer be running the packaged/installed files that form the basis of the installed app on the handset and would instead be a web app that is relying on an external server for all views. And, of course, even if it does require access to data from a server, the often massive increase in speed by not round tripping the server with a new HTML page (only a relatively tiny JSON payload in most situations) makes it feel much more like a true native app.
In ionic, the rendering happens on your phone. The server simply provides data. So if you need any data from a server (usually yes) then you need an API.
Ionic is focused on building native/hybrid mobile apps rather than
mobile websites.
– http://ionicframework.com/docs/overview/#browser-support
As per definition, an API only defines the way your ionic app can interact with your php script. In principle, there are no rules on how you design this interaction. So yes, you can keep it quite traditional/old-fashioned. Don't get the concept of an API mixed up with the concepts of RESTful or SOAP APIs etc.
When communicating between a Node/React web server and a PHP api server is it best practice to "proxy" all requests by the client (React) through the web server and not directly to the api server?
Im using universal (isomorphic) React rendered on the Node web server. It would also use the api server to build the initial page loads (isomorphic).
That's what I would do. Actually that's what i'm doing (with a java based backend/api). It allows you to hide the real structure of your api and also to eventually parse the result in the node server if needed. Also it allows you to adapt the request method to fit exactly your client services (if for example your api is not exactly sending the data the format and the way you want).
For me it seems to be a good practice (and I agree trying to close this question is crazy, this is a good question ...)
I'm still new in programming and my situation is:
I want to do a webpage connect to MySQL by using php
How I read the data from card reader in this way? By using php also?
And how I format or read the data from the card? And then it is necessary for me to get card reader which has SDK so that I can read the data from the card?
A PHP web application's code is typically executed on the server side, so if you want to interact with a smartcard reader on the client side, you will need to use something else besides PHP code to access that client-side hardware. There are different possibilities on how to perform such access:
You could develop/use a Java applet embedded into the web page -- this is what most web applications do at the moment. If the smartcard reader is PC/SC-compliant, you could use the Java SmartcardIO API within that applet to access the reader and forware information to your PHP application on the server.
Another option could be a client-side application (you would need to create and provide that application) that acts as a web server itself and processes JSON (or whatever) GET/POST requests. That client-side application would then access the smartcard reader and your web application's (Java) script code could send JSON (or whatever) requests to it to retrieve card data.
Instead of a client-side stand-alone application you could also create a web-browser plugin (again, you would need to create and provide that plugin). That plugin could then act as a proxy between your web-application and the smartcard reader.
You must use this library
PC/SC for PHP5
And install the php extension for PC/SC https://pecl.php.net/package/pcsc
But you need to install an older version of Laravel to use PHP5, the library is not compatible with PHP 7
I'm working for a business whose users are seeking for houses to rent.
These can be viewed through our website.
I am looking to create an Android application to help people find the houses on their smartphone. How can I make the mobile application get the data from the webserver (PHP/MySQL *) and make requests to it?
Isn't this the definition of a web service? Then what kind of webservice is supported by PHP and the Android platform version 8 (2.2 Froyo)?
There is one important requirement: it should be secure, by requiring authentication from the application, i.e. only the application would be able to access the data.
* Python 2.6.6 is supported. I truly love Python but I'd prefer not mixing server languages, as 100% of the website is written in PHP.
How can I make the mobile application get
the data from the webserver (PHP/MySQL *) and make requests to it?
On Android you have an older version of the Apache HTTP Client available. So that side is covered for making HTTP requests from your app to your server:
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://www.myserver.com/webservice/xyz");
HttpResponse response = client.execute(request);
With just 3 lines of code you have a GET request.
Then what kind of
webservice is supported by PHP and the Android platform version 8 (2.2
Froyo)?
There is a variety of different web-service libraries available for PHP like SOAP and other XML based protocols. Personally I wouldn't go for that, because XML is bloated. You want to keep the transmitted data small between server and client, because you are dealing with mobile devices, limited bandwidth and costly data-plans. JSON is a more compact alternative to XML. You could also create your own "binary" data format for exchanging data between server and client.
On the Android side you just need to look for a suitable Java client library for the web-service of your choice. Or if you go for a custom solution you just code it yourself.
There is one important requirement: it should be secure,
Use HTTPS
by requiring
authentication from the application, i.e. only the application would
be able to access the data.
That cannot be reliably enforced, unless you are dealing with user logins, then yes. If you do require your users to log in, then take a look at OAuth.
Don't store plain text passwords, neither in your client app nor on your server.
If you just want to enforce that only your app can access that web service then you could add something like a "client secret" string to your app's HTTP request headers. Your server would require that secret string to be present, otherwise access will be denied.
This wouldn't stop people from looking at your app for figuring out that secret, though. You can make it a tad harder by obfuscating that secret string, like randomly jumbling around the letters and so on.
You could also regularly change the client secret with each major update. This would require that your users have to update, otherwise they will be locked out.
You may want to consider implementing a function to query a PHP server for JSON data in your Android application (like json-simple), and in your server a way to retrieve a GET request (look at interperting $_GET and then sending back JSON too).
You can use XML, plaintext, or anything else too, but JSON is probably the smallest and the quickest to implement.