Category Archives: PHP

PHP: How to parse MHT file into HTML

PHP parsing MHT file, using the editor to open, you can see Base64 encoding, so MHT can be converted into HTML.

<?php

/**
* Parsing for Mht format files
* Example of use:
*  
*  function mhtmlParseBody($filename) {

	if (file_exists ( $filename )) {
		if (is_dir ( $filename )) return false;
		
		$filename = strtolower ( $filename );
		if (strpos ( $filename, '.mht', 1 ) == FALSE) return false;
			
		
		$o_mhtml = new mhtml ();
		$o_mhtml->set_file ( $filename );
		$o_mhtml->extract ();
		return $o_mhtml->get_part_to_file(0);

	}
	return null;
}

function mhtmlParseAll($filename) {

	if (file_exists ( $filename )) {
		if (is_dir ( $filename )) return false;

		$filename = strtolower ( $filename );
		if (strpos ( $filename, '.mht', 1 ) == FALSE) return false;
			

		$o_mhtml = new mhtml ();
		$o_mhtml->set_file ( $filename );
		$o_mhtml->extract ();
		return $o_mhtml->get_all_part_file();

	}
	return null;
}
*/

class mhtparse {

	var $file = '';
	var $boundary = '';
	var $filedata = '';
	var $countparts = 1;
	var $log = '';
	
	function extract() {
		$this->read_filedata ();
		$this->file_parts ();

		return 1;
	}
	
	function set_file($p) {
		$this->file = $p;
	}
	
	function get_log() {
		return $this->log;
	}
	
	function file_parts() {
		$lines = explode ( "\n", substr ( $this->filedata, 0, 8192 ) );
		foreach ( $lines as $line ) {
			$line = trim ( $line );
			if (strpos ( $line, '=' ) !== FALSE) {
				if (strpos ( $line, 'boundary', 0 ) !== FALSE) {
					$range = $this->getrange ( $line, '"', '"', 0 );
					$this->boundary = "--" . $range ['range'];
					$this->filedata = str_replace ( $line, '', $this->filedata );
					break;
				}
			}
		}
		if ($this->boundary != '') {
			$this->filedata = explode ( $this->boundary, $this->filedata );
			unset ( $this->filedata [0] );
			$this->filedata = array_values ( $this->filedata );
			$this->countparts = count ( $this->filedata );
		} else {
			$tmp = $this->filedata;
			$this->filedata = array (
					$tmp 
			);
		}
	}
	
	function get_all_part_file() {
		return $this->filedata;
	}
	
	function get_part_to_file($i) {
		$line_data_start = 0;
		$encoding = '';
		$part_lines = explode ( "\n", ltrim ( $this->filedata [$i] ) );
		foreach ( $part_lines as $line_id => $line ) {
			$line = trim ( $line );
			if ($line == '') {
				if (trim ( $part_lines [0] ) == '--')
					return 1;
				$line_data_start = $line_id;
				break;
			}
			if (strpos ( $line, ':' ) !== FALSE) {
				$pos = strpos ( $line, ':' );
				$k = strtolower ( trim ( substr ( $line, 0, $pos ) ) );
				$v = trim ( substr ( $line, $pos + 1, strlen ( $line ) ) );
				if ($k == 'content-transfer-encoding') {
					$encoding = $v;
				}
				if ($k == 'content-location') {
					$location = $v;
				}
				if ($k == 'content-type') {
					$contenttype = $v;
				}
			}
		}
		
		foreach ( $part_lines as $line_id => $line ) {
			if ($line_id <= $line_data_start)
				$part_lines [$line_id] = '';
		}
		
		$part_lines = implode ( '', $part_lines );
		if ($encoding == 'base64')
			$part_lines = base64_decode ( $part_lines );
		elseif ($encoding == 'quoted-printable')
			$part_lines = imap_qprint ( $part_lines );
		
		return $part_lines;
	}
	
	function read_filedata() {
		$handle = fopen ( $this->file, 'r' );
		$this->filedata = fread ( $handle, filesize ( $this->file ) );
		fclose ( $handle );
	}
	
	function getrange(&$subject, $Beginmark_str = '{', $Endmark_str = '}', $Start_pos = 0) {
		/*
		 * $str="sssss { x { xx } {xx{xx } x} x} sssss"; $range=string::getRange($str,'{','}',0); echo $range['range']; //tulem: " x { xx } {xx{xx } x} x" echo $range['behin']; //tulem: 6 echo $range['end']; //tulem: 30 (' ') -- l5pumärgist järgnev out: array('range'=>$Range,'begin'=>$Begin_firstOccurence_pos,'end'=>$End_sequel_pos) | false v1.1 2004-2006,Uku-Kaarel J5esaar,[email protected],http://www.hot.ee/ukjoesaar,+3725110693
		 */
		if (empty ( $Beginmark_str ))
			$Beginmark_str = '{';
		$Beginmark_str_len = strlen ( $Beginmark_str );
		
		if (empty ( $Endmark_str ))
			$Endmark_str = '}';
		$Endmark_str_len = strlen ( $Endmark_str );
		
		/* $Start_pos_cache = 0; */
		do {
			/* !algus */
			if (! is_int ( $Begin_firstOccurence_pos ))
				$Start_pos_cache = $Start_pos;
				
				/* ?algus-test */
			$Start_pos_cache = @strpos ( $subject, $Beginmark_str, $Start_pos_cache );
			
			/* this is possible start for range */
			if (is_int ( $Start_pos_cache )) {
				/* skip */
				$Start_pos_cache = ($Start_pos_cache + $Beginmark_str_len);
				/* test possible range start pos */
				if (is_int ( $Begin_firstOccurence_pos )) {
					if ($Start_pos_cache < $range_end_pos)
						$rangeClean = 0;
					elseif ($Start_pos_cache > $range_end_pos)
						$rangeClean = 1;
				}
				/* here it is */
				if (! is_int ( $Begin_firstOccurence_pos ))
					$Begin_firstOccurence_pos = $Start_pos_cache;
			} /* VIGA NR 0 ALGUST EI OLE */
			
			if (! is_int ( $Start_pos_cache )) {
				/* !algus */
	/* VIGA NR 1 ALGUSMARKI EI LEITUD : VIIMANE VOIMALIK ALGUS */
	if (is_int ( $Begin_firstOccurence_pos ) and ($Start_pos_cache < $range_end_pos))
					$rangeClean = 1;
				else
					return false;
			}
			if (is_int ( $Begin_firstOccurence_pos ) and ($rangeClean != 1)) {
				if (! is_int ( $End_pos_cache ))
					$End_sequel_pos = $Begin_firstOccurence_pos;
				
				$End_pos_cache = strpos ( $subject, $Endmark_str, $End_sequel_pos );
				
				/* ok */
				if (is_int ( $End_pos_cache ) and ($rangeClean != 1)) {
					$range_current_lenght = ($End_pos_cache - $Begin_firstOccurence_pos);
					$End_sequel_pos = ($End_pos_cache + $Endmark_str_len);
					$range_end_pos = $End_pos_cache;
				}
				/* VIGA NR 2 LOPPU EI LEITUD */
				if (! is_int ( $End_pos_cache ))
					if ($End_pos_cache == false)
						return false;
			}
		} while ( $rangeClean < 1 );
		
		if (is_int ( $Begin_firstOccurence_pos ) and is_int ( $range_current_lenght ))
			$Range = substr ( $subject, $Begin_firstOccurence_pos, $range_current_lenght );
		else
			return false;
		
		return array (
				'range' => $Range,
				'begin' => $Begin_firstOccurence_pos,
				'end' => $End_sequel_pos 
		);
	} // end getrange()
} // class


?>

 

 

PHP: How to get the total number of data in the MySQL table (total number of rows)

RewCount (): Returns the number of rows affected:

 $sql='select * from '.$_POST['fname'].'_blog_data';
		 $sth=$pdo->query($sql);
		 die('<script>alert('.$sth->rowCount().')</script>');

2

$q = $pdo->query("SELECT count(*) from w_login_record;"); $rows = $q->fetch(); $rowCount = $rows[0];
		 die('alter("'.$rowCount.'")');

3

Use the fetchAll function $q = $db->query("SELECT ..."); $rows = $q->fetchAll(); $rowCount = count($rows);

How to Hide index.php

 
 

 
 
 

server {
        listen        80;
        server_name  www.mxscs.com;
        root   "D:/develop_soft/daima_mxs/ib_crm_bonus";
        location/{
           if (!-e $request_filename) {  
                rewrite ^/(.*)$ /index.php/$1 last;
                break;
            }
            index index.php index.html error/index.html;
            error_page 400 /error/400.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 500 /error/500.html;
            error_page 501 /error/501.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            error_page 504 /error/504.html;
            error_page 505 /error/505.html;
            error_page 506 /error/506.html;
            error_page 507 /error/507.html;
            error_page 509 /error/509.html;
            error_page 510 /error/510.html;
            include D:/develop_soft/daima_mxs/ib_crm_bonus/nginx.htaccess;
            autoindex  off;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

 

composer Error: The requested PHP extension ext-bcmath * is missing from your system. Install or enable

The requested PHP extension exit-BCMath * is missing from your system. Install or enable PHP’s BCMath extension. The requested PHP extension exit-BCMath * is missing from your system.
Install the PHP BCMath extension 1. First check your own PHP version 2. After the installation is complete, restart php4. Check to see if the PHP extension is installed successfully

An error

$ composer require --prefer-dist yiisoft/yii2-mongodb                            
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Using version ^2.1 for yiisoft/yii2-mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested PHP extension ext-bcmath * is missing from your system. Install or enable PHP's bcmath extension.
  Problem 2
    - The requested PHP extension ext-mcrypt * is missing from your system. Install or enable PHP's mcrypt extension.


Installation failed, reverting ./composer.json to its original content.

Solution: Install the BCMath extension for PHP
1. Check your own version of PHP first

php -v

2. Install the corresponding version of the extension

yum  -y install php72w-bcmath

Note: 72W represents version 7.2. Please specify the version number when installing
3. After the installation is complete, restart PHP

service php-fpm restart  或  systemctl restart php-fpm

4. Check to see if the PHP extension was installed successfully

php -m

Leetcode 357: How to calculate the number of digits with different digits

Such a simple thing, mentality exploded, the first glance will know very simple, originally intended to do half an hour, the results tamper tamper and nearly 50 minutes, but also in the middle of debugging several times, the algorithm is not really can’t.
AC after the state of mind and exploded, this know this is a digit dp, but I use greed (turns out not greedy), thought for a long time also did not think of how to do with dp, in the burst of time, the original dp is to store the value of one place, ten place just

int countNumbersWithUniqueDigits(int n) {
	if(0==n)
		return 1;
	if(n<0 || n>10)
		return 0;
	int ret = 0;
	for(int i=n;i>=1;--i)
	{
		int ret1 = 1;
		int num = 9;
		for(int j=0;j<i;++j)
		{
			ret1 *= num;
			num = 0==j ?num : num-1;
		}
		ret += ret1;
	}
	return ret+1;
}

nginx.conf php-fpm.conf and php.ini Error among the three_ Differences and relations between log instructions

The error_log directive is found in the configuration file nginx.conf of Nginx, the configuration file PHp-fPM, and php.ini. This article attempts to briefly explain the differences and associations between these three configurations.

php.ini
The error_log </ code> string
Sets the file to which script errors will be logged. This file must be writable by the Web server user. If the special value syslog is set, an error message is sent to the system logger. On Unix and similar systems, syslog(3) is used, while on Windows NT-class systems it is event logging. System logging is not supported on Windows 95. See: syslog(). If this configuration is not set, an error message is sent to the SAPI error logger. For example, an error appears in an Apache error log or is sent to Stderr in the CLI.

PHP – FPM. Conf
The error_log </ code> string
Location of the error log. Default: #INSTALL_PREFIX#/log/ php-pm. log. If set to "syslog", the log will not be written to the local file, but will be sent to syslogd.

nginx.conf
The

Syntax: </ th>

error_log file </ code> ( level </ code>];

Default:
error_log logs/error.log error;
Context: mainhttpmailstreamserverlocation

Configures logging. Several logs can be specified on the same level (1.5.2). If on the main configuration level writing a log to a file is not explicitly defined, the default file will be used.
The first parameter defines a file that will store the log. The special value stderr selects the standard error file. Logging to syslog can be configured by specifying the “syslog:” prefix. Logging to a cyclic memory buffer can be configured by specifying the “memory:” prefix and buffer size, and is generally used for debugging (1.7.11).
The second parameter determines the level of logging, and can be one of the following: debuginfonoticewarnerrorcritalert, or emerg. Log levels above are listed in the order of increasing severity. Setting a certain log level will cause all messages of the specified and more severe log levels to be logged. For example, the default level error will cause errorcritalert, and emerg messages to be logged. If this parameter is omitted then error is used.

From the above documentation, it is initially clear that error_log has a higher priority in php.ini, so let’s experiment with these combinations of configurations in turn.
The test reports errors using the following simple php code.

<?php
throw new Exception('foobar');

The configuration values of each error_log are as follows:

Nginx: error_log/var/log/nginx/error log.
Php-fpm: error_log = /var/log/php-fpm/error.log
Php.ini: error_log = /var/log/ PHP /error.log

1. When three values are configured at the same time, the PHP error log will be written to the file specified by the error_log in php.ini

[21-Apr-2019 22:19:13 Asia/Shanghai] PHP Fatal error: Uncaught Exception: Foobar in/usr/share/nginx/HTML/error. PHP: 5
the Stack trace: # 0 {main}

thrown in/usr/share/nginx/HTML/error. PHP on line 5

But what if the error_log specifies a file that does not have writable permissions, would it be logged into the error_log file of nginx or PHP-FPM?The answer is no, and the error message is lost because it cannot be written.
2. Do not configure the error_log in php.ini, and configure the error_log in nginx.conf and PHp-fPm.conf. At this time, the error log will be written to the error_log file of Nginx

2019/04/21 22:33:04 [Error] 2031#0: *102 FastCGI sent in stderr: “PHP message: PHP Fatal error: Uncaught Exception: Foobar in/usr/share/nginx/HTML/error. PHP: 5
the Stack trace: # 0 {main}

thrown in/usr/share/nginx/HTML/error. PHP on line 5 “while reading the response headers from upstream, the client: 127.0.0.1, server: _, request: “GET /error.php HTTP/1.1”, upstream: “fastcgi:// 127.0.0.9000 “, host: “127.0.0.1”

3. Since nginx error_log does not support shutdown, it is impossible to compare the priority of error_log between Nginx. conf and PHP-fpm. In fact, the error_log in PHP-fpm conf is not used to record PHP error messages, but to record some runtime information of the PHP-FPM process itself.
4. Although error_log in PHP-fPm.conf does not record PHP error information, php_value/php_flag or php_admin_value/ php_ADMIN_flag configuration can be used to override the configuration in PHp.ini:

You can also pass additional environment variables to a run pool, or update PHP configuration values. This can be done in the process pool configuration file with the following configuration parameters:
Example #1 passes environment variables to the runtime pool and sets the configuration values for PHP

env[HOSTNAME] = $HOSTNAME
       env[PATH] = /usr/local/bin:/usr/bin:/bin
       env[TMP] = /tmp
       env[TMPDIR] = /tmp
       env[TEMP] = /tmp

       php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
       php_flag[display_errors] = off
       php_admin_value[error_log] = /var/log/fpm-php.www.log
       php_admin_flag[log_errors] = on
       php_admin_value[memory_limit] = 32M

PHP configuration values are passed
Php_value or
Php_flag is set and overrides previous values. Please note that
Disable_functions or
The value defined in DISABle_classes in php.ini is not overridden, but the new setting is appended to the original value.
Values defined using php_ADMIN_value or php_ADMIN_flag cannot be overridden by ini_set() in PHP code.

For example, if you configure php_admin_value[error_log] in PHp-fpm.conf = /var/log/php-fpm/www-error.log, and configure error_log in php.ini, you will find that the PHP error message will be written into the /var/log/php-fpm/www-error.log file
Conclusion:
Error_log Priority: PHp_value [error_log]/php_admin_value[error_log] in PHP-pm.conf
Greater than PHP ini the error_log
The error_log is greater than the nginx. Conf
The error_log in PHP-pm.conf has nothing to do with logging an error message when PHP is running.
The easiest way to get PHP error logging is to look at the phpInfo () message and see the value of the error_log. If there is a value, the error logging is recorded where the value is specified, and if there is no error logging, it is recorded in nginx’s error_log.

Some frameworks use set_exception_handler and set_error_handler, as well as register_shutdown_function to reset the exception handling and error reporting, and may write the error log to another place, so in a development environment, temporarily open display_errors. This is the fastest way to locate errors.
That’s all

How to solve Magento 500 internal server errors

Many users encounter some weird Magento 500 Internal Server Errors (Error type 500). I will try to list the most common solutions. These errors are not always caused by the same reason. You should try to take a look at your server’s error logs to get some help about this error.You can get additional info about the errors by Turning on Developer Mode.  Look in the Magento bootstrap file (index.php), you’ll see lines similar to the following

#Mage::setIsDeveloperMode(true);  
#ini_set(‘display_errors’, 1);  

Uncomment these. In a production system, you’d never want to have your errors display to the browser, but while developing having an errors and warnings thrown immediately in your face is invaluable.  This way, you will see the actually problem which lead to the Internal Error Server. In almost cases, the reason is that there is an exception throw after output is sent to browser.

Solution #1

This error might be caused because you have not set the correct permissions for the magento folders. To solve this go to File Manager and then change the file permission of index.php file from 664 to 644.  Also change the permissions of downloader/index.php file to 644 as well otherwise when you will try to access System > Magento Connect >Magento Connect Manager (after magento installation) by logging to magento admin,  you will get 500 Internal Server Error.

You can also try this tool, it’s a magento cleanup utility. It will set the correct permissions for your complete magento installation:

    Download itUnzip magento-cleanup.php to the root directory of your magento installationBrowse to http://yourdomain.com/magento/magento-cleanup.php
<?php  
  
## Function to set file permissions to 0644 and folder permissions to 0755  
  
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){  
   $d = new RecursiveDirectoryIterator( $dir );  
   foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){  
      if( $path->isDir() ) chmod( $path, $dirModes );  
      else if( is_file( $path ) ) chmod( $path, $fileModes );  
  }  
}  
  
## Function to clean out the contents of specified directory  
  
function cleandir($dir) {  
  
    if ($handle = opendir($dir)) {  
        while (false !== ($file = readdir($handle))) {  
            if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) {  
                if (unlink($dir.'/'.$file)) { }  
                else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; }  
            }  
            else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) {  
                cleandir($dir.'/'.$file);  
                if (rmdir($dir.'/'.$file)) { }  
                else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; }  
            }  
        }  
        closedir($handle);  
    }  
  
}  
  
function isDirEmpty($dir){  
     return (($files = @scandir($dir)) && count($files) <= 2);  
}  
  
echo "----------------------- CLEANUP START -------------------------<br/>";  
$start = (float) array_sum(explode(' ',microtime()));  
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";  
echo "Setting all folder permissions to 755<br/>";  
echo "Setting all file permissions to 644<br/>";  
AllDirChmod( "." );  
echo "Setting pear permissions to 550<br/>";  
chmod("pear", 550);  
  
echo "<br/>****************** CLEARING CACHE ******************<br/>";  
  
if (file_exists("var/cache")) {  
    echo "Clearing var/cache<br/>";  
    cleandir("var/cache");  
}  
  
if (file_exists("var/session")) {  
    echo "Clearing var/session<br/>";  
    cleandir("var/session");  
}  
  
if (file_exists("var/minifycache")) {  
    echo "Clearing var/minifycache<br/>";  
    cleandir("var/minifycache");  
}  
  
if (file_exists("downloader/pearlib/cache")) {  
    echo "Clearing downloader/pearlib/cache<br/>";  
    cleandir("downloader/pearlib/cache");  
}  
  
if (file_exists("downloader/pearlib/download")) {  
    echo "Clearing downloader/pearlib/download<br/>";  
    cleandir("downloader/pearlib/download");  
}  
  
if (file_exists("downloader/pearlib/pear.ini")) {  
    echo "Removing downloader/pearlib/pear.ini<br/>";  
    unlink ("downloader/pearlib/pear.ini");  
}  
  
echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>";  
If (!isDirEmpty("app/code/local/")) {   
    echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>";  
}  
If (!isDirEmpty("app/code/community/")) {   
    echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>";  
}  
$end = (float) array_sum(explode(' ',microtime()));  
echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";  
?>  

Solution #2
Your server does not support some of the magento specifications. You can easily test this using the magento check utility. Follow the steps below to check your server’s software, if there is an incompatibility this utility will show it.

Download it
Unzip magento-check.php to the root directory of your magento installation
Browse to http://yourdomain.com/magento/magento-check.php


<? 
extension_check(array(   
    'curl',  
    'dom',   
    'gd',   
    'hash',  
    'iconv',  
    'mcrypt',  
    'pcre',   
    'pdo',   
    'pdo_mysql',   
    'simplexml'  
));  
  
function extension_check($extensions) {  
    $fail = '';  
    $pass = '';  
      
    if(version_compare(phpversion(), '5.2.0', '<')) {  
        $fail .= '<li>You need<strong> PHP 5.2.0</strong> (or greater)</li>';  
    }  
    else {  
        $pass .='<li>You have<strong> PHP 5.2.0</strong> (or greater)</li>';  
    }  
  
    if(!ini_get('safe_mode')) {  
        $pass .='<li>Safe Mode is <strong>off</strong></li>';  
        preg_match('/[0-9]\.[0-9]+\.[0-9]+/', shell_exec('mysql -V'), $version);  
          
        if(version_compare($version[0], '4.1.20', '<')) {  
            $fail .= '<li>You need<strong> MySQL 4.1.20</strong> (or greater)</li>';  
        }  
        else {  
            $pass .='<li>You have<strong> MySQL 4.1.20</strong> (or greater)</li>';  
        }  
    }  
    else { $fail .= '<li>Safe Mode is <strong>on</strong></li>';  }  
  
    foreach($extensions as $extension) {  
        if(!extension_loaded($extension)) {  
            $fail .= '<li> You are missing the <strong>'.$extension.'</strong> extension</li>';  
        }  
        else{   $pass .= '<li>You have the <strong>'.$extension.'</strong> extension</li>';  
        }  
    }  
      
    if($fail) {  
        echo '<p><strong>Your server does not meet the following requirements in order to install Magento.</strong>';  
        echo '<br>The following requirements failed, please contact your hosting provider in order to receive assistance with meeting the system requirements for Magento:';  
        echo '<ul>'.$fail.'</ul></p>';  
        echo 'The following requirements were successfully met:';  
        echo '<ul>'.$pass.'</ul>';  
    } else {  
        echo '<p><strong>Congratulations!</strong> Your server meets the requirements for Magento.</p>';  
        echo '<ul>'.$pass.'</ul>';  
  
    }  
}  
?>

Solution #3
If you are getting weird 500 internal server errors on specific pages of your site, it might be a matter of resources. I was getting internal server erros on some product pages and on the http://yourdomain.com/checkout/onepage. I found out that the .htacess file of my magento installation was somehow reset and the php_value memory_limit value was set to 32M as soon as I raised it, the internal server errors vanished! You should use at least 256M for over 600-700 SKUs. Magento is very resource hungry and it is easy to get these kind of errors if you try to save some bucks from the hosting.

Solution #4
Htaccess file which is located at Magento root folder. It will be this case if you meet Internal Server Error on every page. Try to remove it for testing purpose
If your website was running file for a long time, then it must be a change at Server side, just submit a ticket to Hosting Company.

Solution #5 (Comment from Huberto)
If the curl extension is missing you can get 500 Internal server error. You can install it using the command below:

apt-get install curl libcurl3 libcurl3-dev php5-curl  

from: http://www.techjam.gr/2012/magento/solve-magento-500-internal-server-errors/

Using $this when not in object context in (How to Fix)

Error message: The $this reference has no context
Reason: In PHP5, $this cannot be used in static methods of static declarations; you need to use self to refer to methods or variables in the current class.Example code is as follows:

<?php
namespace syhl\admin\page\record;  // namespace

require_once  dirname(__FILE__).'/../../../../common/smarty_loader.php';  

class record {
  
    
     public static function exec($smarty) {    
        
        $ttr=self::getres();
        $smarty->assign("arr",$ttr);      
        $smarty->display ( 'rec_mgr.html' );
    }
   function getres(){
      $arr = array (  
       "1" => 'test',  
       '2' => 'me',  
       array (  
        "3" => "beij",  
        "4" => "zz"  
       ),  
       array (  
        "5",  
        "6" => "ewrwer",  
        "7" => "ssss"  
       )  
      );  
      return $arr;
    }
}
record::exec($smarty);

?>

 

$this(getRes () method in the sample code) is not allowed in the referenced method.

composer Error while processing content unencoding: Unknown failure within decompression softwar

On Composer download file Error [Composer\Downloader\TransportException] Error while Processing content unencoding: Unknown failure within decompression Software. After checking the results returned after running the command, it was found that the problem was not due to compression expansion. The package information was loaded from the local cache and may be out of date. So you can just clear the Composer local cache

Composer clears the cache: Composer ClearCache

Unserialize(): cause analysis and solution of error at offset

Unserialize (): Cause analysis and solution of Error at Offset2016-09-10
Classification: Practical knowledge
Reading (5590).
Comments (0)

In the use of PHP’s unserialize function, the following error occurs when a string or data is fetched from a database in Chinese

Notice: unserialize(): Error at offset xx of xxx bytes in C:\toolmao\php\index.php on line 21

Speaking of Chinese, we must first think of coding, so let’s see how the serialize function handles Chinese with different file codes, using the same piece of code and testing the file with different codes

echo serialize(array('name'=>'Tools','url'=>'http://www.toolmao.com/'));

Looking at the UTF8 effect first, we find that the Length of the Chinese “tool cat” is 9

When the file code is GB2312, the length of Chinese “tool cat” is 6

Therefore, when we take out the database encoding GBK and other Chinese encoding, and then use transcoding function to convert to UTF8, and then use unserialize function, this problem will occur because the length of Chinese in different encodings is different. One might say that SET NAMES is not acceptable when the database is pulled out, but some databases (such as Access and SQLite) do not support this. So when the code does not match, you must take out the data transcoding. So how do you do that?Here’s the solution:
Above, we have already known the cause of Error at offset in unserialize. Therefore, it is easy to solve this problem. Just replace the Error length with the regular function.

unserialize(preg_replace('!s:(\d+):"(.*?)";!se', '"s:".strlen("$2").":\"$2\";"', $string))
From:http://www.phpddt.com/php/unserialize-error-at-offset.html

However, due to the PHP problem, the/E mode has been compromised, so this usage has been removed since PHP5.5, so don’t worry if you are using PHP5.5 +, here is another solution

preg_replace_callback('#s:(\d+):"(.*?)";#s',function($match){return 's:'.strlen($match[2]).':"'.$match[2].'";';},$data);

The above is my actual development encountered in the problem, combined with the solution of the net and their own actual situation finally write the code, I hope to help you!

PHP parse error: syntax error, unexpected ‘use’

After a long search, I finally found the reason, not the PHP version [], that I wrote use in the methods of the class.
This thing cannot be used independently of the class, otherwise it would be considered a namespace.
The test example is as follows

// Trait.php

trait CustomerFunctionsTrait {

    public function plus ( $a = 1, $b = 1 ) { 
        echo $a + $b; 
    }   

    public function minus ( $a = 5, $b = 1 ) { 
        echo $a - $b; 
    }   

}


// Test.php
include './Trait.php';
class MyTest {
    use CustomerFunctionsTrait;
    public function plus () {
        // use CustomerFunctionsTrait;  //This is where I made a mistake, writing use into the method body -!!!!
        echo 'str';
    }
}

$n = new MyTest;
$n->minus();

Fatal error: Function name must be a string in

Fatal error: Function name must be a string in

<?php

if ($_COOKIE('CaptchaResponseValue') == "false")
{
    header('location:index.php');
    return;
}
?>

Amendments.
It should be $_COOKIE[‘ name ‘], not $_COOKIE(‘ name ‘)

<?php

if ($_COOKIE['CaptchaResponseValue'] == "false")
{
    header('location:index.php');
    return;
}
?>

</ div>