A traceroute can only be executed from the machine that is running the code.
Is the client running the code? Probably not, your server is. So you cannot get what you want.
Something more important: You have a very bad code excution vulnerability! You have to validate that the string containing the IP address contains nothing else.
Please do not use that script online. You will get hacked.