Tampilkan postingan dengan label PHP. Tampilkan semua postingan
Tampilkan postingan dengan label PHP. Tampilkan semua postingan

Kamis, 14 Juni 2012




The mail() function  allows us to directly send email from php script.  This function allows sending header information as parameter.

This feature can be used for attaching files with the email sent from mail() function.



The below function mail_attachment can be used for sending email with file attachment.




function mail_attachment($filename, $path, $mailto, $from_mail, $from_name,  $subject, $message) {
    $file = $path.$filename;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$from_mail."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
    if (mail($mailto, $subject, "", $header)) {
        echo "mail send ... OK"; // or use booleans here
    } else {
        echo "mail send ... ERROR!";
    }
}

This function can be called as below.

$my_file = "file1.pdf";
$my_path = $_SERVER['DOCUMENT_ROOT']."/myfiles/";
$my_name = "raj";
$my_mail = "info@domain.com";
$my_subject = "Email Subject ";
$my_message = "Refer the attached file.";
$to_email="to@domain.com";

mail_attachment($my_file, $my_path, $to_email, $my_mail, $my_name, $my_subject, $my_message);


You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Senin, 16 April 2012



We are working on developing a website (InboundLinksChecker.com) useful for the Webmasters to do SEO for their Websites by utilizing many SEO Tools freely. I will give more details about this web site in separate post.

This website includes Inbound links analysis tool. And we used php flush() function for outputting the result immediately after processing each link instead for waiting for completing the entire process.

It was working fine in our local machine. But the flush() function was not working in the server. i-e The page was displayed only after completing the process of all links.

I have tried various options (e.g ob_flush(),ob_end_flush()) to solve this issue. But it was NOT solved.

Finally it was solved by creating a .htaccess file with below content to disable gzip functionality.

SetEnv no-gzip dont-vary



You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Kamis, 12 April 2012




Today I have requested a dedicated IP address for our websites from our hosting. Then I wanted to check whether the IP address got changed. I tried below statement.

 echo $_SERVER['SERVER_ADDR'];

And, it was showing the new ip address. But below statement is still showing the old ip address.

echo file_get_contents("whatismyip.com")

I tried with various other sites such as whatismyipaddress.com also. But everything is showing the old ip address only

So, I would like to know whether $_SERVER['SERVER_ADDR'] is the correct way of knowing the IP address of the server, or any other suitable way available?

I asked this question in LinkedIn and this below answer look appropriate.

In your case, indeed the correct method would be:
echo $_SERVER[SERVER_ADDR];

as this would echo the IP address of the server under which the current script is executing.

On the other hand;
echo file_get_contents("whatismyip.com")

will output the source of the homepage of a website. This IP address might differ from what you get from the previous method as this is what the out side world sees. Meaning if the website is co-hosted or virtualized then the latter will give you the edge IP address of the hosted infrastructure.

And, I found below function for finding actual IP address. I decided to find the IP address of the SERVER by requesting a page which displays IP address by calling below function. (The server will be the client for this request). But this approach also showing the new ip address. I am still wondering what will the code used in whatismyip.com for finding the actual IP of the host (device) instead of showing just the virualized ip.

function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Senin, 27 Februari 2012

We used a Session variable for getting the Wordpress logged in user id from an external php file.
But it didn't work once after upgrading the wordpress. Obviously the session variable setting page was overwritten by new wordpress update.

So, I have decided to use the wordpress object to get the userid instead of session variable so that any future wordpress update won't affect our code.

I used below piece of code in the external php file, and it was working fine.

require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
require_once('../wp-includes/pluggable.php');
global $current_user;
get_currentuserinfo();

$userid= $current_user->ID;

You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Sabtu, 18 Februari 2012

 Social Media can be used effectively to get website traffic freely. Especially the micro-blogging service Twitter helps to get good number of visitors to our websites.


Past few years I am trying various approaches to get traffic to our websites from Twitter. We developed various scripts to make use of Twitter, and experimenting them internally. Some of them were NOT helpful and some of them helped to get significant traffic. For example, our HotTrends tweets didn't help as the twitter negatively affect the usage of hottrends. But our Auto Tweets and Quotes Tweets are helpful. Especially our Motivational Quotes Site http://TheQuotes.net/ uses our twitter application to grow fast within few months.

Apart from our internal use, I thought of selling the script (source code) to the people who want to buy it so that they can enhance it according to their own needs. So, started this sales page long back.
But I haven't promoted it. Now I have decided to start the sales immediately.
So, I have decided to give 50% Discount for first  few sales. I set the Normal price as $130 USD.

 The first two buyers can get it just for $65 USD.


You can get the details about the scripts at http://qualitypointtech.net/products/twitter/index.php 

 I already posted a message about this Offer in Digital point Forum. So, you need to buy it soon if you want to use this Offer.

These Twitter Tools scripts help to manage multiple Twitter accounts easily to bring targeted Traffic to any website.
Switching between multiple accounts is very easy, and even you need NOT switch between accounts for sending same tweet to multiple accounts using "MultiPost".
It is having most of the features (timeline, @mention, retweet, Quoted retweet, DM) of Twitter in addition to providing AutoTweet and Multipost features.
And, bulk loading options are available to load lot of tweets and many Twitter accounts easily from csv files.

And, importantly these Scripts will help you send your Tweets with your own Source. For example, In this tweet you can see "TheQuotes" as Source. On clicking TheQuotes our site TheQuotes.Net will open. Similarly the buyer of the script can have his own source.

And, we can do any custom changes at affordable price.Contact me (rajamanickam.a@gmail.com) if you are interested in utilizing this Offer.

You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Sabtu, 11 Februari 2012

Recently I came to know that there were small issues in our Keyword Position Finding Script.

It showed error message when pressing Enter key instead of clicking the submit button after specifying keywords and URL .

This error occurred as  the Form is having more than one submit button (one more uploading csv file, one for submitting the keyword details).
I solved the issue by disabling the pressing of Enter key by adding below piece of code.

function checkEnter(e){
 e = e || event;
 return (e.keyCode || event.which || event.charCode || 0) !== 13;
}
I called this function as "onkeypress="return checkEnter(event)"" from onkeypress event of the Input text box which is used to get URL.

And, I had to add curl_setopt($ch,CURLOPT_HTTPHEADER,array ("Accept: text/plain")); in the cURL function for emulating the Javascript disabling activity.

Right now, our Keyword Rank checking Tool is added with many features. But still I am keeping the same price. If you are interested, you can buy this script from here.

You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Senin, 09 Januari 2012



Recently I had worked on developing a Script for getting data from external websites using php cURL.

It took more Time and Effort for executing the script, as the script execution was stopped intermittently many time due to unknown issue.

i-e I had to rerun the script multiple times to collect the data from the third-party site.

I couldn't find the reason why the script execution was stopped. Anyway, I found a work around to handle this issue.
I updated the php script to store the extracted data in a mysql table with status column. i-e once data for particular item is extracted fully, the corresponding row in the  mysql table will me marked as "completed". And, updated the php script to process only the rows which are NOT having status as "completed".

This workaround saved lot of time and effort. Anyway, I am still looking for the root cause of this issue.  I already set huge value as script time out period using "set_time_limit()" function.



You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.

Selasa, 15 November 2011



Few years back, we had set-up a phpBB based Forum for allowing the users to discuss about various things including software testing and web development.

And, our Team is spending time and effort to update knowledge base section of this Forum. We use this Forum as Support Forum for our products.

Large number of users are joining this Forum, as this Forum members can freely access lot of our applications such as Quiz, Twitter Tools, SEO Tools, social bookmarking, etc.

While writing this post, this Forum is having 4,890 Members. Note that almost all these members will be real active users. Because We had taken lot of steps to prevent spam users. And, our own batch script will delete the spammers periodically. Let me know if you still find any spammers in our Forum.

So, the Forum is having lot of benefits and lot of members too. But active discussion in this Forum is low even it is having lot of active members.

After doing some investigation, we were able to find the reason for this low active discussion. The Forum is NOT informing the users about any new reply added to their question. So, the people are NOT willing to use this Forum for asking any further questions without knowing the fact that their questions are getting answered.

This Forum is having "subscribe" option for allowing the users to get notified whenever they get any reply. But it seems most of the people are not knowing this feature. By default it is turned off.

So, I wanted to turn on it by default. I searched the ACP to find any setting for making this change. But I couldn't find any setting for turning it on by default.

After doing some Google search, I did it with below two steps.

1. For setting default "subscribe" option for the New users.

Open \includes\functions_user.php and replace 'user_notify'=> 0, with 'user_notify'=> 1,

2. For setting default "subscribe" option for the Existing users.

Run the following SQL query:

UPDATE phpbb_users
SET user_notify = 1
WHERE user_type <> 2;
Remember to purge the Cache  using ACP if you want to see this change immediately.

I plan to focus more on improving the quality of our Forum further so that the huge user base can utilize our Forum effectively.

You can subscribe to our Email posts, and you can bookmark this blog for further reading, or you can subscribe to our blog feed.