Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - require_once in multiple pages
    text
    copied!<p>I am using LAMP stack to develop a PHP application. I am using require_once to include class files. I need to use the functions in those class files in more than one PHP page. So, I am including those class files in all the required PHP pages using require_once. But, if I include those class files in more than one page, the PHP file goes blank. It displays nothing. View source also displays nothing.</p> <p>Files: test.php, process.php and class.test.php</p> <p>test.php has</p> <pre><code>&lt;?php session_start(); require_once 'classes/class.test.php'; . Few more classes . . ?&gt; &lt;html&gt; &lt;form name = "myForm" method="POST" action="process.php"&gt; &lt;input type = "text" name="username" value=""/&gt; &lt;input type = "submit" value="Submit" /&gt; &lt;/form&gt; &lt;/html&gt; </code></pre> <hr> <p>process.php</p> <pre><code>&lt;?php session_start(); require_once 'classes/class.test.php'; $obj_test = new test(); $obj_test-&gt;test(); ?&gt; </code></pre> <hr> <p>class.test.php</p> <pre><code>&lt;?php session_start(); require_once 'class.misc.php'; require_once 'config.php'; //DB connection details function test() { $obj_misc = new misc(); $id = $obj_misc-&gt;random_ID(); $username = $_POST['username']; $query = "INSERT INTO test_table VALUES ('$id','$username',NOW()); mysql_query($query); } ?&gt; </code></pre> <p>Now, it returns a blank page. If I comment out the require_once in process.php, the test.php page displays the form, but on submitting the form the process.php throws an error "class test not found". </p> <p>I am struggling with this problem for the past 2 weeks. :( It was working fine before that. I don't understand what went wrong. Please help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload