passing variable between pages

后端 未结 6 1513
青春惊慌失措
青春惊慌失措 2020-12-22 02:29

Is it good way to pass variable between pages using $_GET method with url:

and take

6条回答
  •  清歌不尽
    2020-12-22 02:52

    It depends on your needs, really, If you are passing search arguments between pages, for example, and the variables should be both persistent and be available to the end user (via bookmarking, for example), then pass them in the URL (but don't usually use quotes like you have around $id in "input_obj.php?id='$id'&method=plain)

    If you are truly passing internal variables between scripts, this is better done via $_SESSION variables. Remember that end users can easily modify variables passed through URLs. Unless they are intended for use by the end user, that may be a real problem. By using $_SESSION, you insulate your script's variables from tampering by the end user when it's necessary to insulate them. (unless, of course, the variables are produced by other user input via GET/POST/COOKIE)

    //page1.php
    session_start();
    $_SESSION['id'] = $id;
    
    //page2.php
    session_start();
    echo $_SESSION['id'];
    

提交回复
热议问题