29 Oct 2014

What is short open tag in php

<?= is not equal with <?php.

<?= is the short open tag for <?php echo

<? is the short open Tag for <?php

You can use short open tags by activate short_open_tag in the php.ini.


How to Enable "short open Tag":


Method 01
Go to php.ini and set short_open_tag = On

and then finally restart your server


Method 02

You should be able to change it in your .htaccess file if it wasn't locked down

<IfModule mod_php5.c>
   php_value short_open_tag 1
 </IfModule>

25 Oct 2014

How to change PrestaShop admin Password using Database

Step :01
Go to the PrestaShop root folder and find the config folder. This will take you to a list of all files within that folder.select-config-folder

Step :02

Look for the settings.inc.php file.

Step :03
Once inside the settings.inc.php file, locate the setting named _COOKIE_KEY and copy the string value. You may want to save it temporarily to a word processing document such as notepad.

Step :04
Go to the database and select the one named ps_employee.
Note that your PrestaShop database prefix might not begin with ps_

Step :05

This opens the table data information. Find your admin user from the list of data rows.

Step :06
Find the password row, it is named passwd. There are two columns you will need to edit. The first is the Function column. Use the dropdown and select the MD5 option. The second column is the Value column. For this column, paste the _COOKIE_KEY value you saved earlier and attach your new password directly to the end of the key with no spaces. Be sure to use a real password and not anything easy like NEWPASS1234 that we used in the example.


Step :07

Then click the GO button to save the new information.

Now login the admin panel.

How To Install WordPress Plugin Without Using FTP

You are not able to update/upgrade your WordPress and plugins to a newer version without providing your FTP connection information. This is a common issue whereby the WordPress system can’t write to your /wp-content folder directly.

To solve this issue you need to define the FTP details in your wp-config.php file so WordPress will remember it. Alternatively, you may also provide WordPress with write access to your /wp-content folder by accessing the FTP root file and changing the folder file permission (CHMOD) to 775 rather than the default 755 and 644.

There is however an easier way to deal with this; by defining constant, FS_METHOD in your wp-config.php file. This bypasses WordPress’s recurring prompts, and allows auto-updates of your files to happen. And it takes only 1 line of code to do this.

Step 1. Open /Wp-Config.Php

Now the first thing you need to do is to open the wp-config.php file from your WordPress root folder (you may access this file from your WordPress installer folder). From the installation folder, the file is located at wordpress/wp-config.php

Step 2. Insert FS_METHOD

Paste the following code to your wp-config.php file, preferably just below every other line of code.

define('FS_METHOD','direct');

Step 3. Save And Upload

When you have already pasted the one-line code, you can proceed to upload the file to your WordPress root folder on your server, and it should work right away. Uploading can be done directly from your host control panel.

24 Oct 2014

How to check php version in website

Creating a PHP info page in Website


Using the steps below I'll show you how to create a PHP info page that will allow you to not only see your PHP version, but also all the PHP options that are currently in use.

Step :01

Login to your cPanel.

Step :02
Under the Files section, click on File Manager, then select Web Root and click on Go.

Step :03
At the top-left, click on + New File, name the file info.php and click on Create New File.

Step :04
Now open the file with the Code Editor in cPanel and enter in the following code:
<?php
phpinfo();
?>

Then click on Save Changes at the top-right hand corner of the screen.

Step :05
Now if you visit your website such as http://example.com/info.php you should see the PHP info page. This example screen shot shows that this server is running PHP version 5.2.17, and that the PHP configurations are getting loaded from the file /home/userna5/public_html/php.ini


php info page

Step :06
You can scroll further down the PHP info page, to also see individual PHP options that you can set.

16 Oct 2014

Excerpt or Content Word Limit in WordPress

This is just a revamp of a function I wrote a while back to add the ability to limit the number of words displayed when you call the excerpt or content. As it stands, the max number of words for the excerpt is 55.

Add the following code to your functions.php file.

function excerpt($limit) {
  $excerpt = explode(' ', get_the_excerpt(), $limit);
  if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt).'...';
  } else {
    $excerpt = implode(" ",$excerpt);
  }
  $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  return $excerpt;
}

function content($limit) {
  $content = explode(' ', get_the_content(), $limit);
  if (count($content)>=$limit) {
    array_pop($content);
    $content = implode(" ",$content).'...';
  } else {
    $content = implode(" ",$content);
  }
  $content = preg_replace('/\[.+\]/','', $content);
  $content = apply_filters('the_content', $content);
  $content = str_replace(']]>', ']]&gt;', $content);
  return $content;
}


Now, instead of using the_content() or the_excerpt in your loop, use excerpt($limit) or content($limit).

If you want to limit your excerpt to 25 words the code would look like this:

Use this PHP code:
<?php echo excerpt(25); ?>

14 Oct 2014

Sending Simple HTML Email with PHP

It's Not Much Different Than Text Email

Sending HTML Email through PHP uses the exact same mail function as text email:

Code 01:
mail($to, $subject, $message, $headers);

The last parameter, the headers, are optional for the function but required for sending HTML email, as this is where we are able to pass along the Content-Type declaration telling email clients to parse the email as HTML.

In fact, the headers area gives us the opportunity to do lots of important email functions. This is where we can set the From: and Reply To: settings if need be, as well as CC and BCC other recipients (Hey, a checkbox for CC'ing yourself would be a cool feature to add!). Here is the code used for the new and improved HTML-Sendin' Website Change Request Form:

Code 02:
$to = 'bob@example.com';

$subject = 'Website Change Request';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


Now We Can Use HTML Tags

The message parameter (a big string we pass to the mail function with the body of our email), can now have HTML tags in it. For example:


Code 03:
$message = '<html><body>';
$message .= '<img src="samx/header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
$addURLS = $_POST['addURLS'];
if (($addURLS) != '') {
    $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
}
$curText = htmlentities($_POST['curText']);          
if (($curText) != '') {
    $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";


More Details: http://css-tricks.com/sending-nice-html-email-with-php


13 Oct 2014

Creating a basic Joomla! template

Setting up a directory structure


To make the most basic template, create a new folder in the templates folder. Name this folder after your template i.e. mynewtemplate.

Using your favourite text editor create the files index.php and templateDetails.xml. To keep things organized, make 2 new folders called images and css. Inside the css folder create a file called template.css.

Although it is fine to place all your CSS code directly in your index.php file to start, many web developers prefer to place their CSS code in a separate file that can be linked from multiple pages using the link tag. This may also shorten the loading time of your pages, since the separate file can be cached.

This is the most basic practical setup. Outline of folder and file structure:

>mynewtemplate/
>>css/
>>>template.css
>images/
>index.php
>templateDetails.xml

Step: 01

For Joomla 2.5 and later, use the following version. Change version="2.5" into the version of your Joomla! installation.


<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="template">
        <name>mynewtemplate</name>
        <creationDate>2008-05-01</creationDate>
        <author>John Doe</author>
        <authorEmail>john@example.com</authorEmail>
        <authorUrl>http://www.example.com</authorUrl>
        <copyright>John Doe 2008</copyright>
        <license>GNU/GPL</license>
        <version>1.0.2</version>
        <description>My New Template</description>
        <files>
                <filename>index.php</filename>
                <filename>templateDetails.xml</filename>
                <folder>images</folder>
                <folder>css</folder>
        </files>
        <positions>
                <position>breadcrumb</position>
                <position>left</position>
                <position>right</position>
                <position>top</position>
                <position>user1</position>
                <position>user2</position>
                <position>user3</position>
                <position>user4</position>
                <position>footer</position>
        </positions>
</extension>

Step: 02

Creating a basic index.php file

Begin

A Joomla template begins with the following lines:

<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
   xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
The first line stops naughty people looking at your coding and getting up to bad things.

The second line is the Document Type Declaration (DOCTYPE), which tells the browser (and web crawlers) which flavor of HTML the page is using. The doctype used above is HTML5, a newer version of HTML that is largely backwards compatible, but contains many new features. You should be aware that this will not work well in Internet Explorer 8 or earlier without a hack. You might want to investigate this situation and your clients' wishes before deciding on which doctype you want to use. However this is used in Joomla Joomla 3.0 and higher.

The third line begins our HTML document and describes what language the website is in. A html document is divided into two parts, head and body. The head will contain the information about the document and the body will contain the website code which controls the layout.

Head

<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/template.css" type="text/css" />
</head>
The first line gets Joomla to put the correct header information in. This includes the page title, meta information as well as system JavaScript. The rest creates links to two system style sheets and to your own style sheet (if it's named template.css and is located in the css folder of your template directory. So if your temlate is in http://www.mysite.com/templates/my_template/ then the css files will go in http://www.mysite.com/templates/my_template/css/).

Body Section

<body>
<jdoc:include type="modules" name="top" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="bottom" />
</body>
Amazingly, this will suffice! Yes, it's a very basic layout, but it will do the job. Everything else will be done by Joomla!. These lines, usually called jdoc statements, tell Joomla to include output from certain parts of the Joomla system. Note: you will need to ensure your menu is set to go into the "top" module position.

Module Positions

Above, the line which says name="top" adds a module position called top and allows Joomla to place modules into this section of the template. The type="component" line contains all articles and main content (actually, the component) and is very important. It goes in the centre of the template.

Note: You can add your own module lines anywhere you want in the body, but you have to add a corresponding line to the templateDetails.xml file which sits alongside the index.php of your template.

End

Finish it off - one last bit:

</html>

Custom Images

If you want to add any images to the template you can do so like this:

<img src="<?php echo $this->baseurl; ?>/images/stories/myimage.png" alt="Custom image" class="customImage" />
Here the baseurl variable will fill in the path to your template for you.

Custom CSS

You can add custom css like this:

<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/css/styles.css" type="text/css" />
Every file which is added must have a line in the templateDetails.xml file for the template.

This leaves a final file of:

<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
<!DOCTYPE html>
<html xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/mynewtemplate/css/template.css" type="text/css" />
</head>
<body>
<jdoc:include type="modules" name="top" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="bottom" />
</body>
</html>

More Details: http://docs.joomla.org/Creating_a_basic_Joomla!_template