0

I have a multi-site Wordpress installation for a client, and for one of the forms I need to do some manual database interaction as the feature is separate.

The problem I'm having however, is that any simple PHP script I uploaded to anywhere on the site is throwing an "end of script output before headers" error according to the logs.

The script is literally only echo-ing "hello world", and the permissions are set to 755.

Is there something to do with Wordpress that could be causing this issue? The entire site works completely fine otherwise. It's confusing to say the least

Is there something I need to include that's Wordpress specific to the file at the beginning?

There is no code to share really - there is an html form:

<form action="<?php bloginfo('template_directory') ?>/add-calories.php" method="get" id="add-calories">
    <input class="required" type="text" name="item" placeholder="Food or Drink">
    <input class="required" type="number" name="calories" placeholder="Calories">
    <input class="required" type="time" name="time" placeholder="Time">
    <input class="required" type="date" name="date" placeholder="Date">
    <button type="submit">Add to diary<i class="fa fa-chevron-right"></i></button>
</form>

Initially the php script this form points to echo'd out the $_POST variables, but currently it simply reads:

<?php
    echo "hello world!";
?>

I have tried checking for headers being sent with headers_sent(), but that didn't seem to help much either...

6
  • What's the script you are using and where exactly you are placing the script?
    – bravokeyl
    Commented Apr 19, 2016 at 17:00
  • how are you including that script? through some hook? which one? Commented Apr 19, 2016 at 17:32
  • It's a simple script used as a form action - not wordpress, no hooks, just an empty script that does nothing. Can't even echo out "hello" :/ @bravokeyl
    – Solflux
    Commented Apr 19, 2016 at 20:29
  • @NabeelKhan It isn't included, it's just stored at the base of the theme. The form action passes some POST variables to it. Even without the variables, it just fails giving 500. With the logs saying the error in the title of the question
    – Solflux
    Commented Apr 19, 2016 at 20:32
  • you'll have to share the form code Commented Apr 20, 2016 at 0:57

1 Answer 1

0

Don't know exactly what you are trying to accomplish using custom script.You can do this effectively in WP way using either shortcodes,page templates,plugin.

Well if you don't want to do it that way and want to just place scripts in the active theme base directory.One way i suggest:

Let's say we have two php files aform.php (Actual form page) and add-calories.php (Form action page) in the active theme base directory.

You can rename them to page-aform.php and page-add-calories.php and create two pages with same names aform and add-calories. Then these scripts are available at http://example.com/aform and http://example.com/add-calories(be sure to change form action to req url).

You can check more about template hierarchy here.What ever we place in the theme directory goes through this cycle.

If you don't want to do it that way and want to have http://example.com/aform.php then place the php script file at the root directory of WP installation (Remember if you do this way, file you won't have access to WP functions)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.