PHP Public Development Note series
Date: 2014.9.2
The main task today is to deal with the cached information that was mentioned yesterday, and I need to save some messages to make two judgments.
First, write some knowledge of PHP syntax.
1. Connection syntax for strings in PHP:
In Lua, the connection of two strings is simple, with two strings "AAA" added; BBB "; These two strings need to be concatenated together, with only two periods. Then you can: "AAA". "BBB"; Note here that the string and period directly need a space, no space will be error;
In PHP, the connection requires only a period: "AAA". " BBB "; And there is no need to force a space between the string and the period;
2. Get time, convert to date format:
Using the DATE function, the format is: Date (' y-m-d h:i:s ', Time ()); it's quite simple, record it.
Public platform development needs to complete the progress.
Now go back to the task that was left yesterday: Use the session cache to record information and implement the menu we envision:
PHP in the use of the session, I am not very clear, so always degree Niang Niang, toss A, finally is to achieve my functional requirements, but still feel that there are some deficiencies, left to fix it later.
Yesterday mentioned, I want to implement the menu, hoping to remember the last message. That is, to remind users to input queries, into the Query menu, after the user sent over "query", the next message should be transferred to the Query menu, that is, I need to remember the user sent "query" this information. In the degree of Niang for a long time, found to either use the database, or use the session, in PHP with the database will not, and then I feel that the simple process to remember that information should not need to use the database, so using the session.
Use the session to achieve our needs:
PHP in the specific how to use the session, after still need to degree Niang to learn more, now we are just simple use.
When accessing the material, some netizens mentioned using the user's username as the unique ID, so that the information stored for each user will be inconsistent (because we are now sending messages to the server, each user will send a message, can not affect the use of other users), so the code is implemented as follows:
session_id ($POSTOBJ->fromusername); This is the user name in the XML packet that the server post comes in, using this as the ID
Session_Start (); Is this supposed to mean opening the session?
It's not clear where I put these two lines of code, and now I'm putting this code in the Responsemsg function, and I don't know if that's the case, and the test behind it is useful.
After the session is opened, the information is recorded:
$_session[' menu_type ' = $this->getusermenu ($textWord); The getusermenu here is the function I used to get the menu type based on the user input, and the record information is used in the $_session variable, which is used in an array form??
After we have recorded the information, we should make a judgment of the information and use it to:
Isset ($_session[' menu_type '); Use Isset to determine if we set this value so that we can tell if the user has selected a menu.
Then, when we don't need to use it, we use the following function to destroy this:
unset ($_session[' menu_type ');
By making the appropriate adjustments in the code, we can achieve our needs. And now I think the lack of place is, when should I destroy the saved user selected menu type? If the user chooses the "Query" menu, then we are in response to the user's query behavior, at least in the process of user queries we should not destroy the saved menu type. I feel reasonable. There are three situations where the user has turned off the dialog box (that is, the user has exited the chat box with our public number, but has not found out how to know that the user exited); The user has not performed a query operation for a long time (that is, the user selects the "Query" menu, After a given time does not perform the corresponding query operation, this time automatically destroyed); Finally, the user automatically chooses to exit. Do not destroy the information of the record, there will be a problem, the user selected the "Query" menu, and then the user quit the chat with the public number, the next time to enter the time, will also save the record user selected menu information, it is not reasonable to feel this.
Put aside the above mentioned problem, at least this step we need the function is realized, the problem slowly fix it.