Sending variables from one PHP page to another

后端 未结 3 1363
长情又很酷
长情又很酷 2021-01-24 17:04

I\'m building a quiz web application that is dynamically generated from a database on my server. I have pretty much implemented all the functionality, the only missing piece is

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-24 17:25

    First of all, tackle one problem at a time first the list of question working then the authentication.

    You should use GET because:

    • $_SESSION is to store things specific to a given user its behaviour and authentication information such as a token.
    • $_POST is for code that modifies the server side (here you only load things from the database).
    • $_GET is to retrieve server-side information which is exactly your case.

    Here loading a question is not something that should be different from one user to another. It will not directly modify something on the server-side. This is why you should use GET. Using something else will work but it is not the proper way to do it.

    So basically what you change is:

    echo '' . $row['title'] . '
    ';

    by

    echo '' . $row['title'] . '
    ';

    And in you quizz page you can now know the id of the question (stored by default in $_GET["qid"]) and do whatever you want with it. This of course can be applied to other variables.

提交回复
热议问题