0

I have this very simple code. Its supposed to go to google when i click on enter, but the php code just pops up on a blank screen. It doesnt execute?

<!DOCTYPE html>

<html>

<head>

</head>


<body>

  <form name="form" action="test.php" method="get">
    <input type="text" name="subject" id="subject" value="Car Loan">
  </form>

</body>



</html>

<?php header('Location: http://google.dk') exit; ?>
Chutney
  • 31
  • 1
  • 1
  • 5

1 Answers1

-1

First of all, be sure you put the PHP code in files whose termination is .php, then check if the web server is configured to run PHP scripts.

You can do this check easily. Write <?php phpinfo(); in a new file (let's name it info.php) and open the file in the browser through the webserver (http://localhost/info.php f.e.). If you see the raw source of the file then your server is not configured to run PHP scripts.


Your PHP script has syntax errors. A semicolon is missing after the call to the header() function and that prevents it to run.

<?php
header('Location: http://google.dk');
exit;

You should enable error reporting and error logging in your php.ini and check the errors log frequently (ideally keep a tail -f php_errors.log always running in a terminal window).

axiac
  • 68,258
  • 9
  • 99
  • 134
  • 1
    While true, that wouldn't cause the source code to be displayed in the browser. It would show a 500 internal server error, so this isn't an answer to the problem described in this question. – Quentin Jun 09 '17 at 09:06
  • @Quentin I guess those blank screen exactly 500 error – Alex Slipknot Jun 09 '17 at 09:08
  • @AlexSlipknot — The question says "**the php code just pops up** on a blank screen". I'll grant you that "blank screen" is a weird way of saying "white background" though. – Quentin Jun 09 '17 at 09:09
  • @Quentin xD well I heard a lot of times about "blank" so In this case it can be "white background". But we don't know sure while hi doesn't explain :) – Alex Slipknot Jun 09 '17 at 09:13
  • Sorry if it wasnt clear. Yes it is a white background, where all my php code is displayed. My coding teacher told me, that even tho PHP is a server side language, it can be ran from a file on the computer. I've used PHP for quite some time, but only on MAMP localhost. Never tried clientside in a file, and i guess that doesnt work unless it does?? – Chutney Jun 09 '17 at 09:23