红酒泡绿茶 2014-08-21 11:58
浏览 20
已采纳

PHP将对象从脚本发送到脚本

I have a PHP webpage containing several php scripts. In the first script I create an object, which is needed by all scripts. In general I want to avoid globals, so how can I send an object from one script to another script?

My first point of thought was to use $_SERVER['object']=$myobject. But I realized that this is not working. So I'm looking for another solution. In the past years I used PHP_SELF, but that was used in forms. In this case I do not have any forms and this object is created before a session is started and will be uses also outside sessions. Is there another option?

  • 写回答

1条回答 默认 最新

  • douye8500 2014-08-21 12:10
    关注

    why don't you create a page , call it Shared.php or whatever , create the object inside it , and use require("Shared.php"); in each of the needed scripts ? require will include this object defined in Shared.php

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

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器