<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                  在首頁,點“購買”后,將商品添加到購物車。   第一步:建立buy.php 在cart根目錄下建立buy.php. 代碼: ~~~ <?php $id=$_GET['id']; echo 'goods ID '.$id.', Test Success buy.php'; ?> ~~~   $_GET[id],接收點擊“購買”按鈕后,首頁傳過來的參數id。   echo行,輸出id參數。 * * * * *   打開首頁,點“購買”按鈕,打開buy.php頁,顯示:   goods ID 4, Test Success buy.php   說明測試成功,完成了buy.php頁面正常顯示和參數傳遞 * * * * *   第二步:進行正式代碼書寫 ~~~ <?php //啟用SESSION功能. session_start(); //設置網頁字符集,否則,提示時會出現亂碼. header("Content-type:text/html;charset=utf8"); //判斷是否有goodsid和goodsnum的SESSION記錄. if(!isset($_SESSION['goodsid']) && !isset($_SESSION['goodsnum'])){ //給goodsid和goodsnum的SESSION變量賦值. $_SESSION['goodsid']=$_GET['id'].'@'; $_SESSION['goodsnum']='1'.'@'; }else{ //將SESSION['goodsid']變量分割開,這樣便于后邊判斷. $array=explode('@',$_SESSION['goodsid']); //判斷新傳來的商品id是否已在goodsid中. if(in_array($_GET['id'],$array)){ //如果存在,則出現提示. echo "<script>alert('此商品已在購物車里!');history.back();</script>"; //退出程序,即下邊代碼不再執行. exit; }//if end. //如果檢測goodsid的SESSION數組變量中沒有此商品id,則將此商品id賦值給SESSION數組. //注意,此時賦值與上邊稍有不同,看等式.".="用此表達式,意思將新id添加到原變量后邊. $_SESSION['goodsid'].=$_GET['id'].'@'; $_SESSION['goodsnum'].='1'.'@'; }//if end. var_dump($_SESSION['goodsid']); //最后,將跳轉到購物車頁。 echo "<script>window.location.href='shopping_car.php';</script>"; ?> ~~~     往購物車中添加商品后,因為有可能更改數量等,所在是臨時性存儲,一定要用到SESSION功能([SESSION詳解](http://www.w3school.com.cn/php/php_sessions.asp))。   所以,必須先開啟session_start(); * * * * *   isset($_SESSION['goodsid'])   isset(),此函數是檢測變量是否設置。 $_SESSION[],設置SESSION變量. * * * * *   explode('@',$_SESSION['goodsid']) explode('字符',字符串),以某個字符為標記,分解字符串,分解后將以數組形式出現。 * * * * *   in_array($_GET['id'],$array)   in_array(),搜索數組中是否存在指定的值。   搜索$array數組中是否含有新傳遞過來的商品id.   如果有,則出現js代碼提示。   如果沒有,則將新購商品id添加到SESSION['goodsid']數組中,重點注意表達式“.=”,這是字符串連接表達式。 * * * * *   window.location.href='shopping_car.php'   是js代碼的跳轉代碼。shopping_car.php是購物車頁。下一節講解。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看