I have a new domain which has an
index.php file. Inside this file, I get user's IP, save it and redirect to another page on another domain. So there is no output, only header info. Will Google index this domain?
No, they will not. Search engines follow redirects and the final landing page gets credit for any links, etc, that the original URL has. So that first domain will have no SEO value. So doing this like having a keyword rich domain redirect to another domain has no value and isn't worth doing (as an example).
To follow up on this, search engines don't see nor care where a redirect comes from. So a redirect from PHP or htaccess or something else are all the same to them.