Jump to content

Driving me crazy


caseyh

Recommended Posts

??? I recently edited some files and now they dont work, the thing is i cant figure out why. I look at it and it should work but it doesn't. When ever i include a new class that I just did my site doesnt work at all

<?php

////////////////////////////////////////////
///////////////////////////////////////////
//*  Copy Right Casey Hillman 2007     *//
//*  None of this code may be used    *//
//*  without prior written consent   *//
//*  from its respected owner!      *//
//////////////////////////////////////
/////////////////////////////////////

// Class used to output default page
class cSession
{

/////////////////////////////////////////////////////////
///////////    Class cSession's Constructor    /////////
///////////////////////////////////////////////////////

  // Variable to hold ref to external object
  var $refToClass='';
  
  // Constructor, passes ref of an external object into cConGen
  // sets it to $ref local 
  function cSession(&$ref)
  {
  $this->refToClass=$ref;
  }   
  
////////////////////////////////////////////////////////    
///////// Class cSession's Default Attributes /////////
//////////////////////////////////////////////////////   

// Cart Begins Empty
  $cart = array();
  
////////////////////////////////////////////////////////  
///////////// Class cSession's Functions //////////////
//////////////////////////////////////////////////////

function begin()
{
 	session_start();
 	$this->setVar('log',0);
	$this->setVar('items','0');
	$this->setVar('cart',$this->$cart);
}

function addItem($itemN, $itemQ)
{
	$new = array('$itemN'=>'$itemQ');
	$current = $_SESSION['cart'];
	$add = array_merge($new,$current);
	$this->setVar('cart',$add);
	$curr = $this->get_var('items');
	$add = $curr + 1;
	$this->setVar{'items',$add);
	$comment = "<h3>The Item Has Been Succesfully Added To Your Cart</h3>";
	$comment .= "<a href='javascript:init('index.php')'>Continue Shopping</a> |";
	$comment .= " <a href='javascript:init('index.php?page=checkout')'>Proceed To Checkout</a>";
	$echo "$comment";
}

function login($uname,$pswd)
{
	if( !$uname || !$pswd)
	{
		return false;
	}
	else {
	$this->setVar('user',$uname);
	$this->setVar('log','1');
	$this->setVar('cart','0');
	return true;}
}

   function setVar( $varName, $varVal )
   {
       if( !$varName || !$varVal )
       {
           return false;
       }
       $_SESSION[$varName] = $varVal;
   }


   function get_var( $var_name )
   {
       return $_SESSION[$var_name];
   }


   function del_var( $var_name )
   {
       unset( $_SESSION[$var_name] );
   }


   function del_vars( $arr )
   {
       if( !is_array( $arr ) )
       {
           return false;
       }
       foreach( $arr as $element )
       {
           unset( $_SESSION[$element] );
       }
       return true;
   }


   function del_all_vars()
   {
       del_all_vars();
   }


   function endSes()
   {
       $_SESSION = array();
       session_destroy();
   }
}
?>

 

Any insite into why it kills my site when i just include it would help out a lot.

 

In my index.php i have

 // Include class cConGen for paging system
include ("classes/cConGen.inc.php");

// Include class cDataBase for mySQL databse connectivity
include("classes/cDataBase.inc.php");

// Include class cSession for session support
include("classes/cSession.inc.php");

 // Create object $data of class cDataBase
 $data = new cDataBase();

 // Create object $ses of class cSession 
 $ses = new cSession($data);

 // Create object $page of class cConGen
 $page = new cConGen($data);

 

which gives me a blank page, but if i comment out like this

 // Include class cConGen for paging system
include ("classes/cConGen.inc.php");

// Include class cDataBase for mySQL databse connectivity
include("classes/cDataBase.inc.php");

// Include class cSession for session support
//include("classes/cSession.inc.php");

 // Create object $data of class cDataBase
 $data = new cDataBase();

 // Create object $ses of class cSession 
 //$ses = new cSession($data);

 // Create object $page of class cConGen
 $page = new cConGen($data);

 

it works fine, if i cant figure it out im just gonna start over. well its crappy code i know, its my first time working with sessions and im just starting simple. Well thanks in advanced for any help.

Link to comment
Share on other sites

the fourm will not let me edit my post for some reason, but the cSession class should be this

<?php

////////////////////////////////////////////
///////////////////////////////////////////
//*  Copy Right Casey Hillman 2007     *//
//*  None of this code may be used    *//
//*  without prior written consent   *//
//*  from its respected owner!      *//
//////////////////////////////////////
/////////////////////////////////////

// Class used to output default page
class cSession
{

/////////////////////////////////////////////////////////
///////////    Class cSession's Constructor    /////////
///////////////////////////////////////////////////////

   // Variable to hold ref to external object
   var $refToClass='';
   
   // Constructor, passes ref of an external object into cConGen
   // sets it to $ref local 
   function cSession(&$ref)
   {
   $this->refToClass=$ref;
   }   
   
////////////////////////////////////////////////////////    
///////// Class cSession's Default Attributes /////////
//////////////////////////////////////////////////////   

// Cart Begins Empty
   $cart = array();
   
////////////////////////////////////////////////////////  
///////////// Class cSession's Functions //////////////
//////////////////////////////////////////////////////

function begin()
{
 	session_start();
 	$this->setVar('log',0);
	$this->setVar('items','0');
	$this->setVar('cart',$this->$cart);
}

function addItem($itemN, $itemQ)
{
	$new = array('$itemN'=>'$itemQ');
	$current = $_SESSION['cart'];
	$add = array_merge($new,$current);
	$this->setVar('cart',$add);
	$curr = $this->get_var('items');
	$add = $curr + 1;
	$this->setVar{'items',$add);
	$comment = "<h3>The Item Has Been Succesfully Added To Your Cart</h3>";
	$comment .= "<a href='javascript:init('index.php')'>Continue Shopping</a> |";
	$comment .= " <a href='javascript:init('index.php?page=checkout')'>Proceed To Checkout</a>";
	$echo "$comment";
}

function login($uname,$pswd)
{
	if( !$uname || !$pswd)
	{
		return false;
	}
	else {
	$this->setVar('user',$uname);
	$this->setVar('log','1');
	$this->setVar('cart','0');
	return true;}
}

    function setVar( $varName, $varVal )
    {
        if( !$varName || !$varVal )
        {
            return false;
        }
        $_SESSION[$varName] = $varVal;
    }


    function get_var( $var_name )
    {
        return $_SESSION[$var_name];
    }


    function del_var( $var_name )
    {
        unset( $_SESSION[$var_name] );
    }


    function del_vars( $arr )
    {
        if( !is_array( $arr ) )
        {
            return false;
        }
        foreach( $arr as $element )
        {
            unset( $_SESSION[$element] );
        }
        return true;
    }


    function del_all_vars()
    {
        del_all_vars();
    }


    function endSes()
    {
        $_SESSION = array();
        session_destroy();
    }
}
?>

 

I have noticed already quite a few people have viewed this topic, im wondering if yall can't see anything wrong or if its just code so crappy to not even bother?

Link to comment
Share on other sites

hey, i hate to steal your thunder but is there a name for the -> function i googled it but nothing came up. I see those everywhere and they seem to make code a lot cleaner.  i wish i could help, but i probably got a couple more years till i can make something half as good as that.

 

HotDaWg

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.