doulang6695 2012-01-04 08:31 采纳率: 100%
浏览 65
已采纳

如何在iPhone应用程序中执行注销?

I know nothing about PHP, but in my application I need to implement user login and logout. I've found this nice tutorial and have successfully implemented logging in, but how do I log out? I just can't find any information about it in google, particularly about iPhone side. PHP tutorials mostly explain a lot of theory about sessions and stuff like that which is not applicable for my specific event. I would love to spend my time for learning that theory, but I have to learn PHP basics first and this is not what I currently need.

All I need is to understand the correct way of implementing logout.

  1. I would be glad very much if someone explained me shortly in plain language the mechanism of standard interaction between iPhone app and php script when logging in and out.
  2. This is more important. Would you please provide me with few lines of php and objective- с code displaying how to implement logging out?
  • 写回答

1条回答 默认 最新

  • douzhong2954 2012-01-04 09:09
    关注

    In our app we use this schema:

    Login I'll jumpover (that you've done)

    When the user logout our application call an URL, which is considered for logout. For example: http://ourcoresyste.com/logout.php

    Sorry for inconvinience, but I'm not iOS developer, so I don't know exactly how application makes call, but I think you should know it, if login is done.

    In the script logout.php:

    <?php
        if (!isset($_SESSION))
        {
            exit(json_encode(array('code' => 0, 'message' => 'Logout successful')));
        }
        esle
        {
            $user = $_SESSION['user_id']; // suppose you have stored into $_SESSION['user_id'] logged in user;
            // Do some stuff while logout, maybe some DB interactions.
            if ($shit_happens)
            {
                exit(json_encode(array('code' => 1, 'message' => 'Shit happens')));
            }
            unset($_SESSION['user_id']); // or session_destroy(), if you want completly remove all information about user.
            exit(json_encode(array('code' => 0, 'message' => 'Logout successful')));
        }
    

    Than in your app you parse JSON response which will be like this:

    {"code":0,"message":"Your detailed message"}
    

    And decide by code retrieved from JSON response, were user logged out or not. If he was, next time you call any PHP script, which relies on $_SESSION['user_id'], will fail, probably that's mean that user is logged out.

    I think that's all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 通过下面文章的方法求手机号段
  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体