passing variables from php file to anther

前端 未结 4 1196
[愿得一人]
[愿得一人] 2021-01-23 04:11

How to pass variables from a php file to another while it is not html inputs ,just i have a link refer to the other file and i want to pass variables or values to it

Exa

相关标签:
4条回答
  • 2021-01-23 04:36

    You can use URLs to pass the value too.

    like

    index.php?id=1&value=certain
    

    and access it later like

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

    However, POST might be much reliable. Sessions/Cookies and database might be used to make the values globally available.

    0 讨论(0)
  • 2021-01-23 04:42

    Try to use sessions. Or you can send a GET parameters.

    0 讨论(0)
  • 2021-01-23 04:42

    Here's one (bad) solution, using output buffering:

    File 1:

    <?php
        $name = 'OdO';
        echo '<a href="File2.php">Go To File2</a>';
    ?>
    

    File 2:

    <?php
        ob_start();
        include 'File1.php';
        ob_end_clean();
    
        echo $name;
    ?>
    
    0 讨论(0)
  • 2021-01-23 04:57

    Use sessions to store any small value that needs to persist over several requests.

    File1.php:

    session_start();
    $_SESSION['var'] = 'foo';
    

    File2.php:

    session_start();
    $var = $_SESSION['var'];  // $var becomes 'foo'
    
    0 讨论(0)
提交回复
热议问题