Tuesday, December 25, 2012

How to remove unnessesary blank lines in your code

In Dreamviewer
  1. Open the file
  2. Click CTRL + F
  3. Select "Current document" in "Find in" (You can also select the folder if you have multiple files)
  4. Search in "Source code"
  5. Tick "Use regular expression"
  6. Type "[\r\n]{2,}" (without quotes) in "Find"
  7. Type "\n" (without quotes) in "Replace"
  8. Press "Replace All"

Friday, November 30, 2012

50 Extremely Useful PHP Tools

 50 Extremely Useful PHP Tools posted at Smashing Magazine

By Jacob Gube
PHP is one of the most widely used open-source server-side scripting languages that exist today. With over 20 million indexed domains using PHP, including major websites like Facebook, Digg and WordPress, there are good reasons why many Web developers prefer it to other server-side scripting languages, such as Python and Ruby.
PHP is faster (updated), and it is the most used scripting language in practice; it has detailed documentation, a huge community, numerous ready-to-use scripts and well-supported frameworks; and most importantly, it’s much easier to get started with PHP than with other scripting languages (Python, for example). That’s why it makes perfect sense to provide the huge community of PHP developers with an overview of useful tools and resources that can make their development process easier and more effective.
This post presents 50 useful PHP tools that can significantly improve your programming workflow. Among other things, you’ll find a plethora of libraries and classes that aid in debugging, testing, profiling and code-authoring in PHP.

Details of Jomres ( joomla hotel reservation component )

If you want to view or custermise booking data, you can edit jomeres/core-minicomponents/j03020insertbooking.class.php file.

Tuesday, November 20, 2012

Authenticating Customer Outside Magento

<?php
/**
* Magento validation starts here
*/
require_once (dirname(dirname(realpath(__FILE__))).'/app/Mage.php');
umask(0);
Mage::app();
//Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session');
try{
$session->login($_REQUEST['login']['username'],$_REQUEST['login']['password']);
$session->setCustomerAsLoggedIn($session->getCustomer());
//Load the customer modules
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
//Get customer attribbutes
$customer->loadByEmail($_REQUEST['login']['username']);
/**
* Do the stuff you need to when user authenticates
*/
}catch (Exception $e){
$key ="authenticate=N";
}

Friday, November 9, 2012

How to access Magento user's session from outside Magento?

<?php
require_once dirname(__FILE__).'/app/Mage.php';
umask(0) ;
$_SESSION['wz']['customer_id']    =    null;
Mage::app();

// Checking for customer session
Mage::getSingleton('core/session', array('name'=>'frontend') );
$session=Mage::getSingleton('customer/session', array('name'=>'frontend') );

$customer_data = Mage::getModel('customer/customer');

if ($session->isLoggedIn()) {
    //echo "Customer is logged in";
    $_SESSION['wz']['customer_id'] = $session->getId();
} else {
    //echo "Customer is NOT logged in ";
    unset($_SESSION['wz']);
    header("Location: error.php?mode=unk_user");
}

Unable to login into the Magento backend


When you migrate your Magento website from location to another, or you change the domain-name under which it is running, you might run into the problem that you can't login anymore to the Magento Admin Panel. Here are various solutions to this problem.

Localhost

One reason why the Magento login fails, might be that you're accessing the Magento website through the hostnamelocalhost. Magento checks whether the hostname is a real domainname, and if it isn't, it fails to create the right cookies.
The only workaround is to fool Magento into thinking a real domainname is used. Under Linux or MacOS you could try using localhost.localdomain, but under Windows you will need to modify your hosts-file for this. Easier is just to use the IP-address 127.0.0.1 to access Magento.
If you are using a remote webserver, it's unlikely that this problem occurs.

Cookie domain

Another reason why you fail to login, could be some setting within the Magento configuration. To alter this, you will need to open up the MySQL database - for instance by using phpMyAdmin. Navigate within your Magento database to the MySQL table core_config_data and look for a row with the field path set to the value web/cookie/cookie_domain. There might be multiple entries, but the one with the scope_id set to 0 should be matching the domainname you're using to access Magento.
If the database table core_config_data doesn't contain any row with path set to web/cookie/cookie_domain, don't add it because you don't need it. If you find multiple entries, be careful with what to change because you might break your Magento site completely.
If you use a database table prefix, the table core_config_data might actually be uii44_core_config_data or something alike. This makes it harder for hacker to attack your Magento site (SQL injection attacks).

Secure or unsecure URLs

Another problem could be that the so-called Secure URLs and/or Unsecure URLs do not match the current hostname. In this circumstance, Magento tries to redirect to the original hostname anyway. So watch the hostname in the browsers addressbar closely.
In the same MySQL table core_config_data you might find various entries with path starting with web/secure/base orweb/unsecure/base. These also need to point to the right hostname. Note that the number of occurances could range from 0 (nothing configured) to 10 (everything configured).

Deleting and reconfiguring

Instead of trying to set the values above correctly, which could be a lot of work, you can also delete these entries and have a fresh start. You can use the following SQL-queries for this:
DELETE * FROM `core_config_data` WHERE `path` = "web/cookie/cookie_domain"
DELETE * FROM `core_config_data` WHERE `path` LIKE "web/secure/base%"
DELETE * FROM `core_config_data` WHERE `path` LIKE "web/unsecure/base%"

Check your file permissions

It's also worth taking a look at the permissions of your hosting environment. The folder var/cache within your Magento installation needs to be writable to the webserver, so new session-files can be created. If the folder is not writable, nobody is able to login.

Save sessions in the database

Instead of fixing the file permissions, you can also store the sessions in the database instead. You can accomplish this by editing the file app/etc/local.xml. Make sure you have a good backup of this file, and follow the exact syntax as below.
Locate the line starting with <session_save> and change the word files into db. So the following:
<session_save><![CDATA[files]]></session_save>
should become:
<session_save><![CDATA[db]]></session_save>
Save the file and sessions will be saved in the database instead. Please note that this change could have consequences regarding performance as well.

Friday, July 20, 2012

Change Your Table Prefix in WordPress


If your table prefix is “wp_” or “wp1_” or even “wordpress_”, then changing it will bring your WordPress site security to a higher level.
By default Fantastico installation sets “wp_” as a prefix for each WordPress table name. Since this is a known vulnerability, malicious users can exploit your data easily.
They specifically look for the wp_options table, because it will alter your WordPress site look. Through wp_options they can set the url to redirect to their sites, leaving you the impression that your site was defaced.
If you already have a WordPress site, take a look at either your config.php file or go to phpMyAdmin in cPanel to check your tables names.
// Entry in config.php showing wordpress table prefix used in the installation
$table_prefix = ‘wp_’; // Only numbers, letters, and underscores please!
Attackers can easily send malicious code using JavaScript injecting SQL targeting your wp_ based tables. To make your wordpress site really secure, change the prefix to something that is difficult to guess. I would pick something almost like a password, except you are limited here to only numbers, letters, and/or underscores.
You might want to check a plugin “wp prefix changer” written by Philipp Heinze for BlogSecurity.net. It should do the job for you. However, I had problems using it, and prefer the manual way which I already done for 2 blogs.
I strongly recommend you to do change the prefix, if it is plain wp_. Just follow the next 6 steps and you should be in good shape. I have tested these steps already with a WordPress 2.8 installation:
1- Take a backup
Since this is a change in your WordPress table structure, you will have to take a backup first.
In cPanel click on the “Backups” icon and click on “Generate/Download a full Backup” and proceed with a “Home Directory Backup”.
2- Edit your wp-config.php file and change
$table_prefix = ‘wp_’;
to something like
$table_prefix = ‘op2mro445_’;
3- Change all your your WordPress table names
Go to phpMyAdmin and choose your WordPress database. Click on sql menu item and enter the command to rename all your tables. Do it one table at a time.
Note: You might have more tables that start with “wp_” prefix, change all the tables.
Every time you paste one line into the SQL window, click on GO and see the table name change on your left. Keep changing the table names until all your wordpress tables have the new prefix.
Rename table wp_commentmeta to op2mro445_commentmeta;
Rename table wp_comments to op2mro445_comments;
Rename table wp_links to op2mro445_links;
Rename table wp_options to op2mro445_options;
Rename table wp_postmeta to op2mro445_postmeta;
Rename table wp_posts to op2mro445_posts;
Rename table wp_terms to op2mro445_terms;
Rename table wp_term_relationships to op2mro445_term_relationships;
Rename table wp_term_taxonomy to op2mro445_term_taxonomy;
Rename table wp_usermeta to op2mro445_usermeta;
Rename table wp_users to op2mro445_users;
4- Edit wp_options
Then you need to edit in the op2mro445_options table ( formaly wp_options ) table
Click on the table name link and then click on “Browse” menu item.
You will see all the data stored in that table. Look under the option_name column header and change wp_user_roles to op2mro445_user_roles.
You will be able to change it by clicking on the edit button for that record.
Note: wp_user_roles might not appear on the 1st page under options. Keep looking for it, otherwise you will not be able to login afterwards.
5- Edit wp_usermeta
And finally apply changes to op2mro445_usermeta formally ( wp_usermeta). Don’t miss any records.
In phpMyAdmin highlight op2mro445_usermeta link and click browse menu.
Change every value under meta_key column header, that starts with the old prefix wp_ to the new prefix op2mro445_ the number or records might be different for your web site.
I have changed the following in my installation:
wp_capabilities to op2mro445_capabilities
wp_autosave_draft_ids to op2mro445_autosave_draft_ids
wp_user_level  to op2mro445_user_level
wp_usersettings to op2mro445_usersettings
You can run a query in phpMyAdmin to find out how many records you need to change:
Simply click on the search link, add the following search condition (meta_key like ‘wp_%’ ), and click the GO button. (see image) This will get you the exact number of record you need to update. (Jessi, thanks for the tip)
table_prefix_search
6- Done! Test your WordPress site now
It should be a lot more secure giving you the peace of mind to focus on blogging.
Oh, one more thing. Do another backup.
If I can be of any help, just let me know.
Popularity: 100% [?]

Thursday, June 21, 2012

How To Move WordPress To A New Server Or Host

I have seen many requests online on how to move aWordPress blog to a new server or host- including requests from some of my readers.
It seems as though the easy part is transferring the files. What most people find difficulty with is moving their WordPress database to the new server or hosting company.
While there are other tutorials available online, many seem to lack clear instructions on how to move your blog. In this tutorial, I’m going to take you step-by-step and show you exactly how to move your WordPress blog to a new server or host.
It may look difficult at first with all the steps I’ve included, but I assure you- it’s easier than it looks- especially after you move a blog a few times. It may seem like there are many steps to moving your WordPress blog to a new server, but there really aren’t that many. I’ve just broken each step down to make it very clear even to beginners exactly how to move their WordPress blog.
So, are you ready? Here we go:
Open either your FTP program or your file manager through your hosting company and browse to yourhome or public_html directory. With WordPress installed, it should look something like this:
How To Move A WordPress Blog To A New Server Or Host
You want to download all the files and folders to a convenient location on your computer, then upload all the files and folders to your new server/host.
Once you have all the files on your new server/host, you need to download a copy of your original WordPress database from your original host.
(All of the following screenshots were taken from cPanel, but if your host uses a different administration panel, the steps will be the same- they may just look slightly different.)
Once logged in to your administration panel, go to phpMyAdmin.
How To Move A WordPress Blog To A New Server Or Host
Once you click phpMyAdmin, in the left column click on the database that is used for your original WordPress blog.
How To Move A WordPress Blog To A New Server Or Host
You should now see the name of the WordPress database in the drop-down box and all the WordPress tables listed underneath. The tables you have can be different than mine because the WordPress plug-ins you use will determine what tables you have in your blog’s database.
Regardless, it should look something like this:
How To Move A WordPress Blog To A New Server Or Host
Now in the main window, click the tab at the top of the screen that says “Export”. In the “Export” box, all of your WordPress database tables should be highlighted.
How To Move A WordPress Blog To A New Server Or Host
Underneath that, check the box that says “Save as file” and name it whatever you want, then click “Go” to download your blog’s database.
How To Move A WordPress Blog To A New Server Or Host
Click the “Save” button to save a copy of your WordPress database to a convenient location on your computer.
How To Move A WordPress Blog To A New Server Or Host
Congratulations! Now you’re done with your old server/host! It’s time to move on to the new server/host.
Login to your new server/host’s control panel. The first step is to create a new database that will be used for your new WordPress Blog.
Click on “MySQL Databases”.
How To Move A WordPress Blog To A New Server Or Host
Under “Create New Database”, enter a name for your new WordPress database, then click the “Create Database” button.
How To Move A WordPress Blog To A New Server Or Host
Now that your new WordPress database has been created, we need to make a new user for that database. Usually on the same screen you’re at, you have the option to create a new user.
Enter a name and password for the WordPress database user and click the “Create User” button.
How To Move A WordPress Blog To A New Server Or Host
Now you have to give that user permission to use your blog’s database. Again, usually on the same screen you will have the option to add that user to the database. Select your WordPress database and the user you just created, then click the “Add” button.
How To Move A WordPress Blog To A New Server Or Host
On the next screen, you have the option to grant which permissions this user has to your blog’s database. Be sure to grant this user total access to the WordPress database by checking “All Privileges”, then click the “Make Changes” button.
How To Move A WordPress Blog To A New Server Or Host
You should get a confirmation telling you that the user has been successfully added to the database.
How To Move A WordPress Blog To A New Server Or Host
Now that your new database has been created, we need to import your old WordPress blog’s database contents into your new database.
Back in the main window of your control panel, click on “phpMyAdmin”.
How To Move A WordPress Blog To A New Server Or Host
In the drop-down box in the left column, select your new WordPress database that you’ve just created. It should say that there are no tables in the database yet, since it’s a blank database that you’ve just created.
How To Move A WordPress Blog To A New Server Or Host
In the main window, click the “Import” tab. Under “File To Import”, click the “Browse” button and select the .sql file that you downloaded from your old WordPress database, then click the “Go” button.
How To Move A WordPress Blog To A New Server Or Host
After waiting for the entire blog’s database to import, you should get a confirmation telling you that the tables have been successfully imported. Again, the number of queries that were executed may be different than mine, depending on which plug-ins you have installed.
How To Move A WordPress Blog To A New Server Or Host
Now in the left column, you should be able to see all the WordPress tables that were just imported.
If your new WordPress blog is using a different domain name than the original, we need to modify three values, and they are all located in the “options” table.
Even if you are using the same domain name, there is one option you may have to change. I would recommend you continue to follow along, even if your new WordPress blog is using the same domain name as the original blog.
All of the changes we need to make are located in the options table. My options table is named “wp1_options”, but yours may be a little different (probably “wp_options”), just as long as the suffix is “options”.
How To Move A WordPress Blog To A New Server Or Host
After you click on the options table, click the “Browse” tab at the top of the page.
How To Move A WordPress Blog To A New Server Or Host
One of the option names will be “siteurl”. You will see that your original domain name is listed. If your new WordPress blog is on a new domain name, you need to edit that value to your new domain name.
You can do so by clicking the “Edit” button, which looks like a pencil.
How To Move A WordPress Blog To A New Server Or Host
Once you click the “Edit” button, just enter your new blog’s URL and then click the “Go” button to save the changes.
How To Move A WordPress Blog To A New Server Or Host
The next two values we need to change are usually located on page 2 of the options. At the top and bottom of the main window, you should see the heading “Page number” with a drop-down box. Select page 2.
How To Move A WordPress Blog To A New Server Or Host
Scroll down until you see the “home” option. Again, you will see your old WordPress blog’s URL. Click the “Edit” button which looks like a pencil to modify the old blog’s URL.
How To Move A WordPress Blog To A New Server Or Host
After you click the “Edit” button, enter your new WordPress blog’s URL, then click the “Go” button to save the changes.
How To Move A WordPress Blog To A New Server Or Host
The third and final value we need to change is the upload path. This is the location where WordPress will upload all of your images.
Scroll down until you see the “upload_path” option, and again click the “Edit” button that looks like a pencil to modify this value.
How To Move A WordPress Blog To A New Server Or Host
Now you need to enter your new upload path. The only part of your new upload path that you need to modify is the username that your hosting company gave you for your domain name.
This is usually just after “/home/”, and in my case is “jrivnet”. Replace this with your new username. This is usually the username you use to login to cPanel, or your domain’s control panel.
How To Move A WordPress Blog To A New Server Or Host
If you are still unsure as to what it is, take a look in the left column. Your username is the prefix of your WordPress database. Notice how mine is “jrivnet”.
How To Move A WordPress Blog To A New Server Or Host
Once you’re done with that, click the “Go” button to save.
WHEW! You’re finally done with all the database stuff! Your final step is to go to your wp-config.php file of your new WordPress blog. This is in the root folder of your WordPress blog (usually /home/ or /public_html/). You can do this with your FTP program or the file manager for your new WordPress blog through your hosting company.
Find the file “wp-config.php” and click “Edit”.
How To Move A WordPress Blog To A New Server Or Host
Once the “wp-config.php” file is opened, the first things you will see are:
DB_NAME, DB_USER, and DB_PASSWORD.
Enter your new WordPress blog’s database name, username and password between the ‘ ‘. Look at the 13th image in this article above just below where I said “You should get a confirmation telling you that the user has been successfully added to the database”. That was my new WordPress database and username that I created. The 10th image in this article is where I created the user’s password.
This IS NOT your WordPress admin username and password! This is your database’s name and password which you just created for your new host/server.
How To Move A WordPress Blog To A New Server Or Host
Once you enter the new information, save the updated “wp-config.php” file.
You’re done!
You can now go to your new WordPress blog’s URL admin login (i.e. example.com/wp-admin) and login using the same username and password you were using on your original WordPress blog.
How To Move A WordPress Blog To A New Server Or Host
That’s about as simple as I can explain the process of moving your WordPress blog to a new server or host. If you have any problems, feel free to post your comment below and we can all do our best to help you along.