how to pass value from one php page to another using session

后端 未结 2 1612
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 08:04

I can pass values form one page to another but I need to pass value like this,

Page 1:

Page4.php

Page3.php

I need to pass the value in a t

2条回答
  •  粉色の甜心
    2020-11-30 09:04

    Use something like this:

    page1.php

    
    

    Any other PHP page:

    
    

    A few notes to keep in mind though: You need to call session_start() BEFORE any output, HTML, echos - even whitespace.

    You can keep changing the value in the session - but it will only be able to be used after the first page - meaning if you set it in page 1, you will not be able to use it until you get to another page or refresh the page.

    The setting of the variable itself can be done in one of a number of ways:

    $_SESSION['myValue']=1;
    $_SESSION['myValue']=$var;
    $_SESSION['myValue']=$_GET['YourFormElement'];
    

    And if you want to check if the variable is set before getting a potential error, use something like this:

    if(!empty($_SESSION['myValue'])
    {
        echo $_SESSION['myValue'];
    }
    else
    {
        echo "Session not set yet.";
    }
    

提交回复
热议问题