PHP 数组current和next用法分享,currentnext

2.next

PHP 数组current和next用法分享,currentnext

1.current

复制代码 代码如下:
奥门新浦京官方网站,<?php
 $transport = array(‘foot’, ‘bike’, ‘car’, ‘plane’);
 $mode = current($transport); //$mode = ‘foot’;
 $mode = next($transport);   // $mode =’bike’;
 $mode = current($transport); //$mode = ‘bike’;
 $mode = prev($transport);   // $mode =’foot’;
 $mode = end($transport);    // $mode =’plane’;
 $mode = current($transport); //$mode = ‘plane’;
 ?>

2.next

复制代码 代码如下:
<?php
 $transport = array(‘foot’, ‘bike’, ‘car’, ‘plane’);
 $mode = current($transport); //$mode = ‘foot’;
 $mode = next($transport);   // $mode =’bike’;
 $mode = next($transport);   // $mode =’car’;
 $mode = prev($transport);   // $mode =’bike’;
 $mode = end($transport);    // $mode =’plane’;
 ?>

示例很简单,但是却很实用,希望小伙伴们能够喜欢。

数组current和next用法分享,currentnext
1.current 复制代码 代码如下: php $transport = array(‘foot’, ‘bike’,
‘car’, ‘plane’); $mode = current($transport); //$mode…

if __name__ == "__main__":
    tornado.options.parse_command_line()

    settings = {
        "template_path": os.path.join(os.path.dirname(__file__), "templates"),
        "cookie_secret": "bZJc2sWbQLKos6GkHn/VB9oXwQt8S0R0kRvJ5/xJ89E=",
        "xsrf_cookies": True,
        "login_url": "/login"
    }

    application = tornado.web.Application([
        (r'/', WelcomeHandler),
        (r'/login', LoginHandler),
        (r'/logout', LogoutHandler)
    ], **settings)

    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
<?php
 $transport = array('foot', 'bike', 'car', 'plane');
 $mode = current($transport); //$mode = 'foot';
 $mode = next($transport);   // $mode ='bike';
 $mode = current($transport); //$mode = 'bike';
 $mode = prev($transport);   // $mode ='foot';
 $mode = end($transport);    // $mode ='plane';
 $mode = current($transport); //$mode = 'plane';
 ?>
class WelcomeHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        self.render('index.html', user=self.current_user)

1.current

代码是简单的示例,没有做登录验证

示例很简单,但是却很实用,希望小伙伴们能够喜欢。

5.服务器设置

<?php
 $transport = array('foot', 'bike', 'car', 'plane');
 $mode = current($transport); //$mode = 'foot';
 $mode = next($transport);   // $mode ='bike';
 $mode = next($transport);   // $mode ='car';
 $mode = prev($transport);   // $mode ='bike';
 $mode = end($transport);    // $mode ='plane';
 ?>

2.登录url

本文这里通过示例给大家简单对比分析了PHP
数组current和next的用法,虽然示例很简单,但是对于我们理解current和next非常有帮助,这里推荐给大家。

获取cookie中用户信息

3.主界面url

login_url参数设定了登录url

class LogoutHandler(BaseHandler):
    def get(self):
        if (self.get_argument("logout", None)):
            self.clear_cookie("username")
            self.redirect("/")

1.重写get_current_user()方法

@tornado.web.authenticated装饰器包裹get方法时,表示这个方法只有在用户合法时才会调用,authenticated装饰器会调用get_current_user()方法获取current_user的值,若值为False,则重定向到登录url

class LoginHandler(BaseHandler):
    def get(self):
        self.render('login.html')

    def post(self):
        self.set_secure_cookie("username", self.get_argument("username"))
        self.redirect("/")
class BaseHandler(tornado.web.RequestHandler):
    def get_current_user(self):
        return self.get_secure_cookie("username")

4.退出登录url

删除cookie中的用户,重定向到登录url

发表评论

电子邮件地址不会被公开。 必填项已用*标注