PHP + curl, HTTP POST sample code?

前端 未结 11 2374
北荒
北荒 2020-11-21 04:58

Can anyone show me how to do a php curl with an HTTP POST?

I want to send data like this:

username=user1, password=passuser1, gender=1
11条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 05:43

    A simpler answer IF you are passing information to your own website is to use a SESSION variable. Begin php page with:

    session_start();
    

    If at some point there is information you want to generate in PHP and pass to the next page in the session, instead of using a POST variable, assign it to a SESSION variable. Example:

    $_SESSION['message']='www.'.$_GET['school'].'.edu was not found.  Please try again.'
    

    Then on the next page you simply reference this SESSION variable. NOTE: after you use it, be sure you destroy it, so it doesn't persist after it is used:

    if (isset($_SESSION['message'])) {echo $_SESSION['message']; unset($_SESSION['message']);}
    

提交回复
热议问题