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
https://forums.phpfreaks.com/topic/42572-driving-me-crazy/
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
https://forums.phpfreaks.com/topic/42572-driving-me-crazy/#findComment-206614
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
https://forums.phpfreaks.com/topic/42572-driving-me-crazy/#findComment-206618
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.