Error Need your help

Discussion in 'PHP' started by UKmember, Jun 14, 2008.

  1. #1
    i have installed a script www.models.cheapwebdesignuk.co.uk but it is saying

    Fatal error: Using $this when not in object context in /home/cheapweb/public_html/models/include/common.php on line 11

    Can anyone help?



    <?
    	session_start();
    	include("config.php");
    
    	$paypal_item = $sitename." Service Monthly Subscription";
    	$paypal_item_number = $sitename;
    	$mainipn = $siteurl."/ipn.php";
    	$paypal_ipn = $siteurl."/site_ipn.php";
    	$paypal_cancel_return = $siteurl."/cancel.php";
    	$paypal_return = $siteurl."/thanks.php";
    	$this->min_pass_length="8";
    	$this->max_pass_length="12";
            $this->chars='abcdefghijklmnopqrstuvwxyz0123456789';
    	$logfile = "logfile.txt";
    	$postmode = 1;
    	$invalidcode = "<table  cellpadding=4 width=170><tr><td align=center><font size=2><b>Invalid Button Code!</b><p>Run Your Own PayPal Donation Campaigns at <a href=$siteurl/join.php>$sitename</a></font></table>";
    	$table1 = "<TABLE class=design  cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#ffffff' STYLE='border-collapse: collapse'>";
    	$table2 = "<TABLE class=design  cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#ffffff' STYLE='border-collapse: collapse'>";
    	$table3 = "<TABLE class=design  cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#ffffff' STYLE='border-collapse: collapse'>";
    
    	@mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server: " . mysql_error());
    	@mysql_select_db($dbName) or die("Couldn't connect to database: " . mysql_error());
    	
    	function errform($msg, $var = ''){ 
    		global $posterr, $_POST; 
    		$posterr = 1; 
    		echo "<div style='color: #FF0000;'>$msg</div>";
    		if ($var) $_POST[$var] = '';
    	}
    	
    	function addreport($user,$site,$status){
    		mysql_query("INSERT INTO report SET user='$user',site='$site',status='$status',date='".time()."'");
    	}
    
    	function quickcheck($host,$port){
    		$running = @fsockopen($host, $port, $errno, $errstr, 30);  
    		if (!$running){
    			return 0;
    		}else  {  
    			fclose($running);  
    			return 1;
    		} 
    	}
    
    	function fullstatus($host){
    		$services = array(  
    			"http"=>"80",  
    			"ssh"=>"22",  
    			"ftp"=>"21",  
    			"smtp"=>"25",  
    			"pop3"=>"110",  
    			"mysql"=>"3306");  
    
    		$date = date("l, M d, Y - h:i:s A");  
    ?>  
    		<p><font face="Arial" size="2"><b>System Status: <?= $host ?></b></font><br>Time: <?= $date ?></p> 
    		<font face="Arial" size="2"> 
    		<p><table> 
    		<tr bgcolor="#5590CC"><td>Status</td><td>Service</td><td>Host</td></tr> 
    <?  
    		foreach ($services as $name=>$port){  
    			$running = @fsockopen($host, $port, $errno, $errstr, 30);  
    			if (!$running){
    				$status_color = "red";  
    				$status_sign = "X";
    			}else  {  
    				fclose($running);  
    				$status_color = "green";  
    				$status_sign = "&nbsp;";
    			}  
    			echo "<tr><td align=center><div align=\"center\" style=\"font-size: 20pt; border: 2px solid $status_color; color:$status_color;\" width=\"15\" height=\"15\">$status_sign</div></td><td>$name</td><td>$host</td></tr>";  
    		}  
    ?>  
    		</table></p> 
    <?
    	}
    
    	function myround($amt,$dec="3"){
    		ob_start();
    		if($dec == 2){
    			printf("%6.2f",$amt);
    		}else{
    			printf("%6.3f",$amt);
    		}
    		$amount = ob_get_contents();
    		ob_end_clean(); 
    		$amount = str_replace(" ","",$amount);
    		return $amount;
    	}
    
    	class fptime{
    		function fptime(){
    			return 1;
    		}
    
    		function mytime($stamp="",$format="m/d/Y"){
    			return date( $format,($stamp ? $stamp : time()) );
    		}
    
    		function stamp($mm,$dd,$yy,$hh=0,$min=0,$sec=0){
    			return mktime($hh,$min,$sec,$mm,$dd,$yy);
    		}
    
    		function subhours($interval,$mm,$dd,$yy,$hh,$m,$s){
    			return $this->stamp( $mm,$dd,$yy,($hh-$interval),$m,$s );
    		}
    
    		function addhours($interval,$mm,$dd,$yy,$hh,$m,$s){
    			return $this->stamp( $mm,$dd,$yy,($hh+$interval),$m,$s );
    		}
    
    		function subdays($interval,$mm,$dd,$yy){
    			return $this->stamp($mm,($dd-$interval),$yy);
    		}
    
    		function adddays($interval,$mm,$dd,$yy,$hh=0,$min=0,$sec=0){
    			return $this->stamp($mm,($dd+$interval),$yy,$hh,$min,$sec);
    		}
    
    		function submonths($interval,$mm,$dd,$yy){
    			return $this->stamp( ($mm-$interval),$dd,$yy );
    		}
    
    		function addmonths($interval,$mm,$dd,$yy){
    			return $this->stamp( ($mm+$interval),$dd,$yy );
    		}
    
    		function subyears($interval,$mm,$dd,$yy){
    			return $this->stamp( $mm,$dd,($yy-$interval) );
    		}
    
    		function addyears($interval,$mm,$dd,$yy){
    			return $this->stamp( $mm,$dd,($yy+$interval) );
    		}
    
    		function DateDiff ($interval, $date1,$date2) {
    			// get the number of seconds between the two dates
    			$timedifference =  $date2 - $date1;
    			switch ($interval) {
    				case "w":
    					$retval = $timedifference/604800;
    					$retval = floor($retval);
    					break;
    				case "d":
    					$retval = $timedifference/86400;
    					$retval = floor($retval);
    					break;
    				case "h":
    					$retval = $timedifference/3600;
    					$retval = floor($retval);
    					break;
    				case "n":
    					$retval = $timedifference/60;
    					$retval = floor($retval);
    					break;
    				case "s":
    					$retval  = floor($timedifference);
    					break;
    			}
    			return $retval;
    		}
    
    		function dateNow($format="%Y%m%d"){
    			return(strftime($format,time()));
    		}
    
    		function dateToday(){
    			$ndate = time();
    			return( $ndate );
    		}
    
    		function daysInMonth($month="",$year=""){
    			if(empty($year)) {
    				$year = $this->dateNow("%Y");
    			}
    			if(empty($month)) {
    				$month = $this->dateNow("%m");
    			}
    			if($month == 2) {
    				if($this->isLeapYear($year)) {
    					return 29;
    				} else {
    					return 28;
    				}
    			} elseif($month == 4 or $month == 6 or $month == 9 or $month == 11) {
    				return 30;
    			} else {
    				return 31;
    			}
    		}
    
    		function isLeapYear($year=""){
    			if(empty($year)) {
    				$year = $this->dateNow("%Y");
    			}
    			if(strlen($year) != 4) {
    				return false;
    			}
    			if(preg_match("/\D/",$year)) {
    				return false;
    			}
    			return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
    		}
    	}
    ?>
    PHP:
     
    UKmember, Jun 14, 2008 IP
  2. Spawny

    Spawny Well-Known Member

    Messages:
    252
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #2
    you cant use $this outside of an object

        $this->min_pass_length="8";
        $this->max_pass_length="12";
        $this->chars='abcdefghijklmnopqrstuvwxyz0123456789';
    Code (markup):
     
    Spawny, Jun 14, 2008 IP
  3. UKmember

    UKmember Well-Known Member

    Messages:
    1,588
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Can you tell me how to fix this so the site works?
     
    UKmember, Jun 14, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    What do you even use those 3 lines for?

    I had a quick look through and couldn't see them referenced at all, although I could just be getting old and have missed it.

    Instead of $this = new [class]; use $[name] = new [class]. e.g. $file = new File;

    Interestingly I can't see a class declaration either in your code.

    Dan
     
    Danltn, Jun 14, 2008 IP