I tried to download a file from another website:
I have a problem with the download, PHP scripts executes before downloading:
My code for force the download of the file that I want to download:
$f = $_GET["d"];
header("Content-Disposition: attachment; filename=\"$f\"\n");
$mynum = 5 + 5;
echo "5 plus 5 is" + $mynum;
5 plus 5 is 10
<!-- PHP code was executed during downloading -->
You can't do this, PHP is a server-side language and you are trying tu pull it from client-side, PHP is always executed before it's returned
Client sends a request to the server to execute a PHP script in the server, and server returns the HTML code to client. The attempt of download is a request.
PHP is always executed on the server before return code, and for security reasons, you can't get PHP text as plain. There is not methods to get raw PHP code from server, the only way is downloading file via FTP, so you'd have to know the hostname, username and password of the
www.another_website.com, If you don't know these details, you can't get the PHP file as plain text.