生成自定义数字,将其保存到文本文件中,并将数字作为名称,然后重定向到该文本

I'm working on a program that has a premium section to it, but it must be bought through a website, so what I need is that after the PayPal Purchase (If you can include the code that even better) you get sent to a page that generates a custom number and then saves it to a text file with "Your custom number is: x" then the viewer gets redirected to it, the file must be called the number for the program to function with it

I have some code:

<?php
$x=rand(15455, 15875868);
$content = "$x";
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/" + $x + ".txt","wb");
fwrite($fp,$content);

fclose($fp);
?>

I just can't get it so that the user is redirect to the file once done, but also to make it so that people can't refresh/go back and get a new one....

If I have made this question unclear of what I need help with, please reply! Thanks! :D

Add this to end of your script.

header("location: /{$x}.txt");