Forum Moderators: coopster

Message Too Old, No Replies

std class

         

bleak26

2:14 pm on Nov 24, 2006 (gmt 0)

10+ Year Member



When i use the set method of my cookie class i recieve the following error

Fatal error: Call to undefined method stdClass::set() in /home/website/index.php on line 21

I understand from research that all classes are children of the stdclass, but little more about it.

i am creating my cookie object in the usual fashion and calling set on my cookie object in the usual fashion, but i do not understand why php is refering to stdclass instead of my cookie class and not finding my set method.

Any help would be grately appreciated.

Once again Thankyou.

bleak26

5:34 pm on Nov 24, 2006 (gmt 0)

10+ Year Member



Also please could you tell me if try and catch statments effect scope?

eelixduppy

5:04 am on Nov 25, 2006 (gmt 0)



Can we have some code please? :)

Not quite sure what it is off the bat; looks like you are using an object for something you aren't suppose to be.

pixeltierra

7:12 am on Nov 25, 2006 (gmt 0)

10+ Year Member



The stdClass is for Sexually Transmitted Diseases. And they are not classy. All stdClasses have bugs, some of which can never be fixed. First try the antibioticsClass() to see if that helps. Then try the lotsofrestClass(). If those don't work, chances are you will never get rid of your bug.

Sorry to be the bearer of bad news.

bleak26

8:36 pm on Nov 25, 2006 (gmt 0)

10+ Year Member



Maybe u can supply some kind of code based lotion to cure my stdclass problem. it itches so

here is the source for 2 files
1.Single signon client code
2.cookie class

my apologies for posting so much code but i am unsure where the error is.

this is the single sign on client code i am using, this code code on the client server.

<?php
//client script
require_once 'Cookie.php';
require_once 'SingleSignOn.php';
require_once 'Exception.php';
require_once 'config.php';
require_once 'Authentication.php';
check_auth();
echo "client script";
function check_auth() {
try {
$cookie1 = new Cookie();
$cookie1->validate();


}
catch(AuthException $e) {
try {
$client = new SingleSignOn_Example();
//echo "client name".$client->client;
$client->process_auth_response($_GET['response']);
$cookie1->userid = $client->userid;
$cookie1->set();

}
catch(SignOnException $e) {
$client->originating_uri = $_SERVER['REQUEST_URI'];
$client->generate_auth_request();
// we have sent a 302 redirect by now, so we can stop all other work
exit;
}
}
}

?>

this is the cookie class

<?php

require_once 'SingleSignOn.php';
require_once 'Exception.php';
require_once 'config.php';
require_once 'Authentication.php';

class Cookie {
private $created;
private $userid;
private $version;
private $td;
private $cookie;

private $cypher = 'blowfish';
private $mode = 'cfb';
private $key = 'fortheforum';

private $cookiename = 'USERAUTH';
private $myversion = '1';
private $expiration = '600';
private $warning = '300';
private $glue = '¦';


public function __construct($userid = false) {
$this->td = mcrypt_module_open ($this->cypher, '', $this->mode, '');
if($userid) {
$this->userid = $userid;
return;
}
else {
if(array_key_exists($this->cookiename, $_COOKIE)) {
$buffer = $this->_unpackage($_COOKIE[$this->cookiename]);
}
else {
throw new AuthException("No Cookie");
}
}
}
public function set() {
$cookie = $this->_package();
setcookie($this->cookiename, $cookie, 0);
}
public function logout() {
setcookie($this->cookiename);
}
public function validate() {
if(!$this->version ¦¦!$this->created ¦¦!$this->userid) {
throw new AuthException("Malformed cookie");
}
if ($this->version!= $this->myversion) {
throw new AuthException("Version mismatch");
}
if (time() - $this->created > $this->expiration) {
throw new AuthException("Cookie expired");
} else if ( time() - $this->created > $this->resettime) {
$this->set();
}
}

private function _package() {
$parts = array($this->myversion, time(), $this->userid);
$cookie = implode($glue, $parts);
return $this->_encrypt($cookie);
}
private function _unpackage($cookie) {
$buffer = $this->_decrypt($cookie);
list($this->version, $this->created, $this->userid) = explode($this->glue, $buffer);
if($this->version!= $this->myversion ¦¦
!$this->created ¦¦
!$this->userid)
{
throw new AuthException();
}
}
private function _encrypt($plaintext) {
//$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
//mcrypt_generic_init ($this->td, $this->key, $iv);
//$crypttext = mcrypt_generic ($this->td, $plaintext);
//mcrypt_generic_deinit ($this->td);
//return $iv.$crypttext;
return $plaintext;
}
private function _decrypt($crypttext) {
//$ivsize = mcrypt_get_iv_size($this->td);
//$iv = substr($crypttext, 0, $ivsize);
//$crypttext = substr($crypttext, $ivsize);
//mcrypt_generic_init ($this->td, $this->key, $iv);
//$plaintext = mdecrypt_generic ($this->td, $crypttext);
//mcrypt_generic_deinit ($this->td);
//return $plaintext;
return $cryptext;
}
private function _reissue() {
$this->created = time();
}
}
/* vim: set ts=2 sts=2 ai bs=2 expandtab: */
?>

bleak26

9:38 pm on Nov 25, 2006 (gmt 0)

10+ Year Member



Also
THe first section of code is the code which the error is comming from.

eelixduppy

12:10 pm on Nov 27, 2006 (gmt 0)



I've looked over the code and I cannot see the source of the problem. Maybe simplifying the code and running it step by step will help you identify it.

I'm sorry I cannot be of anymore help. Have a quick read through Troubleshooting 101 [webmasterworld.com] to see what steps you should do to discover your problem and find the solution.

bleak26

1:09 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



What seems to be happening is when the Cookie1 is accessed before the end of the 1st try statment it is working but as soon as it enters the first catch statment it becomes unaccesible, Although i can still get a true from is_object(cookie1).