iOS Development

php – How can I learn session variables immediately in Goal C for my iOS utility?

Spread the love


I am writing an utility which wants to have the ability to log into the web. The iOS a part of the app is written in ObjectiveC, and the serverside is written in php – and people php capabilities are referred to as by each the iOS app and the site.

The code to retrieve knowledge from the database works fantastic – I can populate my tables in iOS, and I may also add knowledge to the database by calling php capabilities (utilizing NSURLSession and NSURLRequest), however now I need to add performance to replace safe pages (account administration), and for this I supposed to set cookies for the session. In php, this does not current an issue – I can examine that the login was profitable after which set (and unset) utilizing the next code…

if(session_status() !== PHP_SESSION_ACTIVE) session_start();
if ($_POST['username'] == $username && password_verify($_POST['passhash'], $passwordhash)) {
   $_SESSION['loggedin'] = true;
   $_SESSION['username'] = $username;
} else {
   $_SESSION['loggedin'] = false;
   $_SESSION['username'] = '';
}

I can then examine to see if I am logged in as follows…

if(session_status() !== PHP_SESSION_ACTIVE) session_start();
if (isset($_SESSION['username']) && ($_SESSION['username'] != '') && isset($_SESSION['loggedin']) && $_SESSION['loggedin']) {
  return true;
} else {
  return false;
}

I might at all times name these capabilities from ObjectiveC (the identical means that I populate and retrieve knowledge from my tables) – however this appears inefficient. I’ve an NSURLSession, so (I’d have thought) it ought to be doable to see these values immediately with out calling php code on my web site.

The issue is that I can not fairly exercise how. NSURLSession would not appear be fairly proper, and NSHTTPCookieStorage appears to persist between classes – which is unquestionably flawed. My understanding of how this all hooks collectively is clearly flawed… Can anybody set me straight?

If doable, I do need to have the ability to proceed sharing as a lot code between web site and app as doable (so setting the cookies for log in for instance), however not when it would not make sense to take action – like calling out to the server for info which ought to be accessible to me domestically.

2 thoughts on “php – How can I learn session variables immediately in Goal C for my iOS utility?

  1. of course like your website but you have to check the spelling on several of your posts A number of them are rife with spelling issues and I in finding it very troublesome to inform the reality on the other hand I will certainly come back again

Leave a Reply

Your email address will not be published. Required fields are marked *