如何获取访问的当前HTML页面并将其存储在PHP中,我的SQL

时间:2019-04-14 08:36:11

标签: php html mysql

我需要将当前查看的页面存储在 php mysql 中。我只有一行html页面,我需要存储数据,例如,如果用户访问关于我们,则该网址后面是about。由于它是单个html页面 index.html ,并且所有菜单都在该 index.html

中提供

我已经有一个 db PHP 代码,但是没有按预期工作

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

我尝试过

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

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

在我的html页面中也包括了

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

PHP版本:5.5和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); 

实际:https://chennaifreelancers.com/get_details.php记录在数据库中,但是

预期:https://chennaifreelancers.com/#about等,我要求将此存储在数据库中

1 个答案:

答案 0 :(得分:0)

您可以在hashchange()事件发生时使用ajax调用

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);
    }
  });
}