Hi All,

I am getting an undefined error in the following code

Undefined variable: Settings in C:\wamp\www\sessions\index.php on line 14(last line)

Any help would be appreciated

Thanks in advance

David

class SiteSettings {
        var $Settings;
    function SettingValues() {
            $Settings['WS-Filepath'] = "/wamp/crud/view.php/";
            $Settings['WS-HTTPpath'] = "http://localhost/crud/view.php/";
            $Settings['DB-Hostname'] = "localhost";
            $Settings['DB-Username'] = "root";
            $Settings['DB-Password'] = "";
            $Settings['DB-Database'] = "db301847341";

            return $Settings;
        }
    }
    header("Location: " . $Settings['WS-HTTPpath']);

This is one option:

class SiteSettings 
{
    public $Settings = array ();

    public function __construct() 
    {
        $this->Settings['WS-Filepath'] = '/wamp/crud/view.php/';
        $this->Settings['WS-HTTPpath'] = 'http://localhost/crud/view.php/';
        $this->Settings['DB-Hostname'] = 'localhost';
        $this->Settings['DB-Username'] = 'root';
        $this->Settings['DB-Password'] = '';
        $this->Settings['DB-Database'] = 'db301847341';
    }
}

$siteSettings = new SiteSettings();
header('Location: ' . $siteSettings->Settings['WS-HTTPpath']);

Hi Pritaeas thanks for your reply worked perfectly I have now placed it in a sitesettings.php file and I get an error with this line

header('Location: ' . $siteSettings->Settings['WS-HTTPpath']);

with an error code of arse error: syntax error, unexpected 'header' (T_STRING) in C:\wamp\www\sessions\index.php on line 26

As always any help would be appreciated

Thanks

David

index.php file

<?php
    session_start();
        ob_start();
        include_once('functions/sitesettings.php')

    header('Location: ' . $siteSettings->Settings['WS-HTTPpath']);








sitesettings.php
    class SiteSettings 
    {
        public $Settings = array ();
        public function __construct() 
        {
            $this->Settings['WS-Filepath'] = '/wamp/crud/view.php/';
            $this->Settings['WS-HTTPpath'] = 'http://localhost/crud/view.php/';
            $this->Settings['DB-Hostname'] = 'localhost';
            $this->Settings['DB-Username'] = 'root';
            $this->Settings['DB-Password'] = '';
            $this->Settings['DB-Database'] = 'db301847341';
        }
    }
    $siteSettings = new SiteSettings();

Missing semi-colon on line 4.

Hi Pritaeas, thanks again.

I am getting the following error messages

` Warning: include_once(functions/sitesettings.php): failed to open stream: No such file or directory in C:\wamp\www\sessions\index.php on line 11

Warning: include_once(): Failed opening 'functions/sitesettings.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\sessions\index.php on line 11`

Is the path incorrect not sure it that is what it is telling me?

Thanks again

David

Hi Pritaeas, I have placed the in the sitesettings.php page in the same folder as index.php and seems to work. Not sure if that is correct?

include_once('sitesettings.php');

Thanks

David

Not sure if that is correct?

Debatable. It works, but defining a good folder structure is often recommended. Especially if the projects get larger.

Hi Pritaeas,
This is where the file is located
include_once('includes/functions/sitesettings.php');

The file structure is as follows:

http://localhost/test/
                    index.php
                    includes
                            functions
                                     sitesettings.php

errors are :

Warning: include_once(includes/functions/sitesettings.php): failed to open stream: No such file or directory in C:\wamp\www\sessions\index.php on line 11

Warning: include_once(): Failed opening 'includes/functions/sitesettings.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\sessions\index.php on line 11

Notice: Undefined variable: siteSettings in C:\wamp\www\sessions\index.php on line 12.

Notice: Trying to get property of non-object in C:\wamp\www\sessions\index.php on line 12.

The last two error will most likely be resolved once the first two error get resolved.

Line 11 and 12 relate to these two lines of code

include_once('includes/functions/sitesettings.php');
    header('Location: ' . $siteSettings->Settings['WS-HTTPpath']);

Thanks again

David

Hi Pritaeas

Am I able to suppress the error using error_reporting(0);? or should they be resolved.

Thanks in advance

David

should they be resolved

Always IMO.

In My Opinion.

If your brake fluid is empty in your car, do you disable the warning light? Work on the cause, not on the sympton.

Thanks Pritaeas, I will re-enable the warnining light. Looking at the structure what would cause the errors. it seems clear that the path is correct.

When I create a link ?><a href="includes/functions/sitesetting.php">sitesetting.php</a><?php

and when selected links to the page.

Any feedback would be great.

Thanks

David

I don't know why you would get warnings on the path.

Apart from that, I'd move $siteSettings = new SiteSettings(); from the sitesettings.php to your index.php. A class file should only contain the class definition. It will remove the notices.

Hi Pritaeas - I have moved the $siteSettings = new SiteSettings(); to index and I get the below message?

Notice: Undefined variable: siteSettings in C:\wamp\www\sessions\index1.php on line 14

Stumped now?

David

Not if you still have the warning about the file.

Your notice says index1.php instead of index.php. Is this a new file you've created, or the same as index.php but just renamed?

Hi Lsmjudoka, thanks for your reply. The contents was copied from index.php and saved as index1.php. Any ideas?

If I change the include to the file in the same directory as the index file it works ok.

session_start();
    ob_start();
    include_once('sitesettings.php');
    header('Location: ' . $siteSettings->Settings['WS-HTTPpath']);`

Thanks

David

Warning: include_once(includes/functions/sitesettings.php): failed to open stream: No such file or directory in C:\wamp\www\sessions\index.php on line 11

Warning: include_once(): Failed opening 'includes/functions/sitesettings.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\sessions\index.php on line 11

The above warning points to the sessions folder, not the test folder you described.

Hi Pritaeas, I have placed all file so that my index1.php is at localhost
http://localhost/index1.php i have taken it out of the session folder so to remove any ambiguity with folder levels.

My sitesetting.php path structure is that indicated on line 3

I have uploaded a zipfile you may want to have a look?

Thanks

David

<?php 

// inculde_once('includes/functions/sitesettings.php')

class SiteSettings 
{
    public $Settings = array ();
    public function __construct() 
    {
        $this->Settings['WS-Filepath'] = '/';
        $this->Settings['WS-HTTPpath'] = 'http://localhost/';
        $this->Settings['DB-Hostname'] = 'localhost';
        $this->Settings['DB-Username'] = 'root';
        $this->Settings['DB-Password'] = '';
        $this->Settings['DB-Database'] = 'db301847341';
    }
}

?>

index1.php

<?php
/**

 * Date: 27/11/2013
 * Time: 4:17 PM
 * Remote Access folder | index.php | File | Settings | Login page .
 */
 session_start();
    ob_start();
    //error_reporting(1);
    include_once('includes/functions/sitesettings.php');
    include('includes/functions/text.php');
    //header('Location: ' . $siteSettings->Settings['WS-HTTPpath'].'success.php');
    $siteSettings = new SiteSettings();

    //include_once ("includes/settings.php");
    //include_once ("includes/optional.php");


     var_dump($_POST);
     $Errors = "";// set errors flag to empty

    if (isset($_POST['formSubmit']) and ($_POST['formSubmit'] == 'true') and isset($_POST['username']) and isset($_POST['password'])){

            $username = mysql_real_escape_string(isset($_POST['username'])) ? $_POST['username'] : "";
            $password = mysql_real_escape_string(isset($_POST['password'])) ? $_POST['password'] : "";
            $password =  md5($password);

            $_SESSION['LoggedIn'] = true;
            $_SESSION['password'] = $password;
            $_SESSION['username'] = $username;
            header('Location: ' . $siteSettings->Settings['WS-HTTPpath'].'success.php');
            exit;

    }else {
            // log in failed
            if (isset($_POST['formSubmit']) and ($_POST['formSubmit'] == 'false')){
            echo $Errors = "The log in details you entered were incorrect, please try again.";
            //}
            //if ($Login->FailedLogin($Text->ValidSQLString($_POST['Username']), $Text->ValidSQLString($_POST['Password'])) == false) {
                // log failed log in
            //  $Errors .= "<br />You have tried to log in from an unapproved IP address, your details have been logged for legal purposes.";
            //}

            $_SESSION['LoggedIn'] == false;
            $_SESSION['UserID'] == "";
            $_SESSION['UserAdmin'] = false;
        }
    }   
?>


<html>
    <head>
        <meta charset="utf-8">
        <title>Watkins Hire | Login</title>


        <link rel="stylesheet" type="text/css" href="styles/login.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,800,700,600,300" rel="stylesheet" type="text/css">
        <link href="/favicon.ico" rel="icon">
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.15/jquery.form-validator.min.js"></script>
        <style type="text/css" media="all">

        </style>
    </head>
<body>


    <div id="topBarWrapper">
        <div id="topBarContainer"><!----></div><!-- end topBarContainer -->
    </div><!-- end topBarWrapper -->      
    <div class="headerRemoveShadow" id="headerWrapper">
        <div id="headerContainer"><!----></div><!-- end headerContainer -->
    </div><!-- end headerRemoveShadow -->     
    <div id="fullPageWrapper">
        <div id="fullPageContainer">

            <form action="<?php echo trim($_SERVER['PHP_SELF']); ?>" id="loginForm" method="POST" name="loginForm" autocomplete="off">
                <input id="formSubmit" name="formSubmit" type="hidden" value="true">
                <label for="username">Username</label><input id="username" name="username" type="text" autofocus data-validation="required" data-validation-error-msg="You did not enter a Username">
                <label for="password">Password</label><input id="password" name="password" type="password" data-validation="required" data-validation-error-msg="You did not enter a Password">
                <!--<label for="password">Email</label><input id="email" name="email" type="email" data-validation="required" data-validation-error-msg="You did not enter a Email Address">-->
                <div class="centre"><input id="loginButton" name="loginButton" type="submit" value="Log In"></div>
            </form>
        </div><!-- end fullPageContainer -->
    </div><!-- end fullPageWrapper -->
    <script type="text/javascript">
        $.validate({
            validateOnBlur : false,
            errorMessagePosition : 'top',
            scrollToTopOnError : false
        });
    </script>

</body>
</html>
<?php 
    ob_end_flush();
?>

I'll check what happens on my machine when I'm home.

Not sure what the problem was? but working ok now.

Thanks for the support

David