Solved

Urgent - use of 'require' and 'include' and session variables

Posted on 2001-06-15
5
156 Views
Last Modified: 2013-11-18
I?m using session variables to store objects and I?m having problems with different versions of PHP. Two files:-

//-------------
//start rjp.rqd
//-------------

<?
class test()
{
     function doEcho()
     {
          echo ?hello<BR>?;
     }
}
?>
//-----------
//end rqp.rqd
//-----------


//-------------
//start rjp.php
//-------------

<?
session_start();
session_register(?theTest?);
session_register(?Count?);
require (?rjp.rqd?);

$Count++;
if (!isset($theTest))
{
     $theTest = new test;
     echo ?test instantiated<BR>?;
}

$theTest->doEcho();
?>
You have visited this site <?echo $Count?> times<BR>
<A HREF=<?echo $PHP_SELF?>?<?=SID?>>page again</A>

<?
//-----------
//end rjp.php
//-----------
?>

This works fine on PHP version 4.0.1pl2 but gives the following error on PHP version 4.0.3pl1 (and 4.0.4pl1) when ?page again? is hit:-

Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition test of the object you are trying to operate on was loaded _before_ the session was started in /testdir /rjp.php

I?ve cut the rqd file into the php file (so it?s actually part of the php file and not ?required?) and it works fine on both php versions.

register_vars, track_vars and enable_trans_sid are all enabled.

What am I doing wrong?

RJP.
0
Comment
Question by:rplewka
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
a.marsh earned 150 total points
ID: 6194865
I would move the require line before the session_start() line.

So your code becomes:

require (?rjp.rqd?);
session_start();
session_register(?theTest?);
session_register(?Count?);

Ant
0
 

Author Comment

by:rplewka
ID: 6195380
Ant,

I'll give that a try and see what happens.

I'll let you know how it goes.

RJP
0
 
LVL 5

Expert Comment

by:aksteve
ID: 6208144
Classes should be included before any other code if for anything other then readability.

session_register automatically issues a session_start so your use of session_start is redundant..
0
 

Author Comment

by:rplewka
ID: 6215233
Thank a.marsh, that did the trick. Actually sorted it out at the weekend, but so busy didn't have time to respond. Thanks again.
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6215255
Glad to help.........if it did the trick though, I'm curious as to why I only deserved a B grade......

:o\

Ant
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now