can cache be applied for storing important informations? - php

I am creating an app which is to be hosted in an multi server environment . My frond end is php and backend is java. i am calling everything using rest client. so i want to reduce the number of api calls. For that i need to store the relevent information on client side once it is called once. i dont want to call same api twice(like user profile info). so what is the best option for this ?
Earlier i thought of using session, but i hope that wont work out for multi server enviornment. I dont have a database in frontend.
so can i use cache for this ? can cache be used to store user related data?
is cache reliable for this use?

If you are using REST you can cache the API calls themself by using a cached HTTP-Proxy to connect to the REST Server.

Related

Saving PHP SESSION Cookie in Cordova iOS 6+

I'm upgrading a Cordova iOS 5.1.1 application (written still in jQuery) to iOS 6.1.1 platform as Apple rejects apps that still use UIWebView. I find the migration quite tough as my app is using loading JS files via Ajax, storing data in localStorage and storing PHP Session cookies and all of this data must be reachable now as well.
I have added cordova-plugin-migrate-localstorage plugin to migrate the localstorage data that UIWebView was using and it works fine. However, I cannot seem to find / implement a solution how to save cookies, especially PHP Session ID as it's mandatory that it doesn't change for each request, because PHP backend returns data depending on the SESSION data.
I've tried most of the plugins that were mentioned, for instance cordova-plugin-cookie-sync, cordova-plugin-cookie-inject etc. but none seem to work and store the Session ID.
Unfortunately I can only test the app in the simulator as none of my devices has i so I'm also wondering if there is a solution that doesn't demand having a physical device?
Am I doing a mistake and should stay on iOS 5.1.1 platform and just add wkWebView? I tried to play around a bit and just add the wkWebView Engine to it but it doesn't seem to know how to load local JS files.

PHP SVN with LDAP authentication

I am working on a PHP website which is using the php_svn module to retrieve data from our SVN repositories.
For this I have set internally a hardcoded user/pwd so I can connect (dirty way...)
Now I would like to connect using my current LDAP user. Means that once I try to connect to SVN, then PHP should be able to retrieve my current windows session (the client side that executes IE,etc..) and pass it to SVN so it will still recognise me without prompting user/pwd...
Not sure if this is possible but would be brilliant to achieve it :)
Has someone achieved something similar? In the php_svn site not much information is available for this specific point...
http://php.net/manual/en/book.svn.php
Thanks in advance!
It seems like you're trying to get a web request to be session based. Web requests are stateless (meaning each request starts over from a blank slate). If you want to maintain credentials between requests, you'll need to use some kind of session handler. PHP has a built in one. http://php.net/manual/en/book.session.php
You won't be able to directly access the 'windows session' however. The information has to make its way from the windows session, into the browser, which isn't really possible without some kind of browser plugin... the more realistic way to do this is: have the user log in to the website, submit their credentials, then store them in a PHP session, to be re-used by PHP on every subsequent page load.

Laravel: Offline Mode?

I want to make my web app (which is built with laravel) work offline...but I cant found out how to do it!
I am using the "app cache" for static files, but im not sure exactly how to handle the dynamic side of the app.
The app uses a database which im guessing I need to use localStorage for? (from what ive read online so far)
Im basically just looking for someone to point me in the right direction as im struggling to find much online on setting up Laravel for use offline
Thanks,
Dave
You can only have a static site offline with appcache. You cannot do this with laravel.
If you want to move the data into localstorage and have a semi- dynamic website, you have to completly change your architecture. Let me outline a possible approach :
A single page web app written in javascript ( using a framework like for instance ExtJs ) that connects to a backend in a form of a webservice that gives access to the database ( you could write it using laravel ).
When you are connected to the server you can load the data in localstorage When you are offline you can continue to work with the data. When the client reconnects, you have to synchronize the changes with the server.
Edit: As of 2020, Application Storage is deprecated. Look into ServiceWorkers instead.

The 'easiest' method to get MySQL on localhost in my Android Application

I've successfully managed to use POST to run a PHP script on my website, which allows the phone application to add a new entry to the database (MySQL), and delete an entry.
The next step is the one I have been struggling with for the last few hours now, and that is getting the information FROM the DB onto the phone!
I would like a method that initially just connects to the DB upon starting the activity and populating listview or something will all entries, and later down the line I plan on copying the information to a SQLite DB within the phone.
What is the easiest method I can look into for achieving this?
I can be resourceful but I just need to know what I'm looking for!
you have many options.
higher level abstraction over HTTP (REST/SOAP/etc) like already mentioned
HTTP as a proxy for plaintext/CSV data (without abstraction)
a direct JDBC connection from android device to the MySQL
database data export/import
I guess you're looking for option 3. That is syncing a remote database to local (SQlite on android) and then working with local data? In this case you just get a mysql-client jar (JDBC drivers) into your app and you can start. There're some restrictions though, like Sébastien Renauld already mentioned in the comment. Yet, those issues can be worked around, i.e. with custom configuration of MySQL or with option (2) which can be implemented in generic way (write once)
In general you need to create server API: choose some format to talk to between your web service and android application.
Then you'll always be need to request some data from server, that will be returned to you in format described above in a body of network response of some sort.
Next all you need is parse this data and populate to your adapters or whatever.
Note that networking operation might take quite some time depending on your connection, so you can't wait while it ends to show your UI - you need to do this in async manner, and give user a feedback that data is retrieving.
Nowadays json format passed in body of http post requests are quite popular. Take a look at this tutorial on how to parse json on android and this video about how to create json api in php.
Of course you can try to connect to remote MySQL server directly.. It really is more simple solution in some cases (you don't need to code server-side api), but might be not so accessible because standard MySQL ports aren't opened in all networks. Also your API server might hide some implementation details on how is data stored in reality, thus allowing you to migrate for example from MySQL to PostgreSQL without pain for android application.
Don't forget to secure your data from unauthorized access!
EDIT
It's 2017 and what would be the easiest option now is to use opensource project which will provide rest api for your database, for instance ArrestDB or postgrest
I personaly had to develop this following REST API Service (based on Laravel framework, which I call it lRapi) for an iOS and Android devices, and works great (the version in use for the apps, is much more complex).
https://github.com/w0rldart/lRapi
There are plenty Models and Controllers there that you may use to get started. Responses are JSON formatted, with proper headers.
I still have to add some more documentation to it, but there is some on the main example view, which you may access by just setting the virtual host and opening the root page in browser.
Laravel is a MVC PHP Framework, and it's really easy to get used to it.
This a good way to avoid to do most of the work, and just focus on implementing what else you need.

Passing PHP session id to FLEX app

I'm developing a FLEX application which has a Java Server as back-end.
What I need:
-The FLEX app can only be used if the user it's logged;
-The FLEX app also needs to know which user it's logged, because it will shows especific content about him;
-I need to perform authentication on every webservice call;
However, the webpages are being developed using PHP, as well the login system.
After some digging, I've discovered that I can use the PHP session ID for authenticate every webservice calls, by using the php-java-bridge so both PHP and Java can share the same session.
My problem it's that I don't know how the FLEX app can get the current PHP session ID. I know that it's possible to pass it by flashvars, but I think it's not secure.
If someone has other solution, even not using the PHP session id, I'd really appreciate it.
Thanks in advance.
I see no benefit for Flex to access the PHP Session ID directly; are you sure that's what you need?
The SWF files that Flex creates are intended as client side software. Whereas PHP and Java are usually used as server side software. Try not to treat your Flex app as if it were a server side program.
The way most web applications handle sessions is that the server sets some cookie on the client. The browser automatically passes that cookie with every request; and the server uses that cookie value to sync the request up with a server side session.I know ColdFusion and Java work like this and I assume PHP uses a similar mechanism.
Every time that your SWF (AKA Flex App) makes a request to the remote server, the request will include all cookies set by the server, just like it is a normal browser request. The server should automatically sync the Flex request to a server side session.
Does that help?
you can have a php page that will be called by flex using httpService, return the $_SESSION['userName'] or your session variable. if returned empty. stop the loading of the program. hope it make sense. coz i did the same thing..

Categories