What is the way of transmitting token between the front end and the back end?

after the user logs in successfully, the daemon will generate a signed token and return it to the browser. When the user wants to make further operations, the token, backend must be provided to the backend to verify that the token is correct before further operations are allowed. But there is a question that I have always wondered, and I can"t find it on the Internet. Most of it is mentioned at once, that is, how does the token generated by the background be returned to the foreground, cookie or header?? Can header support cross-domain? How does the front end transmit token to the back end, url or header?? Can you be more specific about how to do it? for example, I use php to add token to header: header ("Authorization", $token) Why it doesn"t work, and how to set it up? How does php receive the value of the parameter Authorization?
Thank you!

Jun.14,2021

the backend returns token, in cookie,header, or directly in the returned content, depending on which one you like.
personally, I prefer to encapsulate the request function directly in the returned content, and bring the token with each request.

of course, it is also possible to use cookie or header.

it doesn't matter which method. The important thing is to get it right. For example, the landlord made a mistake when setting header in php. If you don't know how to use the function of php, you can look it up in the documentation on the official website: http://php.net/manual/zh/func.

.

take ajax in jQuery.js as an example. Let me write how I use header:

Front end: header.html


api demo token

ajax<br>

<ol> <li>

// :user/login
requestBody: {"tel":"123","pwd":"1234"}
// 
responseBody: {"nickname":"123","token":"123123-123123-123123"}
  • get information from the front end

    // :user/money
    header:  token:123123-123123-123123
    requestBody: {}
    // 
    responseBody: {money:123123}
  • conclusion: just send it back directly with other data without any particularity.

    MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
    MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdbd31-312a0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
    MySQL Errno : 1021
    Message : Disk full (/tmp/#sql-temptable-64f5-1bdbd31-312a0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
    Need Help?