简体   繁体   English

在页面上仅运行一次PHP回发请求?

[英]Run a PHP postback request on a page only once?

I would like to know if there is an equivalent of IsPostBack in PHP. 我想知道PHP中是否存在IsPostBack I want to call a function or a method only once, once the user is logged in. 用户登录后,我只想调用一次函数或方法。

I have a facebook application, in which once the user authorizes the application it should enter his details in the database. 我有一个facebook应用程序,一旦用户授权了该应用程序,它就应该在数据库中输入他的详细信息。 This basic stuff should have been done using the post-authorize callback url which facebook pings when the user first authorizes the app. 这些基本内容应该使用后授权回调网址完成,该网址在用户首次授权该应用程序时会ping Facebook。

The issue is that since I am checking whether the user exists or not in index.php, I would not like index.php to run this code repeatedly for the same user when the user goes to the homepage every time. 问题是,由于我正在检查用户是否存在于index.php中,所以我不希望index.php在用户每次访问主页时都为同一用户重复运行此代码。

Is there any PHP code that will run it only once? 是否有任何PHP代码只能运行一次?

<input type="submit" value="submit" name="submit_button" />
<?php
if(isset($_POST['submit_button']))
{
    // only execute if postback
}
?>

edit 2: I didn't misunderstood after all... 编辑2:毕竟我没有误会...

If it only has to run once per login, you could save the state to the session, so you can see if it has to executed or not. 如果每次登录只需要运行一次,则可以将状态保存到会话中,这样就可以查看它是否必须执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM