Posted by Jochem Maas on 01/15/05 17:00
David OBrien wrote:
> I have RTFM and TTFE and still am having a heck of a time getting my
> objects to play well between pages
> The only real examples are in the notes for classes & objects
> http://us2.php.net/manual/en/language.oop.php
(are you on php4 or php5 btw?)
>
> Basic usage
> <?
> include_once("config.inc");
> include_once("class.php");
indeed, you must include classes for objects stored in a session before
starting the session. :-)
> $songbook = new songbook(); // defined in the class.php
if you are creating this object on every page/call and then assigning it
to the session it will always have a blank/null userid. because
each call overwrites the old object thats stores with a brand new
one. so you need to check the session to see if a songbook
object is already available. so you only ever see the login screen in
your example.
> session_register('songbook');
alternative is using $_SESSION. but if you do you must call
session_start() first:
session_start();
if (!isset($_SESSION['songbook']) || !is_object($_SESSION['songbook'])
|| !(get_class($_SESSION['songbook']) == 'songbook'))
{
$_SESSION['songbook'] = new songbook;
}
> $songbook->get_stats();
> $songbook->populate_manu();
> $songbook->populate_series();
> if (!isset($songbook->userid) || $songbook->userid == "") {
> header("Location: login.php");
> }
>
> Now the login.php is basically the same but if the login correctly it
> should set $songbook->userid to the username
>
> require('common.php');
> session_start();
> include_once("class.php");
> $songbook = new songbook();
> session_register('songbook');
> include("newheader.php");
> if ( isset($_POST['submitit'])) {
> $link = dbconnector();
> $sql = "select * from userinfo where
> lower(username)=lower('".$_POST['user']."') and
> lower(password)=lower('".$_POST['pass']."')";
> $result = mysql_query($sql);
> if( mysql_num_rows($result) > 0 ) {
> $songbook->userid = strtolower($_POST['user']);
> header("Location: green.php");
> } else {
> $errormsg = "<font size=3>Invalid Username or
> Password.<br>\nPlease Try Again.</font>";
> }
> }
>
> So I guess what I am asking is how DO you make objects work across pages?
> -Dave
>
[Back to original message]
|