how to use get method in a session?

前端 未结 1 1797
逝去的感伤
逝去的感伤 2021-01-17 05:55

here is my code. actually i am displaying some data from mysql on the page and creating dynamic link.i want started a session with session_start() in the very begining of co

相关标签:
1条回答
  • 2021-01-17 06:36

    You need to provide a fall-back, in case the URL provided does not contain the proper variables in the $_GET section.

    You have:

    if(isset($_GET['submit'])){
        $_SESSION['session_usn'] = $_GET['usn'];
    }
    

    You should do something else if $_GET['submit'] isn't set:

    if(isset($_GET['submit'])){
        $_SESSION['session_usn'] = $_GET['usn'];
    } else {
        $_SESSION['session_usn'] = "unset";
        // or set a warning flag like "unset"
    }
    

    You should be feeding your php file a url like:

    http://yoururl.com/page1.php?usn='333'
    

    Where 333 is the value you want to store.

    0 讨论(0)
提交回复
热议问题