PHP Pass variable to next page

后端 未结 8 2331
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:11

    Sessions would be the only good way, you could also use GET/POST but that would be potentially insecure.

    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, it is 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!

提交回复
热议问题