How to Uncategorized

PHP redirect script with Log Management by $_GET METHOD

How to redirect a visitor to another website with log management?
When you need a PHP redirecting script with Log management . So Here i have written a Script in PHP Language Redirect to another Address with Log management .When you need to redirect a visitor from your site to another URL its come handy to have a full log of user.

Here is a Script available that will log your user’s information & then Redirect them to desired URL .

You can use Either $_GET Method or $_POST Method , but using $_GET method is more clear & responsive.

Jus put these codes & save as PHP

 

<?php
$url=$_GET[“url”];

//you will be redirect to $url by GET method ;
header(“Location: $url“);

//* Script Written by http://www.cstweaks.com/ */

//Log Management
$userip = $_SERVER[“REMOTE_ADDR”];
$logtime = date(“d/m/y H:i:s”);
$dt = new DateTime();
$handle = fopen(“redirectlogs.txt”, “a”);
foreach($_GET as $variable)
{
fwrite($handle, “## “);
fwrite($handle, $url);
fwrite($handle, “\t”);
fwrite($handle, $userip);
fwrite($handle, “\t”);
fwrite($handle, “\t”);
fwrite($handle, $dt->format(‘Y-m-d H:i:s’));
fwrite($handle, “\n”);
}
fclose($handle);
Echo “You will be Redirect to “;
?>
<a href=”<?echo $url?>“>click Here</a>
<? exit();
?>

Let Save this As “go.php” in your website directory & files location will become

http://www.your-site.com/go.php

Now you can pass it web address with parameter “url” by GET method . Now your address will become.

http://www.your-site.com/go.php?url=http://to-be-redirected.com

Live demo of PHP web Redirect Script with LogManagement

http://www.cstweaks.com/go.php?url=http://www.google.com

Your Logs will be saved On same directory with file name – redirectlogs.txt

 

Have Any Query / Trouble ? Feel free to comment below.

Leave a Comment

CommentLuv badge