[Forgot Password] [Can’t Log In] How to reset WordPress admin password without sending reset email?

So, admit it. We put really strong passwords and then we forget them.
And you end up being locked out of your own website.

So here is how you can reset it quickly.
Go to your hosting control panel and then go to phpMyAdmin if available.

Look into the database which is being used for your wordpress installation and click on Users table

Inside users table, find the row responsible for your admin account. (check the user_nicename column for username match)
and Press edit.

On the editing screen, put your new password again the column password and Choose MD5 in left column FUNCTION

Now scroll down and save this password.

And that’s it. Go to your domain / wp-admin path and login with the new password you just saved.

What to do if you dont have phpMyAdmin?

You gotta have some kind of access to MySQL, so connect to it using the credentials inside wp-config.php file

Use the following command after replacing your details:

UPDATE `wppl_users` SET `user_pass` = 'e0a8aa81eb1762d529783cf587f6f422' WHERE `wppl_users`.`user_nicename` = 'admin';

If you remember the email address only, use:

UPDATE `wppl_users` SET `user_pass` = 'e0a8aa81eb1762d529783cf587f6f422' WHERE `wppl_users`.`user_email` = '[email protected]';

The above command will set your password to abcd@1234. After this command you can login to wordpress admin panel and then reset your password to anything you want. Or use md5.cz to generate md5 for any password string and replace it with e0a8aa81eb1762d529783cf587f6f422

Do NOT forget to replace “wppl_” with your table prefix (stored in wp-config.php file)

Fix Magento 2 – php cli error on cpanel or other hostings

The problem:

On a fresh install of Magento2 on cpanel based hosting, you receive the following error while running any command on SSH

[eee@e1 www]$ php bin/magento cache:clean
X-Powered-By: PHP/7.0.31
Content-type: text/html; charset=UTF-8

bin/magento must be run as a CLI application
[eee@e1 www]$ php bin/magento setup:upgrade
X-Powered-By: PHP/7.0.31
Content-type: text/html; charset=UTF-8

bin/magento must be run as a CLI application

The Solution:

You have to point php to correct binary;
Use the following code in order:
First, open the file which can alter the runtime variables like .bash_profile or .bashrc

cd ~ ; nano .bash_profile
OR
cd ~ ;nano .bashrc

Go to last line and paste this (depending upon php version change ea-php71 or ea-php70):

alias php='/opt/cpanel/ea-php71/root/usr/bin/php'

Save the file and exit the editor.
Log out and login again OR use the following command

$ source ~/.bashrc

If you are not sure about current php version, use which php or php -v command. If you think the cpanel configuration is the issue, fix EasyApache 4 PHP cli issue. With this way you can fix the setting and enable the new php version

How to add colon separated hours in PHP using explode function twice?

Problem Statement

Tracking hours for multiple days are available in HH:MM:SS format separated by tab element. Add all the time to show total hours worked/tracked.

<?php
$a="03:23:28	03:58:54	00:00:00	03:10:49	02:17:33	03:56:38	02:18:23	06:15:42	00:00:00	00:00:00	06:04:51	07:41:09	03:23:15	06:12:59	03:51:27	00:00:00	04:30:06	05:00:23	00:00:00	04:34:25	05:17:02	01:36:21	00:00:00	03:53:20	06:30:52	06:21:47	04:54:16	03:22:28	03:10:35	00:00:00	06:37:11	02:14:22	03:06:49	03:05:44	02:35:54	04:03:22	00:00:00
";
#$a="04:05:21	06:25:39	03:02:36	04:01:17	03:03:21	02:00:36	04:21:54	04:21:35	00:00:00	00:00:00	03:39:21	04:19:17	03:08:14	01:44:48	03:28:11	00:00:00	03:05:53	03:05:34	00:00:00	02:09:17	05:01:13	01:02:20	00:00:00	04:30:51	06:03:49	06:36:35	02:14:01	03:06:38	04:02:09	00:00:00	02:34:29	03:36:30	05:10:17	06:46:19	07:48:08	09:13:34	00:00:00
#";
$a="07:28:49	10:24:33	03:02:36	07:12:06	05:20:54	05:57:14	06:40:17	10:37:17	00:00:00	00:00:00	09:44:12	12:00:26	06:31:29	07:57:47	07:19:38	00:00:00	07:35:59	08:05:57	00:00:00	06:43:42	10:18:15	02:38:41	00:00:00	08:24:11	12:34:41	12:58:22	07:08:17	06:29:06	07:12:44	00:00:00	09:11:40	05:50:52	08:17:06	09:52:03	10:24:02	13:16:56	00:00:00
";
$f=explode("\t",$a);
$th=$tm=$ts=0;
foreach($f as $ele){
	
	$ht=explode(":",$ele);
	$hours=intval($ht[0]);
	$minutes=intval($ht[1]);
	$seconds=intval($ht[2]);
	$th+=$hours;
	$tm+=$minutes;
	$ts+=$seconds;
}
$mm=intval($ts/60);
$ts=$ts%60;
$tm+=$mm;
$hh=intval($tm/60);
$tm=$tm%60;
$th+=$hh;

echo "$th:$tm:$ts";
?>

How to get all attributes with all available labels/options in Magento2?

I did a lot of research but could not find a solution for that. so gathered some info and created this code: (it is not the best way to do it, but it works – you can use it at least one time for quick results)
the values need to be transformed if you want to see them properly in csv

Here is how to print all available attributes in backend and along with their all available options aka labels

<?php
        use \Magento\Framework\App\Bootstrap;
        error_reporting(E_ALL);
        ini_set("display_errors",1);
        include('./app/bootstrap.php');
        $bootstrap = Bootstrap::create(BP, $_SERVER);
        $objectManager = $bootstrap->getObjectManager();
        //use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
        $collection= $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory')->create();
//$attr_groups = array();
$fta=array();
$ft=array();
        foreach ($collection as $items) {
                        $attr_groups = $items->getData();
                                                if($attr_groups['frontend_input']=="select" or $attr_groups['frontend_input']=="multiselect"){
$eav=$objectManager->get('\Magento\Eav\Model\Config')->getAttribute('catalog_product',$attr_groups['attribute_code'])->getSource()->getAllOptions();
$ft[]=$attr_groups['frontend_label'];
$ft[]=$attr_groups['attribute_code'];
//echo $attr_groups['attribute_code'].'<br>'.$attr_groups['frontend_input'].'<br>'.$attr_groups['frontend_label'].'<br>'.$attr_groups['attribute_id'].'<br>';
foreach($eav as $getlabel) {
        if(is_object($getlabel['label'])){
        $r = new ReflectionObject($getlabel['label']);
$p = $r->getProperty('text');
//echo $p;
$p->setAccessible(true);
        $ft[]= $p->getValue($getlabel['label']);
        }
        else
        $ft[]= $getlabel['label'];
}
$fta[]=$ft;
$ft=array();
}

Extracting names from given list of URLs (using regex)

let us extract name form the URL
https://www.google.com/name?=rajiv
paste the URL in the notepad and press crtl+f , and select ‘regular expressions ‘ from search mode

find in notepad

now, enter the regex in the find tab to fetch names
.*?\?=(\w+)$

Now, the selected name will be fetched form regex as (\1).

it can work on numerous links like:-

https://www.google.com/name?=rajiv/
http://www.example.com/asdas?=borde/id=?
http://www.example.com/asdasd?=bordex
http://www.example.com/name?=bordet
http://www.example.com/asdasd?=border
http://www.example.com/jsciloji?=bordeeeee
http://www.example.com/name?=bordee
http://www.example.com/name?=bordeeeeeee
http://www.example.com/09328e?=bordeeee
http://www.example.com/name?=borde
http://www.example.com/lpaosd?=borde

And only the part after first “?=” will be fetched

[SOLVED] PHP must be run as a CLI application error : Content-type: text/html; charset=UTF-8

php bin/magento cache:clean
Content-type: text/html; charset=UTF-8
bin/magento must be run as a CLI application

as root user, run the following commands (For php v7.0)

# yum install ea-php70
# source /opt/cpanel/ea-php70/enable

The solution involves fixing php variable’s path. We need to find which php is being used right now, you can find out by

$ which php
$ php -v

To fix this PHP cli error, see how to edit php in bash profile (.bashrc)

Installing Magento Common Issues

Following are the steps to complete install Magento error-free:-

  • Uncomment the files which are required by Magento in php.ini and restart the server
  • If installation error occurs, set memory_limit = 786M
  • if still error occurs, uninstall the db and make it again
  • after successfull install, go to (root_directory)app/etc/di.xml and change “Symlink” to “Copy” in developerMaterialization section.
  • go to cmd , root directory and type :- “/bin/magento setup:static-content:deploy
  • refresh the page. done.

PHP Malware – Important regex to bust infected website

grep -rnwl './' -e 'eval'
grep -rnwl './' -e ']};}'
grep -rnwl './' -e '}["'
grep --include=*\.php -rnwl './' -e '${${'
grep -rnwl './' -e '57h'
grep -rnwl './' -e '3o'
grep -rnwl './' -e '__O'
grep -rnwl './' -e '__0'
grep -rnw './' -e '057home'
grep -rlnw './' -e '057home'
find -name "*.ico"
grep --exclude=\*.scss -rnwl './' -e '@include'
grep --exclude=\*.{scss,css,map,js} -rnwl './' -e '@include'
grep -rlnw './' -e '057ho'
grep --exclude=\*.{svg,jpg,png,jpeg} -rlnw './' -e '057'
grep -rlnw './' -e '057h'
grep --include=\*.php -rnwl './' -e '@include'
grep -rlnw './' -e '057hom'
grep -rlnw './' -e '7hom'
grep -rnwl './' -e 'bgeteam'
nano grep -rnwl './' -e 'abcd'
grep -rnwl './' -e 'abcd'
grep -rnwl './' -e '{eval'

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry Magento 2

SELECT u.value_id,u2.value_id, u.attribute_id, u.entity_id, u.value
FROM catalog_product_entity_int u, catalog_product_entity_int u2
WHERE u.entity_id = u2.entity_id AND u.attribute_id = u2.attribute_id AND u.value= u2.value and u.value_id<u2.value_id


DELETE FROM catalog_product_entity_int
WHERE value_id IN (
    SELECT u.value_id as value_id
FROM catalog_product_entity_int u, catalog_product_entity_int u2
WHERE u.entity_id = u2.entity_id AND u.attribute_id = u2.attribute_id AND u.value= u2.value and u.store_id=u2.store_id and u.value_id<u2.value_id
    )

[SOLVED] Magento 2 Error: A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later.

Sometimes debugging on Magento can be annoying, specially if something just arises out of the blue, not while you are actually writing a code.

Magento Error - Technical Problem with server
If Problem Persists, try again later

This is something that occurs on Magento admin panel. As of now, it can be one out of 3 reasons, let us discuss them:

1. Admin Password

Try to change admin password, log out and log in again. This should fix it.

2. Some un compiled code or pending schema change

upgrade, compile, deploy, reindex, clean cache

rm -rf generated/* var/cache/* var/view_preprocessed/*
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean

3. Check for some extra output in the php files


See Line 41
One of the developers left this in index.php and this was just messing with the api calls from admin panel because it was corrupting json output.