omegatroller Posted December 15, 2019 Share Posted December 15, 2019 I have made a website (https://sokk.ga/), and I want to log the users public ip whenever he/she clicks one of the links, and then redirect him/her to the correct url. It's supposed to be a little php "script" between the main page and clicked link. The problem i face is that it shows the php code as plain text in the browser (chrome), no redirect or log. Here's my attempt: <php? date_default_timezone_set("Norway/Oslo"); $ipFile = fopen("../logg/ip.txt"); $ipText = time("Y.m.d" + "-" + "H:i:s") + "-" + $_SERVER['REMOTE_ADDR'] + "\n"; fwrite("$ipText", $ipFile); fclose("../logg/ip.txt"); exit; header("https://sokk.ga/skole/"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/309688-how-to-use-php-to-log-ip-then-redirect-to-url/ Share on other sites More sharing options...
Barand Posted December 15, 2019 Share Posted December 15, 2019 1. Your code needs to open with <?php 2. Your timezone is invalid, use date_default_timezone_set("Europe/Oslo"); 3. If you exit before the redirect, how can it redirect? 4. The concatenation operator in php is "." and not "+" I recommend you turn error reporting on. Quote Link to comment https://forums.phpfreaks.com/topic/309688-how-to-use-php-to-log-ip-then-redirect-to-url/#findComment-1572533 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.