douzhenyu6533 2017-02-06 08:54
浏览 26

包括两次php文件?

I am working on a page that demands that a certain php code is included at runtime - however, at some point in the code below, the variable in that included file is to be rewritten by a remote curl POST request, so I need to re-include the file to read the new value of the variable.

Can I "include" it again to reload the new value? Or is a double include of the same file within the same code not allowed?

EDIT:

Here's what I'm doing exactly:

  1. include a file, that contains 1 variable

  2. run a check in an online API to make sure the URL from the variable is not in the database

  3. if it is, initiate a cURL POST request to a page on my second domain, that starts a chain of events there

  4. after that chain is completed, the second page sends a cURL request to another page on my first domain - the request contains another URL which it passes to a page on my first domain, which in turns grabs that and overwrites the initially included file with the new value for the variable

  5. back to my initial code - I now have a new value for that previously included variable, so I need to "reload" it somehow, because I will be using it a bit later in the code of the same page; won't re-including the file be best?

  • 写回答

2条回答 默认 最新

  • drpkcwwav20524605 2017-02-06 09:35
    关注

    I think you should move the "later part" of the code in your first PHP file to the file that overwrites your initial variable in #4. Else, move that code to new php file altogether.

    You can also implement a web-hook kind of system where you'd pass the "variable" to the first code as a GET/POST parameter. So, the first time that code gets called it will check for the variable. If empty, then it does what you mentioned in steps 1-4.

    Then step #4 calls that PHP code again, but passing a variable value. Hence, instead of executing the first part of the code, the file executes the later part.

    In any event, your code seems to be too convulated, and is best to split it into functions and classes or something.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么