在页面之间传递变量 [英] passing variable between pages

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

问题描述

 < a href =input_obj 

使用$ _GET方法在页面之间传递变量是一种很好的方法。 .php?id ='$ id'& method = plain

并将其放在文件input_obj中。 PHP代码如下:

$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ = $ _GET [ 'method'];

OR



使用会话 - 有人想法如何?

解决方案

这取决于您的需求,真的,如果您在页面之间传递搜索参数,例如,变量应该是持久的并且对最终用户可用(例如,通过书签),然后在URL中传递它们(但通常不使用像 $ id in input_obj.php?id ='$ id'& method = plain



如果您真的在脚本之间传递内部变量,最好通过 $ _ SESSION 变量完成。请记住,最终用户可以轻松修改通过URL传递的变量。除非它们打算供最终用户使用,否则这可能是一个真正的问题。通过使用 $ _ SESSION ,您可以在最终用户需要将它们隔离时防止脚本变量被篡改。 (除非,当然,这些变量是由其他用户通过GET / POST / COOKIE输入的)

  // page1.php 
session_start();
$ _SESSION ['id'] = $ id;

//page2.php
session_start();
echo $ _SESSION ['id'];


Is it good way to pass variable between pages using $_GET method with url:

<a href="input_obj.php?id='$id'&method=plain

and take it in file input_obj.php with such code:

$id = $_GET['id'];
$method = $_GET['method'];

OR

using session - has someone idea how?

解决方案

It depends on your needs, really, If you are passing search arguments between pages, for example, and the variables should be both persistent and be available to the end user (via bookmarking, for example), then pass them in the URL (but don't usually use quotes like you have around $id in "input_obj.php?id='$id'&method=plain)

If you are truly passing internal variables between scripts, this is better done via $_SESSION variables. Remember that end users can easily modify variables passed through URLs. Unless they are intended for use by the end user, that may be a real problem. By using $_SESSION, you insulate your script's variables from tampering by the end user when it's necessary to insulate them. (unless, of course, the variables are produced by other user input via GET/POST/COOKIE)

//page1.php
session_start();
$_SESSION['id'] = $id;

//page2.php
session_start();
echo $_SESSION['id'];

这篇关于在页面之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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