When you see this kinda message, there are a few things that can go wrong, I won't go into detailing all of them. I will be focusing precisely on one, but before I do that, let's quickly check what could go wrong Wrong user role for the user that is signing in Upgrade to latest version of wordpress has gone wrong wp_options table got corrupted Your site is hacked Wrong file level permissions Missing role of an Administrator and gazilion others ... Let's focus on point 6, The missing administrator role This can happen because of various reasons Faulty plugin Human error Corrupt wp_options table So let see what we can do to restore it wp_options table have a column called option_name, execute the follow MySQL statement to see if our wp_user_roles value is present or not [crayon-651e28b355775757137161/] This should return you a row with option_value which should be a long string. If above query doesn't return anything, then check your database backup, restore it locally (not on production server) and see what value this property had If above query returned an option value which did not list "Administrator" in the awkwardly looking JSON string, then also refer to the back and see what value you had to restore it. If your backup is missing, then you can temporarily use the folling query to restore access [crayon-651e28b355779126668668/] Now try to login again, if administrator role was missing, you would've been redirected to /my-account page of your website or the website home page. Couple of other points, Check if your admin user has administrator capabilities, [crayon-651e28b35577b658585271/] I am assuming that your default user have an ID of 1. Check if the value of meta_value property has something like this as a value a:1:{s:13:"administrator";b:1;} If above is not sighted, the do this to have it added [crayon-651e28b35577c663679019/] make sure to replate REPLACE_WITH_META_ID with your meta_id that corresponds to meta_key = 'wp_capabilities' Also make … [Read more...]
Braintree\Exception\SSLCertificate with braintree_php sdk
Ok so I scratched my head around this for a while to figure out why would this happen There are several reasons The request URL was malformed. (This was ok in my case, I've logged each request and didn't see any issues) The request was an older version of SSL (< TLSv1.2). You have to have the version of openssl that supports TLSv1.2. This was also good in my case Braintree Network issues (https://status.braintreepayments.com) (Braintree didn't report any issues) and many more Let's try to dig into some not too obvious things that could happen First thing first, check if you've got the php curl working Follow what's asked here https://github.com/paypal/TLS-update#php-requirements If everything is good, then move on else you have a problem right there. When you install PHP on say CentOS or other linux distro, php-curl module is generally installed from php-common package, however that's not an implementation of curl itself as behind the scenes it makes use of curl/libcurl. Your local curl should be compiled with SSL against version of openssl that supports TLS1.2. There are several articles on how to do this. Just Google it. Check if your SSL certificate is installed properly, this is also very important This is a good guide to make sure that you've followed all the steps DigitalOcean Guide to Install a SSL Certificate Once installed, check if your certificate is installed properly using SSL Labs results, make sure that a DNS CAA and that forward secrecy is setup and working correctly. PHP FPM In my case PHP FPM was an issue, sometimes requests to braintree works and most of the time they failed. From PHP-Cli, requests will always work in my case. I deactivated the PHP FPM altogether after playing with several settings [crayon-651e28b355b95941535974/] replaced it with Apache processing PHP (using mod) [crayon-651e28b355b9e382212028/] It works like charm thereafter. However I am still playing with settings … [Read more...]
PHP check if search engine bot
How do you check if your website is being crawled by a bot or spider, or in case you want to expose a certain section or sections of your website to the search engines which otherwise would be hidden from them as they are protected resources. First of all, you have to know the bots or spiders that exist in horizon You can get the list of search engine bots/spiders and the user agents from the links below http://www.robotstxt.org/db.html https://github.com/monperrus/crawler-user-agents/blob/master/crawler-user-agents.json Now to the main part, how do we detect them Most of the logic can be as simple as distinctly recognizing the User Agent Here is a function that I use most of the time, [crayon-651e28b355ce3792460321/] You can then simply call the above function as [crayon-651e28b355ce5876234139/] This is the simplest way you can answer a question as to how to detect search engine/bots/spiders visits on my site I hope this helps you to detect crawlers with PHP. Best, … [Read more...]
PHP: Check if Start of each word in a sentence is uppercase or any part of a word is UPPERCASE
When working with strings, occasionally we would want to check if any part of a word is uppercase or start of a word is an uppercase letter. This post provide a generic function that can be extended to match your needs. For this post I will use the string below as my reference string [crayon-651e28b355dee204099666/] Now let's define our function that precisely checks a word for an Uppercase regardless of its position [crayon-651e28b355df1482285486/] preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred. [crayon-651e28b355df2395333092/] [crayon-651e28b355df3561009481/] Now let's modify above function just to check if the first character is an Uppercase letter [crayon-651e28b355df4622860424/] Now let's utilise the function we wrote above [crayon-651e28b355df5489306266/] [crayon-651e28b355df6838277611/] I hope that in someway will be helpful to you, If you come across better method, I would like to know that, Regards Jas … [Read more...]
Hunspell with PHP on Windows – Part 1
Ok so I hear you saying, how the hell can I use Hunspell and PHP with Windows, Now the way I am going to show you isn't the only way but is a much simpler way without compiling and using binaries. What is Hunspell? Well I can re-write what's already written, however if you wish to find out, please check the link below https://hunspell.github.io/ Long story cut short, Hunspell is a tool that you can use to validate your text against a given dictionary, get options for correct spellings for a wrongly spelt words. What to do next on Windows 8/10? First thing first you have to get the executables, I've got hunspell-1.3.2-3-w32-bin.zip, download and extract it to say c:\Hunspell so path to bin folder will look like c:\Hunspell\bin This is where you will find hunspell.exe Great so far so good, now let's add our bin folder to our Environment PATH, Setting Environment variable PATH Step 1 Goto Control Panel --> System --> Advanced system settings --> "Advanced" tab --> "Environment Variables" Step 2 Under "System variables" window select "Path" and click "Edit" button Step 3 A window "Edit System Variable" will pop up showing the current value of "Path". At the end of that string add ;c:\Hunspell\bin Step 4 Click Ok buttons to exit current open pop up windows We are pretty much set, now open your command prompt and type [crayon-651e28b355ffe954074082/] You will see something like this [crayon-651e28b356002961288497/] Now try typing baddd and press enter You will see something like this [crayon-651e28b356003344868218/] Above line is just options of matching words to correct the misspelled word. This step validates that our installation works ok. However you may see error something like this [crayon-651e28b356004514132821/] This means that dictionary definitions are missing, how to recover from this situation First thing to do is to use hunspell command with -D … [Read more...]
PHP Start of the day and End of the day for a timezone Util functions
This is a quick post where I am sharing a couple of functions to calculate start of a given day and end of the day for a given timezone Start of the day [crayon-651e28b356246885315203/] End of the day [crayon-651e28b35624b808789364/] [crayon-651e28b35624d050981602/] You can play with these function and can adjust as per your requirement. Let me know if you see any issues with these. I hope that this post will help you out in one way or another, Cheers … [Read more...]
Project Data Sources: re-sync required – Upgrading to PhpStorm 10.0.2
Hey Guys, While I upgraded to PHPStorm 10.0.2 and restarted it, I got this message at the top right corner of this IDE Project Data Sources: re-sync required Unsupported format version 2.2 - (2.4 expected) While that got me puzzled for a while, I thought, because its something to do with data sources, thus possibly there must be some issue there, It turned out to be true, All you have to do is to GoTo View > Tools Window > Database and then hit that refresh (Sync button) Here is how it looks That fixed it for me If you fixed it using some other way, please do share Cheers … [Read more...]
Android Emulator Windows Hosts file editing
Oh! so you want to update a hosts file just like I wanted and spoiled many minutes playing with what works. Let's go through this process to make it work for you as well (hopefully!) Google Android emulator is an amazing tool to test out your apps, Hybrid or Native. There are many cases when we want to use hosts file to point a domain to a machine located in local network. A good place to start reading about what is or is not possible with emulator when it comes down to networking is to read this help page on Android emulator networking. Edit the hosts file in Android emulator Start your Android Virtual Device (AVD): [crayon-651e28b356386943399928/] Emulator is located under "C:\Program Files (x86)\Android\android-sdk\tools" folder, we are adding the partition size so we give enough buffer to write to our hosts file without any error. The error you may get is failed to copy ‘c:\temp\hosts’ to ‘/system/etc/hosts’: Out of memory Second step is to remount the device image by using the command below [crayon-651e28b356389360513296/] adb stands for Android Debug Bridge, to read more on this command please go visit this page, this program can be found in "C:\Program Files (x86)\Android\android-sdk\platform-tools" location of your windows install. Next step is to get the default hosts file and save it on your local hard drive using the command below, I am using the destination location as c:\copied, yours can be anything [crayon-651e28b35638a425754866/] Make the new entries to you hosts file. Important: Now in the example below I am using a white space instead of a TAB delimiter between IP address and hostname. For me, TAB didn't work. But you can try both to see what works for you. Also not that I am appending my entry to the existing file rather than editing it with notepad. [crayon-651e28b35638b563861532/] Let's save the edited file and send it back to the emulator. [crayon-651e28b35638c317631976/] Now you are able to browse your … [Read more...]
PHPStorm Painfully Slow….
Oh Yeah, That went and drove me nuts. I would like to share what worked for me. I am a Windows user so the instructions you see in this post apply to windows user, but stuff shall be quite similar for Mac/Linux users too. First thing first start using Java 64 bit to get some instant performance gain. Set your default environment path for java to point to your 64 bit install. Variables such as JAVA_HOME etc I mean. Second thing is to then start using PHPStorm 64 bit. Where do you find it? Depends where you installed it basically. On my system it is located as shown in the screenshot below Third thing, make sure you are on latest version of PHP storm, WebStorm, IntelliJ whatever, all pretty much based on same core code I would assume. Wait wait... one more thing before you double click that file to launch your IDE is to edit that PHPStorm64.exe.vmoptions this file is found in the same location as your phpstorm exe, What is this stuff? Read more about vmoptions tuning on PHPStorm site, basically all properties in this file are meant to tune your Java Virtual Machine so it handles PHPStorm stuff better. I won't go into much detail on each property and what it means. You can read all that stuff from oracle website. Here is the link http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html But I want to highlight one thing, the settings that made my PHPstorm good enough to work with it again. Here is my snapshot of vmoptions file [crayon-651e28b35652c072210099/] My problem was made worse by font rendering issue that Java has, thus settings -Dawt.useSystemAAFontSettings=lcd -Dawt.java2d.opengl=true ;<-- we are just enabling Java2D OpenGL Hardware Acceleration here so to speed up You can also enable xrender setting to see if that helps, here is my updated vmoptions file. [crayon-651e28b35652e306104599/] You should tune Java heaps and cache settings depending on your project. Higher … [Read more...]
Rackspace Cloud FIles Bulk Delete objects prefixed/* wildcard php sdk
Hi Guys Rackspace cloud files is an awesome file storage system, We upload a file and can make it publicly available through their CDN. While I use Cloud files in pretty much all my projects at work or personal stuff, one thing that I did today was to delete objects with specific prefix e.g. Lets say I have these objects under container "jcorg" hello hello1 hello2 anothervaluableobject and I want to delete all objects whose name starts with hello Here is a code snippet that will be handy for you Language: PHP API link: https://github.com/rackspace/php-opencloud and of course you can use equivalent code in other language SDKs too Code Snippet [crayon-651e28b3567a3025553542/] Let me give you a brief overview to you First we are creating a connection to Rackspace server, depending on which region you are in you will use either RACKSPACE_US or RACKSPACE_UK to authenticate your request. [crayon-651e28b3567a6526405574/] Then we are connection to our object store [crayon-651e28b3567a9255987236/] Then we are getting hold of object list where name or an object starts with "hello" [crayon-651e28b3567aa480319572/] Finally we are iterating on objects found and deleting them. You can check object name here to just to filter them out before you process them for deletion [crayon-651e28b3567ab648478978/] I hope this makes sense, but just in case if you have a question, do leave your comment. … [Read more...]
Recent Comments