Forum Moderators: coopster

Message Too Old, No Replies

I've finally worked out OOP but.

It just won't print anything..

         

L33t_J0rdan

10:21 am on Jun 19, 2010 (gmt 0)

10+ Year Member



Okay. To cut a long story short - it wont work... (I mean like - it wont echo anything)

Functions.php:

<?php

$function = new functions();

class functions {

var $secured;
var $randomUnsecured;
var $randomSecured;
var $staffPanelOn;
var $username;
var $password;

function secure($unsecured) {
$secure = md5(md5(sha1(md5(sha1(sha1($unsecured))))));
$this->secured = $secure;
}

function randomUnsecured() {
for($i = 0; $i < 11; $i++) {
$d = rand(1,30)%2;
$this->randomUnsecured = $d ? chr(rand(65,90)) : chr(rand(48,57));
}
}

function randomSecured() {
for($i = 0; $i < 11; $i++) {
$d = rand(1,30)%2;
$this->randomSecured = md5(md5(sha1(md5(sha1(sha1($d ? chr(rand(65,90)) : chr(rand(48,57))))))));
}
}

function staffPanelOn() {
if($this->staffPanelOn == "On") {
return $this->staffPanelOn;
} else if($this->staffPanelOn == "Off") {
return $this->staffPanelOn;
} else {
$this->staffPanelOn = "On";
return $this->staffPanelOn;
}
}

function switchStaffPanel() {
if($this->staffPanelOn == "On") {
$this->staffPanelOn = "Off";
echo 'Sucessfully Turned Off!';
} else if($this->staffPanelOn == "Off") {
$this->staffPanelOn = "On";
echo 'Sucessfully Turned On!';
}
}

function logon($username, $password) {
strip_tags($username); //AntiHack
strip_tags($password); //AntiHack
// Password strip tags un-needed but maybe they try to disable encryption?
}

}
?>


Login.php:

<?php
include('backend/functions.php');
$function->switchStaffPanel();
if($function->staffPanelOn == "Off") {
die('<font size="30" face="Verdana">Staff Panel Off, contact website administrator.</font>');
}
?>


Please help!

Matthew1980

3:28 pm on Jun 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan,

Welcome to the world of classes :) You will have the eureka moment soon enough!

What are you trying to do? Because you have a function there that has multiple MD5/SHA1 encryption calls, when realistically SHA1 is probably the more secure option, though I don't want to spark off a lengthy debate here.

Where are you setting the staffPanelOn variable, because you need a default setting, try using true or false, this should eliminate ambiguity of state - and you can just set it to false in the first instance of your declaration:-

Class foo{
Var $variable = false;//Var is php4 public/private/protected is php5, try to keep the two seperate:)

}

Have you tried to 'echo' anything simple to see if its actually working yet ?:-

class foo{
function echoName(){
$myName = "John Doe";
return $myName;
}
}

$EchoClass = new foo();

echo $EchoClass->EchoName();

Try something simple first to see if you can get that going, also, turn on your error_reporting(E_ALL); to see if there is anything happening behind the scenes.

But from reading this quickly, it looks like you haven't declared the vars value anywhere outside the class.

Good luck, and I hope I haven't confused you too much ;)

Cheers,
MRb

Alcoholico

3:50 pm on Jun 19, 2010 (gmt 0)

10+ Year Member



As Matt already told you, you need to initialise staffPanelOn, preferably use a boolean true/false value as suggested. However, I don't know what you're trying to accomplish at the end, you could try for instance:

<?php
include('backend/functions.php');

$function->staffPanelOn = 'On'; //Set an initial state (true/false)

$function->switchStaffPanel();
if($function->staffPanelOn == "Off") {
die('<font size="30" face="Verdana">Staff Panel Off, contact website administrator.</font>');
}
?>

OR
<?php
class functions {
var $secured;
var $randomUnsecured;
var $randomSecured;
var $staffPanelOn = 'Off'; //Set a default value (true/false)
var $username;
var $password;
....
?>

OR use the class constructor function to set a default state, you currently do not have a constructor function.

It does not seem like a good idea to me to name a class "functions" or a variable "function", you'd want to try using something more descriptive and definitively not PHP reserved words, also imagine when you need to search your function named "function" in a bunch of files filled with "functions".
Also this is expensive and definitely not more secure:
md5(md5(sha1(md5(sha1(sha1($d ? chr(rand(65,90)) : chr(rand(48,57))))))))

Paranoia anyone? You're not storing the Coca-Cola formula on your server, are you?

L33t_J0rdan

4:39 pm on Jun 20, 2010 (gmt 0)

10+ Year Member



No but the person I'm coding it for wants it super secure. So I said okay hehe.

EDIT: Thanks! Works now :)

Matthew1980

8:50 pm on Jun 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan,

Cool, glad your working now - though, the point we were making is that you are using multiple calls to 2 separate functions when realistically 1 call to SHA1() would do more or less the same thing.

SHA1() is meant to be the more secure of the two (as it returns a 40 char hex format string as opposed to the 32 hex string from md5), again, not wanting to spark a debate, that's just how I have understood those functions to differ.

Secondly, it would be less overhead on the parser running just 1 algorithm instead of 4 or 5.

Have fun with the rest of the project.

Cheers,
MRb

Readie

9:47 pm on Jun 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Both sha1 and md5 have been cracked, you're better off using the hash function and going for sha256 or sha512.

[uk2.php.net...]

Use hash_algos() to find out the allowed algorithms for use in the first parameter for hash:

[uk2.php.net...]

dreamcatcher

6:40 am on Jun 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I agree with Readie. However, these functions aren`t PHP4 compatible, so always the check whats available if you are creating software for other people to use.

dc