0

I'm new to coding and mostly self-taught through W3Schools and such, so bear with me.

I have a VPS that uses a Linux system. I'm creating a website for a tabletop RPG. My webpage files are mostly written in html, but are .php files since I want to use a little bit of that (mostly the "include" function, which is the source of my issue). Because of Linux, when I upload these files to the server, I go into the "home" folder, then a folder named after my username, then the "public_html" folder, so if I'm understanding the terminology correctly, I should refer to public_html as the "root directory."

So in that root directory, I have various folders and the aforementioned .php files which create the structure of my site, and all of that works fine; the site is viewable online and all. For my webpages, I use the include function to, well, include things like the header, footer, and sidebar on each page, which works fine.

In the root directory, I made a folder called "obj". This contains a large number of small .php files that are not full webpages, but rather each merely contain a set of variables that represent character stats for the RPG. So for example, one such file, called "obj.StickmanSoldier.php", has the following contents:

<?php include 'class.Character.php';
$stickmansoldier = new Character();
$stickmansoldier->name = array('Stickman Soldier','Standard Stickman Soldier');
$stickmansoldier->affinity = 'Ice';
$stickmansoldier->xp = 19;
$stickmansoldier->hp = 20;
$stickmansoldier->vp = 20;
$stickmansoldier->mp = 5;
$stickmansoldier->attack = 2;
$stickmansoldier->strength = 4;
$stickmansoldier->handeye = 5;
$stickmansoldier->platform = 3;
$stickmansoldier->weight = 3;
$stickmansoldier->icemod = '+2';
?>

I guess for clarification, that "class.Character.php" file looks like this:

<?php class Character {
public $name='???';
public $player='Maestro';
public $affinity='Earth';
public $level=0;
public $xp=0;
public $hp=1;
public $badge_hp=1;
public $current_hp=0;
public $vp=0;
public $badge_vp=0;
public $current_vp=0;
public $mp=0;
public $badge_mp=0;
public $current_mp=0;
public $status='Normal';
public $bal=0.00;
public $attack=1;
public $magic=1;
public $defense=0;
public $brain=1;
public $strength=1;
public $handeye=1;
public $platform=1;
public $knowledge=1;
public $clever=1;
public $charisma=1;
public $weight=1;
public $ap=0;
public $earthmod='--';
public $icemod='--';
public $watermod='--';
public $windmod='--';
public $firemod='--';
public $thundermod='--';
public $poisonmod='--';
public $plantmod='--';
} ?>

So in a webpage file, I can use <?php include 'obj.StickmanSoldier.php';?> to call these stats and then use other code (like php's "echo") to display them on that page. If the page is down in a subfolder, it might instead look something like <?php include '../../obj.StickmanSoldier.php';?> , but you get the idea. It's the same include method that I'm using for the header and footer and stuff, and it works fine for those. It also works fine when I call one of these stat files.

One.

If I include more than one of these stat files on the same webpage, then all of a sudden, all code on the page after the second include stops working, giving me a mostly blank page. Or a half-blank page if I put the include halfway down.

Now, when I say "the second include," that's ignoring the includes for the header and footer stuff, because those are there, the same as they are on all the other site pages. And if I only include one of the stat files from the obj folder, then everything works fine; I can display those stats in various forms by using the variables defined in that stat file. But when I try to include multiple stat files in the same webpage file... it does this shit.

I've checked for typos, and I've switched around which stat files I'm including, so it's not a problem with one particular stat file. There are 983 files in the obj folder, so... I'm hoping I don't have to edit all of them. But it doesn't seem like the contents are the problem. Something is just going screwy with the include function.

I haven't created a php.ini file, so if I have one, it's just the default one that came with my server. I also only named the stat files "obj.Whatever.php" because I saw somebody doing that somewhere; the "obj." part serves no function for anything I'm doing, so I can change the names if I need to, if for some reason the extra dot is causing the problem. But none of these explanations make sense given that some of the includes do work.

My site is at http://arpeggiosystem.com/ ; it's incomplete, so some of the links are broken and stuff, but if you want to see the result of this include-induced semi-blank page phenomenon I'm describing, go to http://arpeggiosystem.com/default/enemy/stick.php

EDIT: Ohhhhh... is it because all of the stat files use the include function to call the class file? Does it not like that that gets called more than once on the same page?

  • Note that the closing `?>` tag at the bottom of an included file is redundant. If you omit it then PHP just reads to the end of the file and carries on. If you include it, however, PHP will jump back to HTML mode for the rest of the file and include whitespace or whatever it finds in your page. This can lead to odd and sometimes hard to find bugs. – Tangentially Perpendicular Feb 07 '21 at 02:16
  • Re your edit: Try using `include_once()`, or perhaps even `require_once()`. – Tangentially Perpendicular Feb 07 '21 at 02:18
  • Well, I tried taking out the include line from a couple of the stat files and just putting it once in the webpage file before then including those stat files, and it displayed fine. So I guess I do just have to edit all 983 files. I knew it would find a way to make me do that eventually, but... *sigh* – Grate Oracle Lewot Feb 07 '21 at 03:23

1 Answers1

0

A blank page is most probably the cause of a PHP parser error. To be able to debug the script you need to set the error reporting on. You can do this by either setting this in the php.ini file, or in your index.php. Use just one of these two methods.

Once error reporting it is set on, it will display the errors and it will be a lot easier to track down errors in your scripts. Have a look here to understand how to deal with your errors, and to understand what they mean.

Make sure you do not leave the error reporting on, on the live website. Use it on your developing folder on your machine.

In your php.ini file try to edit these two lines to look like below.

error_reporting = E_ALL
display_errors = 1

Or in your index.php file at the top of the page include the 2 lines.

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
Lorand
  • 57
  • 1
  • 4