• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Why would an idex page show diffrent sceens?

I'm having a problem that I think is the server that I'm using.

When you log in to the site some times it works, other times, it displays php code!

I've contacted "HOSTING24.COM" and they are telling me that it's the php code.

I can't understand that answer.  If php executes line by line, how could the results be different?

I've attached a  word file that contains the  print screens.  If you want the site is "mrbreeze.net"

Thanks
Glenn
Screens.doc
0
breeze351
Asked:
breeze351
  • 4
  • 3
  • 3
  • +1
1 Solution
 
GaryCommented:
It's telling you what the problem is, you are referencing an index in the Security array that doesn't exist.
0
 
Ray PaseurCommented:
I think it's referencing the index named Security and I'm wondering if that index is in $_COOKIE or in $_SESSION.

Check menu_inc.php on line 46
0
 
GaryCommented:
Also
Notice: Undefined index: Menu_No in /home/mrbreeze/public_html/menu_inc.php on line 161
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
breeze351Author Commented:
I think I got this.  Here is the original code from  the top of  "index.php":

<?php
include 'Session_Start.php';
include 'db_connect_inc.php';
include 'menu_inc.php';
echo "<div id = \"map_content\">";

// If login not set
// Set login for "Visitor"
      if (!isset($_SESSION['Security']))
            {
                  $_SESSION['User'] = 'VISITOR';
                  $_SESSION['Password'] = 'VISITOR';
                  $_SESSION['First_Name'] = 'Visitor';
                  $_SESSION['Last_Name'] = 'VIsitor';
                  $_SESSION['E_Mail'] = '';
                  $_SESSION['Security'] = 1;
                  $_SESSION['P_Format'] = 1;
            }
      $_SESSION['Menu_No'] = 1;            
      $_SESSION['Last_Page'] = "index.php";                        
?>

If I move the inclusions below the if statement like this:
<?php
// If login not set
// Set login for "Visitor"
      if (!isset($_SESSION['Security']))
            {
                  $_SESSION['User'] = 'VISITOR';
                  $_SESSION['Password'] = 'VISITOR';
                  $_SESSION['First_Name'] = 'Visitor';
                  $_SESSION['Last_Name'] = 'VIsitor';
                  $_SESSION['E_Mail'] = '';
                  $_SESSION['Security'] = 1;
                  $_SESSION['P_Format'] = 1;
            }
include 'Session_Start.php';
include 'db_connect_inc.php';
include 'menu_inc.php';
echo "<div id = \"map_content\">";

$_SESSION['Menu_No'] = 1;            
$_SESSION['Last_Page'] = "index.php";                        
?>

It should work?
0
 
GaryCommented:
No, that won't work

session_start() needs to be the first line

The error means $_SESSION['Security'] and menu_no is not being set but you are referencing it somewhere else in the code.
In your code above you are only checking if it hasn't been set.
0
 
breeze351Author Commented:
Goctha
I move Session_Start.php  to line 1.
I just grabbed this code and modified it real quick to get an answer.
0
 
MurfurFull Stack DeveloperCommented:
@breeze - the error is not in your index file - it is in menu_inc.php, specifically lines 46 & 161. There is also a problem triggering a syntax error on line 61 of the same file.
0
 
Ray PaseurCommented:
It might be worth addressing this, too.  To a certain extent the PHP errors may be causing the validation errors, but it is hard to tell since the validator does only a single GET request.
http://validator.w3.org/check?uri=http%3A%2F%2Fmrbreeze.net%2F&charset=%28detect+automatically%29&doctype=Inline&group=0

Looking at the "view source" I see a doctype declaration on line 104, leading me to believe that there are organizational errors in the PHP script that generates the HTML.  Here is the organization I often use:

<?php
error_reporting(E_ALL);
require_once('common.php');
/* PROGRAM LOGIC CREATES ALL VARIABLES HERE */
require_once('header.php');
require_once('template.php');
require_once('footer.php.);

Open in new window

By way of explanation, common.php handles all of the "infrastructure" connecting to the data base, starting the session, etc.  The common.php script contains all the class and function definitions (or auto-loaders for these).  After that the program logic runs, usually using the request variables to query the data base, call the APIs, read external files, analyze and set the cookies, etc.  The program logic sets all of the variables that will be needed in the HTML document.  Once that is done the web page can be built.  header.php does exactly what you would think.  template.php loads the web page template, usually a HEREDOC string, and thereby creates an HTML document that contains the variables created by the program logic.  footer.php, like header.php is pretty obvious.  These last three include() files are the only things that produce browser output.  By keeping the scripts modular and in a predictable order, I'm able to keep my work organized, testable and easy to debug.
0
 
breeze351Author Commented:
Ray
This is a menu/index page.  There is no get.

I've read the article on $_SESSION vars.  What I can't still understand is why the page will load correctly and sometimes I get the error messages.  When I hit re-fresh on the browser it loads correctly.  

Also, what is the diff between $isset and $empty?

I also discovered something else.  I haven't accessed the page since yesterday, however it seemed that the $_SESSION vars were still alive.  I thought they expired in 25 minutes?

Thanks
Glenn
0
 
Ray PaseurCommented:
Glenn, There are just too many misunderstandings in the conversation for me to forecast success.  Perhaps you can reach out to a local PHP user group to find someone that can help?

I understand this is a menu/index page.  It is requested via a GET-method request when you type the URL into a browser.  The W3 validator only requests the page once.  Therefore the phenomenon you're seeing will be invisible to the W3 validator.  To understand a little more of the protocols and environment you're using, you might want to read up on HTTP.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

The page loads correctly on the second and subsequent page loads.  This is after the session gets started.  Before the session is started, the page creates those messages that you don't want.

$isset and $empty are PHP variable names.  They start with the dollar sign and do not have the parenthetical ending.  Perhaps you were referring to the functions isset() and empty().  Like all PHP functions these are documented in the online man pages.  You can look them up!  FWIW, I always have a window open to PHP.net when I'm working.  It's how the pros do it.  There are over 1,500 PHP functions.  You can't remember them all; you have to refer to the manual whenever you're not 100% sure of how they work, what they return, etc.
http://www.php.net/manual/en/function.isset.php
http://www.php.net/manual/en/function.empty.php

PHP session garbage collection is controlled by a number of environmental factors and configuration variables.  The article I recommended tells about how PHP sessions work.  It's not simple, but it's a required part of the developer's knowledge.

Anyway, except for the logic errors that are present in the script, this question seems to be morphing into a "how do I write PHP" dialog.  The central issue has been fully answered here, so I'll sign off now.  Best of luck with it, and in respect of your time, seriously think about getting a pro involved.  It will save you a lot of time and frustration, I promise.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now