将变量从第一页传递到 PHP 中的第三页 [英] Passing variable from 1st page to 3rd page in PHP

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

问题描述

我需要将一个变量从第一页传递到第三页,我该怎么做?

I need to pass a variable from page one to third page how do I make it?

  • 我可以将变量从 1 页传递到下一页
  • 如何将变量从第一页传递到第二页,并将相同的值传递到第三页

这是例子

<a href="page2.php?myname=Suraj Mittal&age=22&fav_color=White&fav_fruit=Grapes">Click here to send variables in the URL</a>

第二页

<?php
 $name = $_GET['myname'];
$age = $_GET['age'];
$color = $_GET['fav_color'];
$fruit = $_GET['fav_fruit'];
        echo "My name is ".$name.". and I am ".$age." years old. My favourite color is ".$color." and my favourite fruit is ".$fruit.".";
?>

推荐答案

你可以使用 session 来做到这一点

You can use session to do this

 session_start();

 $_SESSION["myname"] = $_GET['myname'] ;

 $_SESSION["age"] = $_GET['age'] ;

然后你可以在任何页面上访问这个SESSION variables.

and then you can access this SESSION variables on any page.

在你想要访问年龄的页面上,这样做

on your page where u want to access age, do like this

$age=$_SESSION["age"] ;

这篇关于将变量从第一页传递到 PHP 中的第三页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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