PHP

Change WordPress Site URL

If you’ve ever had to transfer a WordPress site between domains, then you know all about the pain of changing the URL. Here’s how to make it quick.

Read more

Solution: Using Include or Require in PHP but Can’t Find File

  • Oct 10, 2011
  • PHP
  • 1

The situation is you are trying to use include or require to load a file from a folder in your site, when the file you are calling include or require from is inside a different folder in the site and NOT the document root. The issue is, when you use include outside of your document root, it considers that folder as the document root, so you are forced to give it the real root directory of your website on the server. Your File: website.com/directory/script.php Your Code in that file: require_once( “/directory2/filename.php”); or include_once( “/directory2/filename.php”); If properly configured, you can use this PHP Server Key/Variable. $_SERVER[“DOCUMENT_ROOT”] So a good Example would be the following: include_once( $_SERVER[“DOCUMENT_ROOT”] . “/directory2/filename.php”); or include_once( $_SERVER[“DOCUMENT_ROOT”] . “/directory2/filename.php”); In the case that directory is the folder just after the root of your site.

Read more

PHP Option Select Menu Generator Function – Dropdown Menu

http://snipplr.com/view/43100/php-option-select-menu-generator-function–dropdown-menu/

Read more

Code Ascetic – SEO Tracking in 4 Lines of Code

I am going to save you all a bunch of headaches and time staring into the sky for the SEO God’s to grant you an effective way to track the conversion from traffic to lead. It is as simple as a few lines of PHP code. I am sure there are equivalents in the other server side scripting languages that someone can kindly post in a reply. Here is the Snippet. if (is_null($_COOKIE[‘referer’])) setcookie(“referer”, $_SERVER[‘HTTP_REFERER’]); if (is_null($_COOKIE[‘entrance’])) setcookie(“entrance”, $_SERVER[‘PHP_SELF’]); What does this do? It checks if there is a current cookie for both the website passed Referer value and if there is a landing page value. If not, it grabs the referer from the last website the person has been too (including organic google search) and the page that they landed on, for instance, index.htm or /affordable-health-insurance/ becomes the value of $_COOKIE[‘entrance’] An easy way to check how your cookies are being set is through this simple PHP Script. You can save a file as test.php and include only the following code: print_r($_COOKIE); This prints the cookies you have set in order. Note: Most Dynamic CMS will already have a bunch of Cookies set that you can take advantage of once you figure out their name value through that smalls cript. The key to web programming is being able to do the most actions with the least amount of code and processing cycles / memory usage. This is similar to being an code ascetic, the more you can go without will bring you to a state of efficiency not many can achieve.  Keep this method for your records! Keep this ideology in your coding! Funny, I reduced this from 6 lines to 4 when i redid this Website and copied content over 😉

Read more