PHP require not working

October 24, 2019 9.4k views
PHP Apache One-Click Install Apps PHP Frameworks

I have installed my droplet (ubuntu 18.04) both manually but also tried the one-click apps. Both times the PHP variables are “undefined” but they are defined in another file. I used the following code to include them:
require ’/var/www/developer/steamauth/userInfo.php’;

This works on my other server (Linus @ ExtraVM) so I don’t understand why this doesn’t work. Am I missing any PHP packages?

PLEASE HELP!

2 Answers

Hi @PixelBoii,

I’ll recommend checking the following article - Ubuntu PHP - How to

It will help you properly install PHP and every packages needed on an Ubuntu.

I’m unsure what you mean by PHP variables not working with require though. Can you please give a little bit more information on the matter?

by Mark Drake
A "LAMP" stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This stack typically consists of the Linux operating system, the Apache web server, a MySQL database, and PHP, a dynamic content processor. This tutorial serves as a guide for installing these components on an Ubuntu 18.04 server.
  • I’ve already tried that tutorial without much success. The error is:
    PHP Notice: Undefined variable: steamprofile in /var/www/html/index.php on line 109"

    Line 109:
    <p style=“color: #000;”><b>Your SteamID 64 is:</b> <?=$steamprofile[‘steamid’];?></p>

    All the errors are like this one, just different lines. All php steam related.

    • Hi @PixelBoii,

      Thanks for the explanation, I now know what you mean.

      Can please make sure you’ve required/included the file at the top of the document and make sure these variables are actually being called in someway by your script/website?

      Regards,
      KDSys

      • Absolutely. This is the top of my file:

        <?
        
          require '/var/www/html/steamauth/steamauth.php';
          require '/var/www/html/steamauth/userInfo.php';
        
          if(isset($_SESSION['steamid']))
          {
              $id = $_SESSION['steamid'];
          }
          else
          {
            # Not logged in
          }
        
        ?>
        <!DOCTYPE html>
        

        and then the html goes on..

Have another answer? Share your knowledge.