PHP Pass variable to next page

后端 未结 8 2322
Happy的楠姐
Happy的楠姐 2020-11-21 06:40

It seems pretty simple but I can\'t find a good way to do it.

Say in the first page I create a variable

$myVariable = \"Some text\";
<
8条回答
  •  感情败类
    2020-11-21 07:09

    Passing data in the request

    You could either embed it as a hidden field in your form, or add it your forms action URL

     echo '';
    

    or

    echo '
    ";

    Note this also illustrates the use of htmlentities and urlencode when passing data around.

    Passing data in the session

    If the data doesn't need to be passed to the client side, then sessions may be more appropriate. Simply call session_start() at the start of each page, and you can get and set data into the $_SESSION array.

    Security

    Since you state your value is actually a filename, you need to be aware of the security ramifications. If the filename has arrived from the client side, assume the user has tampered with the value. Check it for validity! What happens when the user passes the path to an important system file, or a file under their control? Can your script be used to "probe" the server for files that do or do not exist?

    As you are clearly just getting started here, its worth reminding that this goes for any data which arrives in $_GET, $_POST or $_COOKIE - assume your worst enemy crafted the contents of those arrays, and code accordingly!

提交回复
热议问题