Cookies record the path of a user's browsing product

Source: Internet
Author: User

In the e-commerce Web site, the user's browsing path is often recorded to determine which items the user is interested in, or which products are related.

The following will use cookies to record the user's browsing history page. The site stores the title of each page in the $title variable for that page, adding the newly visited title to the COOKIE variable $_cookie["History" value each time the user accesses it.

As the number of pages visited increases, the string that is stored in the cookie variable that contains the page title is getting longer. Cut the cookie variable into an array. Then output the value of the array element to output the title of the page that the user recently visited.

<?PHP/** * @Authors Peng--jun * @Email [Email protected] * @Date 2015-11-07 11:16:05 * @Linkhttp://www.cnblogs.com/xs-yqz/* @version $Id $ ==========================================*/Header ("content-type:text/html; Charset=utf-8"); Ob_start ();//Open buffers so that you can set cookies after you have output$TITLE ="Journey to the";//The product page has many, other product page title is the water Margin, the journey to the monkey and so on? ><! DOCTYPE html>"en">"UTF-8"> <title><?= $TITLE?></title>Similar Products:<a href="hlm.php"> Red Mansions </a> <a href="shz.php"> Marsh </a> <a href="sg.php"> Kingdoms </a> </p> <?php require ("4.22.php");?></body>
sg.php page Code
<?PHP/** * @Authors Peng--jun * @Email [Email protected] * @Date 2015-11-07 11:23:26 * @Linkhttp://www.cnblogs.com/xs-yqz/* @version $Id $ ==========================================*/Header ("content-type:text/html; Charset=utf-8"); Ob_start ();//Open buffers so that you can set cookies after you have output$TITLE ="Kingdoms";//The product page has many, other product page title is the water Margin, the journey to the monkey and so on? ><! DOCTYPE html>"en">"UTF-8"> <title><?= $TITLE?></title>Similar Products:<a href="hlm.php"> Red Mansions </a> <a href="shz.php"> Marsh </a> <a href="sg.php"> Kingdoms </a> </p> <?php include ("4.22.php")?></body>

The rest of the shz.php and hlm.php page content consistent, but $title variable value changed, the rest has not changed.

4.22.php

<?PHP/** * @Authors Peng--jun * @Email [Email protected] * @Date 2015-11-07 11:25:06 * @Linkhttp://www.cnblogs.com/xs-yqz/* @version $Id $ ==========================================*/Header ("content-type:text/html; Charset=utf-8"); $history= $_cookie[" History"];//get cookies that record browsing history if($history = ="") {$path= $TITLE;//saves the title of the current page to the PATH variable}Else{$path= $TITLE."/". $history;//Adds the title of the current page to the front of the browsing history and splits it with the "/" symbol } //save $path to the cookie variable, set the expiration time to 1 daysSetcookie (" History", $path, Time () +3600*1); $arrPath= Explode ("/", $path);//splits the $path into an array explode () function foreach($arrPath as$key =$value) {     if($key >9) Break;//output only the last 10 data foreach is used to iterate over an arrayEcho ($key +1).".". $value."<br/>";//Output Browsing History }?>

Cookies record the path of a user's browsing product

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.