views:

24

answers:

2

They were all working fine on my XAMMP sandbox but now nothing.

Something im doing wrong.

Here is the code:

index.php

Contains mass include, which basically has all the includes in it.

<?php

//Starting session

session_start();

//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs

include ("includes/mass.php");

//Login Form

$login = 


         "<form id='signin' action = 'login.php' method = 'POST'>
         Username<input type= 'text' name= 'username'>
         Password<input type= 'password' name= 'password'>
         <input type= 'submit' value='login' name='submit'>
         </form>";

//Calculate number of users online

$num_users_sql = mysql_query("SELECT * FROM user WHERE loggedin = '1' ", $con);

$num_online_users = mysql_num_rows($num_users_sql);

//user bash link

$user = "<a href='user.php'>User</a><br>";  

//Register Form Link     

$registerlink = "<a id='signup' href='register.php'>Sign Up</a>";

//Logged In User Links 

$logoutlink   = "<a id='logoutlink' href='logout.php'>Log out</a>";

$message = "<div id='welcome'>"."Hello"." ".$_SESSION['username']."!"."</div>";

$num_users_online = "<div id='users_online'><h2>There are ".$num_online_users." Users On Readnotes Right nw!</h2>"."</div>";

         if (isset($_SESSION['username']))

          //If user is logged in

            {

                echo $message;

                echo $user;

                echo "</br>";

                echo $num_users_online;

                echo $logoutlink;

            }

         //If user is logged out

         else

            {   
                echo $login;

                echo $registerlink;  

            }


?>

Mass include

contains all of my includes

<?php

/*Mass include - mass.php*
*Includes all thing needed for operations to start*/


//Grab Header design & details

    require("header.html");

//Grab Footer design & details

    require("footer.html");

//Grab include to connect to the database!

    require("dbcon.php");


?>

Thanx.

A: 

The production server may not have . in include_path. To fix this, add it to the includes, e.g. ./header.html.

Ignacio Vazquez-Abrams
i will give this a go
Tapha
+1  A: 

A quite common cause of trouble about includes that "don't work" when changing servers are :

  • You developped on a Windows machine, and your production server is a Linux machine ;; files names and pathes are case-sensitive on Linux
    • Which means you should check if lower and upper case in your files and directories names do match what you're using.
  • Another problem is files not being found...


About the second problem, two ideas :

  • Use require, instead of include ; you'll get a Fatal Error if the require doesn't work
    • And enable error_reporting and display_errors, to see the error message.
  • Always use absolute paths to point to the files you are including, and never relative ones
    • Of course, you don't want to type the absolue pathes in your code
    • So, you can use the dirname function, a bit like this :


In your file "main" (And the same idea should be used for all other includes) :

require dirname(__FILE__) . '/includes/mass.php';

Note that dirname(__FILE__) will always give you the absolute path to the directory the file you're writting this in is.


About the "enable errors reporting and dislay", as you probably don't have access to your server's configuration files, the simplest way is to put something like this at the top of your main script :

error_reporting(E_ALL);
ini_set('display_errors', 'On');

With that, errors should be displayed in the browser -- it'll be a bit easier to see them than having to take a look at the server's error log.

Pascal MARTIN
trying this out now,
Tapha