Jump to content

How to use PHP to log ip, then redirect to url

Recommended Posts

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:




$ipFile = fopen("../logg/ip.txt");

$ipText = time("Y.m.d" + "-" + "H:i:s") + "-" + $_SERVER['REMOTE_ADDR'] + "\n";

fwrite("$ipText", $ipFile);





Share this post

Link to post
Share on other sites

1. Your code needs to open with <?php

2. Your timezone is invalid, use


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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.