加载页面中的全局变量 [英] global variables in a loaded page

查看:186
本文介绍了加载页面中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的索引页,该页使用脚本将另一个页面加载到div中

I have my index page which uses a script to load another page into a div

  $('#TransportPlanning').click(function() { 
      mainpage = $('#FloatMain')

      mainpage.load('create_diary.php') 

  });

页面可以正常加载到我的div中,但是我想将php变量从一个页面共享到另一个页面,我认为新加载的页面将能够引用主要的索引变量,但事实并非如此,我尝试了全局但仍然无法使用

The page loads ok into my div, but I want to share php variables from one page to another, I thought the newly loaded page would be able to reference the main index variables but this is not the case , I have tried global but still not working

请帮忙吗?

推荐答案

要在两个不同的PHP脚本之间共享变量,请将其设置为超级全局:

To Share Variable Between Two Different PHP Scripts, Make It Super Global :

使用

session_start();
// store session data
$_SESSION['key']=value;

在index.php中,并在crate_diary.php中将其读取为:

In index.php And read it in crate_diary.php as :

session_start();
$key=$_SESSION['key'];

然后在create_diary.php中执行($ key)变量特定代码.

And Do That ($key) Variable Specific code in create_diary.php.

使用会话或Cookies可以防止不道德地使用您的敏感数据.您也可以使用Cookie代替会话.但是,别忘了在设置完会话后取消设置会话.特别是在处理cookie时,因为当用户关闭浏览器时Session会被自动销毁,但对于cookie而言并非如此.

Using Session or Cookies Prevent Unethical Use of Your Sensitive Data. You Can Also Use Cookies Instead Of Session. But Dont forget to unset session after you've done with it. Specially When you are dealing with cookies because Session will get automatically destroyed when user closes browser but this isn't true with cookie.

这篇关于加载页面中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆