dongxie1907 2018-03-24 12:04
浏览 197
已采纳

单击div时如何设置$ _SESSION变量

In my portfolio I implemented a PHP script that generate some div that contain images of some works. When users click on a div, there is a redirect on a details.php page that contains work details. How can I set $_SESSION variable values, in order to use them on details.php?

PHP scipt:

$query2="SELECT * FROM Posts WHERE Category='".$record1['Category']."' ORDER BY data_pubb DESC";
            $esito2 = mysql_query($query2);
            while($record2 = mysql_fetch_array($esito2))
            {
                echo "
                    <div class='col-sm-4 job'>
                        <div class='container hover-image-container'>
                            <a href=''>
                                <img src='".$record2['static_img']."' data-src='".$record2['static_img']."' data-animated-src='".$record2['dinamic_img']."' width='100%' height='100%' />
                                <div class='overlay'>
                                    <div class='text'>".$record2['title']."</div>
                                </div>
                            </a>
                        </div>
                    </div>
                        ";
            }
  • 写回答

3条回答 默认 最新

  • duanquyong8164 2018-03-24 12:18
    关注

    You would need to use JavaScript to detect the onclick and use AJAX to start the session.

    For starters, add session_start(); to the top of your page.

    Then add an onclick event to your div:

    <div class='col-sm-4 job' onclick='startsession()`>
    

    Then define the startsession() function:

    function startsession() {
       $.ajax({
          var name = ''; // the name of your session e.g $_SESSION['counters'];
          var value = ''; // the value of your session e.g 10
          url: "sessionstart.php",
          data: {session: name, value: value},
          success: function(data){
             // your success function
          }
       });
    }
    

    Then on sessionstart.php:

    <?php 
    session_start();
    $_POST['name'] = $_POST['value'];
    <?
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多