


Teach you step by step how to do a keyword matching project (search engine) ---- On the thirteenth day, teach you how to do it on the thirteenth day_PHP tutorial
Teach you step-by-step how to do keyword matching projects (search engines)----On the thirteenth day, teach you how to do it on the thirteenth day
Thirteenth day
Ever since Xiao Shuai Shuai was gangbanged by Mr. Yu, I feel very unhappy because there is this reason: I have done what you want, why can’t I get recognition.
What kind of programmer is good? Xiao Shuai Shuai went to understand the design pattern with such questions.
Although he has read design patterns many times, he even knows the names of design patterns by heart, such as singleton pattern, abstract factory pattern, builder pattern, factory pattern, prototype pattern...etc.
But Xiao Shuaishuai still didn’t know how to use it. He had no choice but to ask Boss Yu again. Boss Yu gave him a copy of the code to look at and see what design patterns were used in it.
What kind of programmer is good? Some people say that good programmers write code that can be read, while ordinary programmers write code that can run.
Yu Boss’s code is as follows:
<?<span>php </span><span>class</span><span> SelectorItem { </span><span>private</span> <span>$item</span><span>; </span><span>public</span> <span>function</span> __construct(<span>$item</span><span>){ </span><span>$this</span>->item = <span>$item</span><span>; } </span><span>public</span> <span>function</span> __get(<span>$name</span><span>){ </span><span>if</span>(<span>isset</span>(<span>$this</span>->item-><span>$name</span><span>)){ </span><span>return</span> <span>$this</span>->item-><span>$name</span><span>; } </span><span>return</span> <span>null</span><span>; } </span><span>public</span> <span>static</span> <span>function</span> createFromApi(<span>$num_iid</span><span>){ </span><span>$client</span> = <span>new</span><span> TopClient(); </span><span>$client</span>->appkey = 'xx'<span>; </span><span>$client</span>->secretKey = 'xx'<span>; </span><span>$req</span> = <span>new</span><span> ItemGetRequest(); </span><span>$req</span>->setFields('props_name,property_alias,detail_url,cid,title'<span>); </span><span>$req</span>->setNumIid(<span>$num_iid</span><span>); </span><span>$resp</span> = <span>$client</span>->execute(<span>$req</span><span>); </span><span>if</span>(<span>isset</span>(<span>$resp</span>-><span>code)){ </span><span>#</span><span> error handle</span> <span>throw</span> <span>new</span> <span>Exception</span>(<span>$resp</span>->msg, <span>$resp</span>-><span>code); } </span><span>return</span> <span>new</span> self(<span>$resp</span>-><span>item); } } </span><span>class</span><span> CharList { </span><span>private</span> <span>$core</span> = <span>array</span><span>(); </span><span>private</span> <span>$blacklist</span> = <span>array</span><span>(); </span><span>public</span> <span>function</span> addCore(<span>$char</span><span>){ </span><span>if</span>(!<span>in_array</span>(<span>$char</span>,<span>$this</span>-><span>core)) </span><span>$this</span>->core[] = <span>$char</span><span>; } </span><span>public</span> <span>function</span><span> getCore(){ </span><span>return</span> <span>$this</span>-><span>core; } </span><span>public</span> <span>function</span> addBlacklist(<span>$char</span><span>){ </span><span>if</span>(!<span>in_array</span>(<span>$char</span>,<span>$this</span>-><span>blacklist)) </span><span>$this</span>->blacklist[] = <span>$char</span><span>; } </span><span>public</span> <span>function</span><span> getBlacklist(){ </span><span>return</span> <span>$this</span>-><span>blacklist; } } </span><span>abstract</span> <span>class</span><span> CharListHandle { </span><span>protected</span> <span>$charlist</span><span>; </span><span>public</span> <span>function</span> __construct(<span>$charlist</span><span>){ </span><span>$this</span>->charlist = <span>$charlist</span><span>; } </span><span>abstract</span> <span>function</span> <span>exec</span><span>(); } </span><span>class</span> MenCharListHandle <span>extends</span><span> CharListHandle { </span><span>public</span> <span>function</span> <span>exec</span><span>(){ </span><span>$this</span>->charlist->addCore("男装"<span>); </span><span>$this</span>->charlist->addBlacklist("女"<span>); } } </span><span>class</span> WomenCharListHandle <span>extends</span><span> CharListHandle{ </span><span>public</span> <span>function</span> <span>exec</span><span>(){ </span><span>$this</span>->charlist->addCore("女装"<span>); </span><span>$this</span>->charlist->addBlacklist("男"<span>); } } </span><span>#</span><span> 其他CharList Handle小帅帅完成</span> <span>class</span><span> Selector { </span><span>private</span> <span>static</span> <span>$charListHandle</span> = <span>array</span><span>( </span>"男装"=>"MenCharListHandle", "女装"=>"WomenCharListHandle", "情侣装"=>"LoversCharListHandle", "童装"=>"ChildrenCharListHandle"<span> ); </span><span>public</span> <span>static</span> <span>function</span> select(<span>$num_iid</span><span>){ </span><span>$selectorItem</span> = SelectorItem::createFromApi(<span>$num_iid</span><span>); Logger</span>::trace(<span>$selectorItem</span>-><span>props_name); </span><span>$matchTitle</span> = <span>$selectorItem</span>->title.<span>$selectorItem</span>-><span>props_name; </span><span>$charlist</span> = <span>new</span><span> CharList(); </span><span>foreach</span>(self::<span>$charListHandle</span> <span>as</span> <span>$matchKey</span>=><span>$className</span><span>){ </span><span>if</span>(<span>preg_match</span>("/<span>$matchKey</span>/",<span>$matchTitle</span><span>)){ </span><span>$handle</span> = self::createCharListHandle(<span>$className</span>,<span>$charlist</span><span>); </span><span>$handle</span>-><span>exec</span><span>(); } } </span><span>//</span><span>do search things </span> <span> } </span><span>public</span> <span>static</span> <span>function</span> createCharListHandle(<span>$className</span>,<span>$charlist</span><span>){ </span><span>if</span>(<span>class_exists</span>(<span>$className</span><span>)){ </span><span>return</span> <span>new</span> <span>$className</span>(<span>$charlist</span><span>); } </span><span>throw</span> <span>new</span> <span>Exception</span>("class not exists",0<span>); } }</span>
After Xiao Shuaishuai read the code, he couldn’t hold it any longer . This is the legendary Boss Yu, and he didn’t copy my code. . .
What would Boss Yu do if he heard Xiao Shuai Shuai’s thoughts?
Xiao Shuai Shuai can’t continue to study the magic secrets.

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)
