The page where the problem occurs is Challenge1.php This page is one of many Challenge pages. Here is its code:
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Challenges</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
<script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
<link rel="STYLESHEET" type="text/css" href="style/pwdwidget.css" />
<script src="scripts/pwdwidget.js" type="text/javascript"></script>
<link rel="shortcut icon" type="image/ico" href="favicon.ico" />
</head>
<body>
<?php include('nav.php'); ?>
<!-- Form Code Start -->
<div id='fg_membersite'>
<br/>
<?php
if(!$fgmembersite->DBLogin())
{
$fgmembersite->HandleError("Database login failed!");
return false;
}
$query = mysqli_query($fgmembersite->connection,"SELECT Title, Points, description, Hint, HintCost, Hint2, Hint2Cost from solutions where id_solution ='1'");
$fgmembersite->connection;
include('Challenge.php'); ?>
</div>
</body>
</html>
Now, as you can see, at the top, it includes the file membersite_config.php . This file contains:
<?PHP
require_once("./include/fg_membersite.php");
$fgmembersite = new FGMembersite();
And followed by the DB connection strings to a MySQL db and such. Now the important part is that it includes the fg_membersite.php file. This file has 1000 lines of code and is where all the php code is kept. You also see that the config file creates $fgmembersite. Remember this, it's important in a sec.
Now, back to the beginning: Challenge1.php also includes challenge.php at the bottom. Every Challenge1-14.php page includes challenge.php as all those pages need that same code.
Now here's the problem. Code snippet from challenge.php:
$fgmembersite->car();
function CheckSol()
{
$fgmembersite->car2();
now, functions "car" and "car2" simply echo "testing" and "testing again", respectively. These functions are written in fg_membersite.php. now here's the actual issue the function car() works, echoes "testing" but car2() does not. in fact, in php debug I get this error:
Notice: Undefined variable: fgmembersite in /customers/9/f/7/bvhtuinen.be/httpd.www/CTF/Challenge.php on line 22
Fatal error: Call to a member function car() on null in /customers/9/f/7/bvhtuinen.be/httpd.www/CTF/Challenge.php on line 22
Line 22 being the line where car2(); is at.
So ultimately, my question is: why can't I call a function within a function? (obviously, inside 'CheckSol, which by the way is called on Challenge1.php's form action, there is a lot more code which also needs $fgmembersite...)
I hope I'm clear enough and thank you all in advance!