dpbdl44228 2019-04-14 08:36
浏览 81

如何获取当前访问的html页面并存储在php我的sql中

I need the currently viewed page to be stored in php mysql. I have a single line of html page and i need to store the data like if users visit about us then the url followed by about. Since it is a single html page index.html and all the menus are provided within that index.html

I already have a db and PHP code but did not work as expected

 $page = "https://chennaifreelancers.com".$_SERVER['HTTPS_HOST']."".$_SERVER['PHP_SELF'];

I tried

$page="https://chennaifreelancers.com".$_SERVER['HTTPS_HOST']."".$_SERVER['index.html']; 

and

$page="https://chennaifreelancers.com".$_SERVER['HTTPS_HOST']."".$_SERVER['SERVER_NAME'];

Included this as well in my html page

<header class="bgimg-1 w3-display-container w3-grayscale-min" id="home" form method="post" action="get_details.php">

PHP Version: 5.5 and Maria DB: 10.2

#get_details.php

<?php
// require ReCaptcha class

  require_once("DBConfig.php");

 $ipaddress = $_SERVER['REMOTE_ADDR'];
 $page= https://chennaifreelancers.com".$_SERVER['HTTPS_HOST']."".$_SERVER['index.html'];
 $referrer = $_SERVER['HTTP_REFERER'];
 $datetime = date("F j, Y, g:i a");
 $useragent = $_SERVER['HTTP_USER_AGENT'];


$query = mysql_query("SELECT `ip` FROM `visitors_table` WHERE `ip` = '$ip' ");
if(mysql_num_rows($query)> 0) { // if return 1, email exist.

} else { // else not, insert to the table

  $query = mysql_query("INSERT INTO `visitors_table` (`ip` ,`current_page`,`referrer`,`time` ,`user_agent`)
                            VALUES ('$ipaddress','$page','$referrer','$datetime','$useragent')");


    $result=mysql_query($query);




     $result=mysql_query($query);




    } 



 close($query); 

Actual : https://chennaifreelancers.com/get_details.php this is recorded in the DB but

Expected: https://chennaifreelancers.com/#about etc i require this to be stored in DB

  • 写回答

1条回答 默认 最新

  • douliao5467 2019-04-14 09:08
    关注

    You could do with ajax call while hashchange() event

    window.addEventListener("hashchange", store, false);
    
    function store() {
      //call get_details.php via ajax call
      $.ajax({
        type: "post",
        url: "get_details.php",
        success: function(response) {
          $("#responsecontainer").html(response);
        }
      });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题