Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 跟踪数据库中缓存的重定向(重定向时数据库未初始化)_Php_Mysql_Database_Caching_Redirect - Fatal编程技术网

Php 跟踪数据库中缓存的重定向(重定向时数据库未初始化)

Php 跟踪数据库中缓存的重定向(重定向时数据库未初始化),php,mysql,database,caching,redirect,Php,Mysql,Database,Caching,Redirect,我正在寻找一种服务缓存重定向(通过文件系统)的方法。因此,我将有一个/cache/文件夹,其中包含“google.txt”等文件,并使用文件\u put\u contents()insert'http://www.google.com'输入到'google.txt'文件中 问题是我想实际跟踪ip的、视图等。。在数据库中,但我希望尽快重定向用户。因此,我创建了一个简单的标志函数。下面是一些伪代码以更好地说明: if redirect_is_cached() //True if google.txt

我正在寻找一种服务缓存重定向(通过文件系统)的方法。因此,我将有一个/cache/文件夹,其中包含“google.txt”等文件,并使用文件\u put\u contents()insert'http://www.google.com'输入到'google.txt'文件中

问题是我想实际跟踪ip的、视图等。。在数据库中,但我希望尽快重定向用户。因此,我创建了一个简单的标志函数。下面是一些伪代码以更好地说明:

if redirect_is_cached() //True if google.txt exists
   redirect_to_link() //actual redirect header(location:...)
   user_was_redirected_via_cache(TRUE) //STATIC: defaults to FALSE if no parameter is used.
   //No exit because I want to track data but database isn't loaded.

...

code snipped out...later on in the script.
...

db_connect(); //Now we can access the database

   if(user_was_redirected_via_cache()) { //TRUE since we flagged it earlier.
     track_redirect(); 
     exit();// Proper exit. We redirect user quickly, 
            // but continue script so we can track redirect.

   }
   else { continue with rest of script }
我的问题是1)这是遵循“最佳实践”还是有点黑客行为?2)用户是否开始在header()或exit()处重定向?如果用户在我实际退出()脚本之前没有开始重定向…这是毫无意义的

谢谢你的帮助