forumsharry Posted December 1, 2007 Share Posted December 1, 2007 hi i have a very serious problem i am not able to call underlying class from the function that is given in the last can some body help please ASAP <?php session_start(); include("common common.php"); // global variable declaration & assignment $action = $_GET['action']; $goto = $_GET['goto']; $d = new MAKEpasswd(); $d-> DB_connect(); $SQL = "SELECT * FROM filedb ORDER BY urlname DESC"; mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS); //mysql_select_db(MYSQL_DB); result = mysql_query($SQL); found = mysql_num_rows($result); $d->DB_close(); while ($row = mysql_fetch_array($result)) { $urlnameArray[] = $row['urlname']; $filenameArray[] = $row['path']; } ?> 2) common common.php <?php class MAKEpasswd{ var $intLength; var $pool; function MAKEpasswd($iLength, $iChars) { $this->intLength = $iLength; $this->pool = $this->getPool($iChars); } function getPool($iChars){ switch($iChars) { case 1: /* a - z */ for($i = 0x61; $i <= 0x7A; $i++) { $str .= chr($i); } return $str; break; case 2: /* A - Z */ for($i = 0x41; $i <= 0x5A; $i++) { $str .= chr($i); } return $str; break; case 3: /* a - z and A - Z */ $str = $this->getPool(1); $str .= $this->getPool(2); return $str; break; case 4: /* 0 - 9, A - Z and a - z */ $str = $this->getPool(3); // get chars a - z and A - Z first for($i = 0x30; $i <= 0x39; $i++) { $str .= chr($i); // add chars 0 - 9; } return $str; break; case 5: /* This will add these chars into the string !#$%&() */ $str = $this->getPool(4); for($i = 0x30; $i <= 0x39; $i++) { $str .= chr($i); } return $str; break; } } function makePassword() { srand ((double) microtime() * 1000000); $str=""; while(strlen($str)< $this->intLength) { $str.=substr($this->pool,(rand()%(strlen($this->pool))),1); } return($str); } } function pwdGen() { $generate = new MAKEpasswd(8,5); $newpass = $generate->makePassword(); return $newpass; } // thumbnail creator and image size adjuster, requires GD 2.0.1 (PHP >= 4.0.6) function thumbnail($image_path, $thumb_path, $image_name, $thumb_name, $thumb_width, $thumb_height, $percent) { // check the image file extension if (strstr(strtolower($image_name), ".gif")) $format = "GIF"; else if (strstr(strtolower($image_name), ".jpg") || strstr(strtolower($file), ".jpeg")) $format = "JPEG"; else if (strstr(strtolower($image_name), ".png")) $format = "PNG"; if ($format) { // if valid image file is present switch ($format) { case "GIF": if (function_exists('ImageCreateFromGif')) $src_img = ImageCreateFromGif("$image_path/$image_name"); break; case "JPEG": $src_img = Imagecreatefromjpeg("$image_path/$image_name"); break; case "PNG": $src_img = ImageCreateFromPng("$image_path/$image_name"); break; } $origw=imagesx($src_img); $origh=imagesy($src_img); if ($thumb_width && $thumb_height) { // if thumbnail's width and height are given $new_w = $thumb_width; $new_h = $thumb_height; } else if ($percent) { // if percentage is given $new_w = (int) ($origw * ($percent / 100)); $new_h = (int) ($origh * ($percent / 100)); } $dst_img = imagecreatetruecolor($new_w,$new_h); //$dst_img = imagecreate($new_w,$new_h); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img)); // ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $new_w,$new_h, imagesx($src_img), imagesy($src_img)); switch ($format) { case "GIF": if (function_exists('ImageGif')) ImageGif($dst_img, "$thumb_path/$thumb_name"); break; case "JPEG": ImageJpeg($dst_img, "$thumb_path/$thumb_name"); break; case "PNG": ImagePng($dst_img, "$thumb_path/$thumb_name"); break; } ImageDestroy($dst_img); } } # Usage: pass a valid filename parameter into the function # this function will return an array of the content function read_file($src) { $i = 0; $handle = fopen($src, 'r'); while (!feof($handle)) { $content[] = trim(fgets($handle, 1024)); //$content[$i] = preg_replace("[\x5c\]" ,"", $content[$i]); $i++; } fclose($handle); return $content; } # usage: pass new data and filename parameter into the function # this function returns true if data is written function write_file($data, $src) { $success = true; if(is_writable($src)) { //$data = preg_replace("[\x5c\]" ,"", $data); $handle = fopen($src, 'w+'); fwrite($handle, trim($data)); fclose($handle); $success = true; } else $success = false; return $success; } // connect to MYSQL database function DB_connect() { if (!mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS)) { popup(DB_CONNECT_FAIL); } mysql_select_db(MYSQL_DB); } // disconnect from MYSQL database function DB_close() { if (!mysql_close(mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS))) { popup(DB_DISC_FAIL); } } // create writable directory or change the chmod permission of chosen directory function check_dir($dir) { if (!file_exists($dir)) { if (mkdir($dir, 0777))// create images dir $done = true; } else if (!is_writeable($dir)) { if (chmod($dir, 0777)) // change perm. setting $done = true; } else $done = true; return $done; } // create new file function create_file($filename) { if (!file_exists($filename)) { $fnew = fopen($filename, "w+"); $done = flock($fnew, 1); fclose($fnew); if (!is_writeable($filename)) // check if file is writable chmod($filename, 0777); } else { popup(FM_FILE_EXIST); } return $done; } // go back to prev page function backtrack() { echo "<SCRIPT LANGUAGE='JAVASCRIPT'>"; echo "history.back();"; echo "</SCRIPT>"; } // open new page function openwindow($url, $target) { echo "<SCRIPT LANGUAGE='JAVASCRIPT'>"; echo "window.open('$url','$target');"; echo "</SCRIPT>"; } // change month figure to words function changeMonth($month) { switch($month) { case 1: $month = "January"; break; case 2: $month = "February"; break; case 3: $month = "March"; break; case 4: $month = "April"; break; case 5: $month = "May"; break; case 6: $month = "June"; break; case 7: $month = "July"; break; case 8: $month = "August"; break; case 9: $month = "September"; break; case 10: $month = "October"; break; case 11: $month = "November"; break; case 12: $month = "December"; break; default: $month = "Invalid"; break; } return $month; } // set selected value in form's dropdown list function set_selected($value1, $value2) { if ($value1 == $value2) echo "selected"; } // set checked option in form's radio button function set_checked($value1, $value2) { if ($value1 == $value2) echo "checked"; } // popup message function function popup($message) { echo "<SCRIPT LANGUAGE='JAVASCRIPT'>"; echo "alert('$message')"; echo "</SCRIPT>"; } // get the client/remote IP address function getip() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $ip = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $ip = getenv( 'HTTP_CLIENT_IP' ); } else { $ip = getenv( 'REMOTE_ADDR' ); } } return $ip; } // remove given directory along with all the contents in it function purge($dir) { $done = false; $handle = opendir($dir); while (false !== ($file = readdir($handle))) { // search for content in the directory and delete them if ($file != "." && $file != "..") { if (is_dir($dir . $file)) { purge($dir . $file . "/"); //rmdir($dir . $file); } else { unlink($dir . $file); } } } closedir($handle); rmdir($dir); // finally, remove the directory if (!file_exists($dir)) // check if the directory has already been erased $done = true; return $done; } function suspend($userID) { $suspended = false; $SQL1 = "SELECT isAdmin, isMember, creation_date FROM userdb WHERE userID=$userID"; $SQL2 = "SELECT membership FROM member WHERE userID=$userID"; DB_connect(); $row1 = mysql_fetch_array(mysql_query($SQL1)); $row2 = mysql_fetch_array(mysql_query($SQL2)); DB_close(); if (!$row1['isAdmin'] && $row1['isMember']) { list($year, $month, $date, $hour, $min, $sec) = sscanf($row1[creation_date], "%4d%2d%2d%2d%2d%2d"); $month = $month + $row2['membership']; if ($month >= 12) { $totalYear = $month / 12; $totalYear = round($totalYear,0); $month = $month % 12; $year += $totalYear; } if ($hour < 10) $hour = "0".$hour; if ($min < 10) $min = "0".$min; if ($sec < 10) $sec = "0".$sec; if ($month < 10) $month = "0".$month; if ($date < 10) $date = "0".$date; $expiryDate = "$year$month$date$hour$min$sec"; $currentDate = date("YmdHis"); if ($currentDate >= $expiryDate) { // if the expiry date exceeds the current date $suspended = true; $SQL = "INSERT INTO suspend VALUES($userID)"; DB_connect(); mysql_query($SQL); DB_close(); } } return $suspended; } ?> EDITED BY WILDTEEN88: Please use code tags ( ) when posting code. Link to comment https://forums.phpfreaks.com/topic/79676-cannot-call-class-from-the-function/ Share on other sites More sharing options...
trmbne2000 Posted December 2, 2007 Share Posted December 2, 2007 Two things I notice: In common_common.php, your constuctor method (MAKEpasswd) has two arguments, $iLength, and $iChars. Those arguments are not passed when you instantiate the object in the first code block. Also, your class ends right after "function makePassword() {...".DB_connect is not a member method, so it can't be called on the object reference. Link to comment https://forums.phpfreaks.com/topic/79676-cannot-call-class-from-the-function/#findComment-404485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.