Does php code with text files (fwrite and so) not work in wordpress?
-
It appears not to be my code because it works in a part of the same hosting where there is no wordpress installation.
-
What do you mean “in wordpress”, are you saying you’ve just moved a file inside a theme directory and it doesn’t work?
No, it’s when I include it. The file itself opened from in the theme works. I also tried without including the file, thus with only the code included, then it doesn’t work. I don’t know if it works with a template, but I want to use it with “search.php”, I don’t see how to make a search page out of a template.
It sounds like a permissions issue if the only thing you’ve done is moved the file.
The permissions I changed also. As you see I edited my former answer.
. I also tried without including the file, thus with only the code included, then it doesn’t work.
Can you re-explain what you mean by this? It doesn’t read well for me (personal opinion).
Sorry.
header <main> ..... <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $search = $_GET['s']; $file=fopen("visitors.txt","a"); fwrite($file, "$search"); fclose($file); ?> </main> footerI’m only trying to get the ‘s’ value written to the text file. It is about searches done on the site.
I see.
Can you post the snippet showing how you’re including the file? Also, can you repeat the theme file you’re editing for this?
And what URL are you accessing to run the file?
The textfile:
http://www.buyonauction.eu/art/wp-content/themes/Auction-art/visitors.txtThe php file:
http://www.buyonauction.eu/art/wp-content/themes/Auction-art/searches_widget.inc.php?s=somesearchheader <main> ..... <?php include('searches_widget.inc.php');> </main> footerSo are you saying the file works when you access it directly:
http://www.buyonauction.eu/art/wp-content/themes/Auction-art/searches_widget.inc.php?s=somesearchThe theme file I edit was ‘search.php’
You reach it from any what page when you do a search but it is on
http://www.buyonauction.eu/art/search.phpBut it has little sense to give that now, as it doesn’t work with an ordinary include, thus <?php include(‘…
Yes that’s what I’m saying.
What happens when you use the full theme path in your include?
Starting from/wp-contentNothing as far as I see. I searched for “Picasso”.
Including the whole path from /domains/ gave an error about a parameter that should be 1.
I wouldn’t include the whole path from domains, just from the ‘wp-content’ bit.
Were you receiving an error message when you started this thread?It wasn’t for the error message when I included the whole path. I found it strange that there was no error message at all without the path. Then I tried it in a part of my hosting where no WordPress is and there it worked. For that reason I came to this forum, I wondered if WordPress blocks that function maybe for safety.
The topic ‘Does php code with text files (fwrite and so) not work in wordpress?’ is closed to new replies.