How to pass variables between php scripts?

前端 未结 7 1961
梦如初夏
梦如初夏 2020-12-03 15:15

Is there any way to pass values and variables between php scripts?

Formally, I tried to code a login page and when user enter wrong input first another script will

7条回答
  •  旧巷少年郎
    2020-12-03 15:38

    The quick way would be to use either global or session variables.

    global $variable = 'something';
    

    The 'better' way of doing it would be to include the script and pass the variable by parameter like

    // script1.php contains function 'add3'
    function add3( $value ) {
      return $value + 3;
    }
    
    // script2.php
    include "script1.php";
    echo 'Value is '.add3(2); // Value is 5
    

提交回复
热议问题