timmah1 Posted October 1, 2009 Share Posted October 1, 2009 I'm trying to help a friend, and I have no idea why I'm getting this error. Fatal error: Using $this when not in object context in /home/include/common.php on line 11 This is the code <?php session_start(); include("config.php"); $att_path = "./uploads"; $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; ?> Can anyone help me out here? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/176202-this/ Share on other sites More sharing options...
lemmin Posted October 1, 2009 Share Posted October 1, 2009 It is exactly what the error says: you are using $this (referring to the current object) when the code is not inside of an object. Where are those three variables that follow $this-> defined? Quote Link to comment https://forums.phpfreaks.com/topic/176202-this/#findComment-928558 Share on other sites More sharing options...
timmah1 Posted October 1, 2009 Author Share Posted October 1, 2009 I guess that's the problem, because I'm not sure Here is the header file <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <title><?=$sitename?></title> <meta http-equiv='Content-Type' content='text/html; charset=windows-1252'/> <link href='style.css' type='text/css' rel='stylesheet'/> </head> <body bgcolor="F2F2F2"> <p><b><a href="index.php">Home</a></b> | <b><a href="rules.php">Rules</a></b> | <b><a href="faq.php">F.A.Q.</a></b> | <b><a href="join.php">Join</a></b> | <b> <a href="account.php">Account</a></b> | <b><a href="contactus.php">Contact Us</a></b></p> Here is the index file <? include("include/common.php"); include("include/header.php"); ?> <table width="85%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <p> </p> </p> </td> </tr> <tr> <td> <div align=center> <form ENCTYPE="multipart/form-data" method="post" name="form1" action="upload.php"> <INPUT NAME="attached" TYPE="file" size="50"><br> File extensions allowed: <b><?=implode("</b>, <b>",explode("|",$att_filetypes))?></b><br> File size limit: <b><?=$att_max_size?>KB</b> <br><br> <input type="submit" name="submit" value="Upload File"> </form> </div> </td> </tr> </table> <? include("include/footer.php"); ?> And the common file where the error is happening <?php session_start(); include("config.php"); $att_path = "./uploads"; $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 bgcolor=#ffffff 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 bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#C0C0C0' STYLE='border-collapse: collapse'>"; $table2 = "<TABLE class=design bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#C0C0C0' STYLE='border-collapse: collapse'>"; $table3 = "<TABLE class=design bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#C0C0C0' 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 = " "; } 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 writecombo($array_name, $name, $selected = "", $start = 0, $add_text = "", $add_text2 = "") { $length = count ($array_name); if (($array_name == "") || ($length == 0)){ echo "<select name=\"$name\"></select>\n"; }else{ echo "<select name=\"$name\" $add_text $add_text2>\n"; while (list($key, $val) = @each($array_name)) { if( !is_array($val) ){ $select_name = $val; $i = $key; echo " <option value=\"$i\""; if ($i == $selected){ echo " selected"; } echo ">$select_name</option>\n"; } } echo "</select>\n"; } } 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); } } $month_values= array( "0"=>"--", "1"=>"Jan", "2"=>"Feb", "3"=>"Mar", "4"=>"Apr", "5"=>"May", "6"=>"Jun", "7"=>"Jul", "8"=>"Aug", "9"=>"Sep", "10"=>"Oct", "11"=>"Nov", "12"=>"Dec", ); $day_values= array( "0"=>"--", "1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", "6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9", "10"=>"10", "11"=>"11", "12"=>"12", "13"=>"13", "14"=>"14", "15"=>"15", "16"=>"16", "17"=>"17", "18"=>"18", "19"=>"19", "20"=>"20", "21"=>"21", "22"=>"22", "23"=>"23", "24"=>"24", "25"=>"25", "26"=>"26", "27"=>"27", "28"=>"28", "29"=>"29", "30"=>"30", "31"=>"31", ); ?> I'm not sure where that is declared Quote Link to comment https://forums.phpfreaks.com/topic/176202-this/#findComment-928560 Share on other sites More sharing options...
timmah1 Posted October 1, 2009 Author Share Posted October 1, 2009 I'm assuming that this is there because of the join page. I found this on there if($submit3) { if(!ereg("^[A-Za-z0-9_]{1,16}$",$susername)) { $serror="Invalid username! Use no more than 15 characters and only letters, numbers, and underscores.<br>"; } $this->c=@mysql_query("select username from users25 where username='$susername'"); $this->d=mysql_fetch_object($this->c); if(is_object($this->d)) { $serror="Username is already in use<br>"; } $this->c=@mysql_query("select username from pending25 where username='$susername'"); $this->d=mysql_fetch_object($this->c); if(is_object($this->d)) { $serror="Username is already in use<br>"; } if (!$serror) { mt_srand((double)microtime()*1000000^getmypid()); $pass_length = mt_rand($this->min_pass_length,$this->max_pass_length); while(strlen($spassword)<$pass_length) { $spassword.=substr($this->chars,(mt_rand()%strlen($this->chars)),1); } include("include/emails.php"); $signupmessage=str_replace("<username>","$susername",$signupmessage); $signupmessage=str_replace("<password>","$spassword",$signupmessage); $signupmessage=str_replace("<first_name>","$sfirst_name",$signupmessage); $signupmessage=str_replace("<last_name>","$slast_name",$signupmessage); $signupmessage=str_replace("<login_url>","$login_url",$signupmessage); $subject = "$signupsubject"; $message = "$signupmessage"; mail($semail,$subject,$message,"From: $admin25email"); $admin25signupmessage = str_replace("<username>","$susername",$admin25signupmessage); $admin25signupmessage = str_replace("<password>","$spassword",$admin25signupmessage); $admin25signupmessage = str_replace("<first_name>","$sfirst_name",$admin25signupmessage); $admin25signupmessage = str_replace("<last_name>","$slast_name",$admin25signupmessage); $admin25signupmessage = str_replace("<member_email>","$semail",$admin25signupmessage); $subject = "$admin25signupsubject"; $message = "$admin25signupmessage"; mail($admin25email,$subject,$message,"From: $admin25email"); $nowdate = date("M d, Y"); mysql_query("insert into users25 (uid, username, password, first_name, last_name, street, city, state, zip, country, email, telephone, last_paid, signup_date) values ('','$susername', '$spassword', '$sfirst_name', '$slast_name', '$sstreet', '$scity', '$sstate', '$szip', '$scountry', '$semail', '$stelephone', 'free', '$nowdate')"); echo "<h3>Signup for a New Account Complete</h3>$table2 <tr><td align=center>Thank you for signing up $susername. We have sent you a welcome email to <b>$semail</b> with your password.</table>"; } Quote Link to comment https://forums.phpfreaks.com/topic/176202-this/#findComment-928565 Share on other sites More sharing options...
Alex Posted October 1, 2009 Share Posted October 1, 2009 $this is used to access a property or method of a class that you're currently in. eg: class SomeClass { private $name = 'Alex'; function __construct() { echo $this->name; } } $class = new SomeClass(); // Alex I'd suggest you read up on PHP OOP Quote Link to comment https://forums.phpfreaks.com/topic/176202-this/#findComment-928603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.