<?php
ob_start();
//Your code
header('Location: example.php');
exit()
//your code
ob_flush();
?>
Tuesday, July 17, 2012
Cannot modify header information - headers already sent.
Friday, June 1, 2012
Reset Your forgotten windows password in easy steps
If you forget windows password, its not easy to reset it. if you dont know the propper tool which can do this. Most of the peoples are using ERD Disk for this. Its working fine upto windows xp, But when they came across windows vista/7 it wont work. So here most of the blogs will suggest to work with sam file (SAM is the file that contains your Windows registry). Its present in directory "WINDOWS/system32/config/". Using linux command chntpw on an Linux live disk we can change the settings. like this,
sudo chntpw –u <username> SAM
Some other similar kind of bootable stuff's are also available for the same. But in-case if you don't have any one of these stuff or you are not getting it working for you, Now if you can access the windows file system. Then you can still change it. Just applying a simple trick and its all done.
What we have to do is we have to found the window functions which can execute on login screen. lucklly we have a sticky key function, i.e. hitting shift key for 5 times and a popup will come. We know password for any user can be change from command line also.So I think you got me. Exactly we are going to interchange these functions. All these functions are controlled from some files. So if we will interchange the name of files it will work for us. here
Command line the file is: cmd.exe
Sticky key file is: sethc.exe
Both are present in "\windows\system32" directory. so we just need to take the backup of sethc.exe file. this thing can be done from Windows installation disk as well as Linux live disk.
So first go with Windows installation disk:
1. Boot off the Windows disk and select the "Repair your computer" option.
2. Find the option to open the Command Prompt and select it.
3. take the back of stiky file as
copy c:\windows\system32\sethc.exe c:\
4. Replace the stiky file with command prompt file as
copy c:\windows\system32\cmd.exe c:\windows\system32\sethc.exe
5. Reboot your system and on login screen hit shift key 5 times, a command prompt will open in administrator mode.
6. using "net user" command you will get user list present in your system.
7. Now time to change the password as:
net user <username> <password>
Now you can log in to your windows System. using your password.
Here you probably want to put back the original sethe.exe file. So you can reboot your system from Windows installation disk and go through step 1 & 2 to get command prompt. and execute the commend
copy c:\sethc.exe c:\windows\system32\sethc.exeSame thing can be done from linux environment also, Only you need to get this windows directory.
Saturday, March 31, 2012
Delete option is missing on right click
Solution: Which ever partition is having this problem Right-click on Partition and Select Property. Select Tools Tab And in Error-Checking Section Click on Check now button. Now one popup will come Check Automatically fix file system errors.
Monday, March 19, 2012
Fix for error "Network Device not managed" in ubuntu
I was configuring DHCP Server, after configuration successful i restarted my server then All Ethernet ports went down, i check Network Manager graphically it shows "Device not managed" then i checked it from terminal using
sudo /etc/init.d/networking restartIt gives me this message
* Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
* Reconfiguring network interfaces...
/bin/sh: cannot open /etc/iptables_rules: No such file
Failed to bring up eth0.
This was the issue i got.
Now Solution!!!
Edit the file "/etc/NetworkManager/NetworkManager.conf"
Change managed=false to managed=true
And ececute this in terminal.
sudo killall NetworkMangerNow we can configure our ethernet/wify interface.
Friday, March 16, 2012
Installation of Android SDK on eclipse
When the matter comes to work on android environment then everyone just think off Eclipse IDE, offcourse it provide lots of feature for android people as well as java developer i think which is no where else. if using eclipse we dont have to download any thing from internet except Eclipse classic.
Note:
While working on Eclipse IDE it is pre assumed that JDK is installed on your system and properly configured.
Now once we downloaded eclipse from here. Now after download complets extract it, and run Eclipse exetutable file. it will ask for workspace location go with default or you can configure it.Now we are ready with eclipse.
Android SDK Manager:
Go to menu tab,Click on help & go for Install New Software as shown in figgure.
now click on Add button a popup will come put some name and location as https://dl-ssl.google.com/android/eclipse/ and press OK button.
then it will search online and get a list of developer tools like this
just select all and click on next then it will calculate the depency & and and show a list of packages it is going to install click on next and accept the terms of license agreements and press finish.
now it will take some time to download & install packages from the location. after finishing the installation it will ask to restart Eclipse IDE. Do the same. on restart it will install ask where is android sdk? if you have downloaded it then just show the path or let it download from the internet. wait for finish it.
Again if it ask to restart Eclipse IDE then restart it.
SDK platform:
Now open Android SDK Manager from window tab in menu bar and install all Android SDK tools & Android SDK platform-tools and which ever SDK platform you want you can choose & install.
AVD Installation:
After installation of SDK platform just go to AVD Manager click on new and create an AVD of your requirement. on successful creation of AVD its all done.
Test:
Create a dummy android project & run it as android application it will take some time to start AVD for the first time & then it will take normal time.
Saturday, February 11, 2012
Shell Script for auto-start and shutdown for a service in linux
Some services are having different starting points in linux. for example webmin: To start webmin we need to execute the command /etc/webmin/start where as all service can be started as /etc/init.d/service-name start. this is comman practice now. so we will write a shell script which will allow us to make it auto-start and shutdown for a service with comman practice & will start when we boot up the computer. lets take an example of webmin.
To make webmin automatically start when we boot up the computer,Create a file in "/etc/init.d/" directory as
sudo vi /etc/init.d/webmin
And put the following code in that file:
# Webmin auto-start
#
# description: Auto-starts webmin
# processname: webmin
# pidfile: /var/run/webmin.pid
case $1 in
start)
sh /etc/webmin start
;;
stop)
sh /etc/webmin stop
;;
restart)
sh /etc/webmin start
sh /etc/webmin stop
;;
esac
exit 0
now we need to change the file permission of this file so that it become executable.
sudo chmod 755 /etc/init.d/webmin
The now the final step is to linking this script to the startup folders with a symbolic link as.
sudo ln -s /etc/init.d/webmin /etc/rc1.d/K99webmin
sudo ln -s /etc/init.d/webmin /etc/rc2.d/S99webmin
Now we are ready with our new set of commands to start, stop & restart the service as
sudo /etc/init.d/webmin start
sudo /etc/init.d/webmin stop
sudo /etc/init.d/webmin restart
How to Authenticate Users With Facebook Connect
Tutorial Details
- Topic: Facebook Connect, PHP
- Difficulty: Moderate
- Estimated Completion Time: 45 Minutes
Lately, there’s been quite a fuzz about lazy registration. It turns out that the less the user has to think, the higher the conversion rates are! What a thought! If everybody seems to have a Facebook profile, why not add a one-click user registration? I’ll show you how to do that today.
Step 1. The Setup
MySQL Table
Let’s begin by creating a database table.
- CREATE TABLE `users` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `oauth_provider` varchar(10),
- `oauth_uid` text,
- `username` text,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Quite simple: we will be setting up a table for user information with id, username, first and last name, the URL to the user’s picture, and registered date. Also, we’re adding both an
oauth_provider
andoauth_uid
fields, to distinguish between different third party open authentication protocols and their identifiers. For example, let’s say that, next week, you decide that it’s a good idea to also let Twitter users in. Easy; you just set another value to the oauthprovider, and avoid duplicating oauthuid values.The Facebook App
Let’s begin by creating a new application. Give it a name and agree to the terms and conditions. Next, grab both the API Key and Secret in the basic tab as shown below.
On the canvas tab, set both the Canvas URL and Post-Authorize Redirect URL to your localhost and path that the script will process — something like
http://localhost.com/login_facebook.php?
. Note the question mark at the end and the domain; both are required by Facebook. Simply set your hosts
file to a valid domain name.On the connect tab, set the Connect URL to the same value and set
localhost.com
(or the one you are using) as the Base Domain.Now save, download the client library, and unzip
facebook.php
in the src
dir to a new directory created in the root.Step 2. The Callback
The authentication flow has three steps:
- The local script generates a URL asking the user for permission
- Facebook returns to the Canvas URL specified with a GET parameter
- The GET parameter authenticates the session
Let’s make a quick test before registering and login.
- # We require the library
- require("facebook.php");
- # Creating the facebook object
- $facebook = new Facebook(array(
- 'appId' => 'YOUR_APP_ID',
- 'secret' => 'YOUR_APP_SECRET',
- 'cookie' => true
- ));
- # Let's see if we have an active session
- $session = $facebook->getSession();
- if(!empty($session)) {
- # Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
- try{
- $uid = $facebook->getUser();
- $user = $facebook->api('/me');
- } catch (Exception $e){}
- if(!empty($user)){
- # User info ok? Let's print it (Here we will be adding the login and registering routines)
- print_r($user);
- } else {
- # For testing purposes, if there was an error, let's kill the script
- die("There was an error.");
- }
- } else {
- # There's no active session, let's generate one
- $login_url = $facebook->getLoginUrl();
- header("Location: ".$login_url);
- }
Now, go to
http://localhost.com/login_facebook.php
, and let’s see what happens. If you are redirected to Facebook and requested for permission, we are on the right track.However, there might be two issues. The first one: if you’re redirected to Facebook, but it shows an error, there might be a missing value in the configuration. Go back to your application settings and check both the Connect and Canvas tabs and make sure the fields are ok as described above.
There might be another issue, where you see an error, like “Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK.” This happens because of the CURL settings. You’ll have to open
facebook.php
, find the makeRequest() method, and, inside the function, find this line:- $opts = self::$CURL_OPTS;
Immediately following it, add:
- $opts[CURLOPT_SSL_VERIFYPEER] = false;
I hate hacking libraries, but I haven’t found another way. Well, let’s continue with user registration. I’ve also added a try/catch statement, because, if there’s an old session keys in the GET params in the URL, the script will die with a horrible error.
Step 3. Registration and Authentication
We’ll next be working with MySQL. Please note that I will not implement a data sanitizer, since I want to keep the code as short and on task as possible. Please keep this in mind: always sanitize your data.
First, let’s connect to the database.
- mysql_connect('localhost', 'YOUR_USERNAME', 'YOUR_PASSWORD');
- mysql_select_db('YOUR_DATABASE');
Now, let’s work on the
$session
conditional, in case we have a session.- # We have an active session; let's check if we've already registered the user
- $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND oauth_uid = ". $user['id']);
- $result = mysql_fetch_array($query);
- # If not, let's add it to the database
- if(empty($result)){
- $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username) VALUES ('facebook', {$user['id']}, '{$user['name']}')");
- $query = msyql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());
- $result = mysql_fetch_array($query);
- }
Note that I’m querying the database, looking for
facebook
as a oauth_provider
; it’s generally a good idea, if you want to accept other OAuth providers (as twitter, Google Accounts, Open ID, etc.) and aoauth_uid
, since it’s the identifier the provider gives to its user accounts.The
oauth_provider
field could potentially lead to bad performance if we leave it as a text
field type. As such, the best option is setting it to an ENUM type.We have now a
$result
var with the values queried from the database. Let’s next add some sessions. Add this line at the beginning of your script.- session_start();
After the
empty($result)
conditional, append the following:- if(!empty($user)){
- # ...
- if(empty($result)){
- # ...
- }
- # let's set session values
- $_SESSION['id'] = $result['id'];
- $_SESSION['oauth_uid'] = $result['oauth_uid'];
- $_SESSION['oauth_provider'] = $result['oauth_provider'];
- $_SESSION['username'] = $result['username'];
- }
As it makes little sense to authenticate a user who is already logged in, just below the
session_start()
line, add:- if(!empty($_SESSION)){
- header("Location: home.php");
- }
And in the scripts which require authentication, just add:
- session_start();
- if(!empty($_SESSION)){
- header("Location: login_facebook.php");
- }
And if you want to display the username, access it as an array.
- echo 'Welcome ' . $_SESSION['username'];
- # or..
- echo 'Welcome ' . !empty($_SESSION) ? $_SESSION['username'] : 'guest';
Step 4. Additional Methods
Facebook has a ton of connect features, but here are four that I’ve found to be the most useful.
Legacy Methods
I might be missing something, but the FQL seems more flexible and easy than the Graph API. Fortunately, Facebook still lets developers use it, altough with the new library, it has changed a bit.
If you want the user id, first name, last name, squared thumbnail for the user picture, the biggest user picture available, and his or her gender, you can use the
users.getInfo
method.- $uid = $facebook->getUser();
- $api_call = array(
- 'method' => 'users.getinfo',
- 'uids' => $uid,
- 'fields' => 'uid, first_name, last_name, pic_square, pic_big, sex'
- );
- $users_getinfo = $facebook->api($api_call);
You can check the full list of fields available for Users.getInfo.
It is possible to achieve the same result, using FQL.
- $uid = $facebook->getUser();
- $fql_query = array(
- 'method' => 'fql.query',
- 'query' => 'SELECT uid, first_name, last_name, pic_square, pic_big, sex FROM user WHERE uid = ' . $uid
- );
- $fql_info = $facebook->api($fql_query);
Here’s the list of tables which can be accessed with FQL, as well as the fields available for the table users.
Extended Permissions
Facebook provides applications with some interaction with the user’s data – just as long as it’s authorized. With the old API, the authorization for additional permissions was exclusively available for the Javascript SDK (altough I’m not quite sure). With the new API, we can easily redirect the user to an authorization dialog in Facebook, and return to our site after the access is either granted or denied.
In the following example, we will be redirecting a user to authorize posts status updates, photos, videos and notes, the user’s real email address, birthday and access to photos and videos.
- $uid = $facebook->getUser();
- # req_perms is a comma separated list of the permissions needed
- $url = $facebook->getLoginUrl(array(
- 'req_perms' => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos'
- ));
- header("Location: {$url} ");
Here’s a full list of permissions. Note that you can specify both the url to direct to if the user accepts and the url to be redirected to if the user denies. The key for these array elements are
next
and cancel_url
, respectively. Here’s a quick example:- $url = $facebook->getLoginUrl(array(
- 'req_perms' => 'email',
- 'next' => 'http://localhost.com/thanks.php',
- 'cancel_url' => 'http://localhost.com/sorry.php'
- ));
If not specified, the default is the requesting script’s location.
Checking for Extended Permissions
Since the user can easily revoke permissions, the application should always check if a given permission is granted before using it, specially if it’s about publishing something. We will have to use the legacy API, as it seems it’s not fully implemented with the new one yet.
- $uid = $facebook->getUser();
- # users.hasAppPermission
- $api_call = array(
- 'method' => 'users.hasAppPermission',
- 'uid' => $uid,
- 'ext_perm' => 'publish_stream'
- );
- $users_hasapppermission = $facebook->api($api_call);
- print_r($users_hasapppermission);
The
ext_perm
will only support the old list of available permissions.Publishing to the Wall
Let’s post something to the wall after verifying the user has the
publish_stream
permission.- # let's check if the user has granted access to posting in the wall
- $api_call = array(
- 'method' => 'users.hasAppPermission',
- 'uid' => $uid,
- 'ext_perm' => 'publish_stream'
- );
- $can_post = $facebook->api($api_call);
- if($can_post){
- # post it!
- $facebook->api('/'.$uid.'/feed', 'post', array('message' => 'Saying hello from my Facebook app!'));
- echo 'Posted!';
- } else {
- die('Permissions required!');
- }
Essentially, we are making an API call to
/<user_id>/feed
, using the POST method (second argument) and an array as a third argument for the data to be sent. In this case, this third argument supports message
,link
, picture
, caption
, name
and description
. Here’s the code:- $facebook->api('/'.$uid.'/feed', 'post', array(
- 'message' => 'The message',
- 'name' => 'The name',
- 'description' => 'The description',
- 'caption' => 'The caption',
- 'picture' => 'http://i.imgur.com/yx3q2.png',
- 'link' => 'http://net.tutsplus.com/'
- ));
Here’s how it is posted.
Some Additional Information you Should Know:
The user can easily revoke permissions with two clicks in his or her wall. You should heavily test what might happen if a user revoked one or more permissions that are vital for the proper functioning of your website, or even if the application is fully removed. This is important.
- In Application Settings you can remove the application entirely by clicking the x at the right side.
- You can remove permissions individually in the Granted Additional Permissions section.
5. Conclusion
While Facebook’s authentication capabilities are indeed useful, since so many people are on Facebook these days, using it as the only method of authentication in a site is not recommended. What about those who don’t have Facebook accounts? Are they not allowed to access your application? Thanks for reading!
Saturday, January 28, 2012
Evolution of MS-DOS "Deal of the Century"
IBM & Microsoft History
In 1980, IBM first approached Bill Gates of Microsoft, to discuss the state of home computers and what Microsoft products could do for IBM. Gates gave IBM a few ideas on what would make a great home computer, among them to have Basic written into the ROM chip. Microsoft had already produced several versions of Basic for different computer system beginning with the Altair, so Gates was more than happy to write a version for IBM.
Gary Kildall
As for an operating system (OS) for an IBM computer, since Microsoft had never written an operating system before, Gates had suggested that IBM investigate an OS called CP/M (Control Program for Microcomputers), written by Gary Kildall of Digital Research. Kindall had his Ph.D. in computers and had written the most successful operating system of the time, selling over 600,000 copies of CP/M, his operating system set the standard at that time.
The Secret Birth of MS-DOS
IBM tried to contact Gary Kildall for a meeting, executives met with Mrs Kildall who refused to sign a non-disclosure agreement. IBM soon returned to Bill Gates and gave Microsoft the contract to write a new operating system, one that would eventually wipe Gary Kildall's CP/M out of common use.
The "Microsoft Disk Operating System" or MS-DOS was based on Microsoft's purchase of QDOS, the "Quick and Dirty Operating System" written by Tim Paterson of Seattle Computer Products, for their prototype Intel 8086 based computer.
However, ironically QDOS was based (or copied from as some historians feel) on Gary Kildall's CP/M. Tim Paterson had bought a CP/M manual and used it as the basis to write his operating system in six weeks. QDOS was different enough from CP/M to be considered legally a different product. IBM had deep enough pockets in any case to probably have won an infringement case, if they had needed to protect their product. Microsoft bought the rights to QDOS for $50,000, keeping the IBM & Microsoft deal a secret from Tim Paterson and his company, Seattle Computer Products.
Deal of the Century
Bill Gates then talked IBM into letting Microsoft retain the rights, to market MS-DOS separate from the IBM PC project, Gates and Microsoft proceeded to make a fortune from the licensing of MS-DOS. In 1981, Tim Paterson quit Seattle Computer Products and found employment at Microsoft.
Sources:www.about.com
Saturday, January 7, 2012
How to Set Up an Amazon EC2 Instance
Now We need to select an ami so here i am going with ubuntu AMI. Here we can choose ami from amazon also in Quick start tab. But we are going with ubuntu so we will get it in community AMIs and search for your Amazon ami using AMI-ID. we can choose with or without EBS.
Now if we need to go for specific settings then we can customize but here we are going with default settings as first time.
Now We need to create a key pair & download .pem file which can be use to connect to server usingh ssh.
ssh -i keypairfilename.pem ubuntu@public_address of AMI
if it ask for password provide as ubuntu further we can change it.
Friday, January 6, 2012
How to install Mac OS X Lion on Windows using VMware
A laptop or desktop computer that supports virtualization (most newer computers do).
At least 3 GB of RAM (the more, the better. OS X Lion requires 2GB to Proceed installation).
VMWare Workstation.
VMWare Hard Drive (vmx files, it is in a self-extracting .exe file just search for Mac_OS_X_Lion_VMware_Files.exe in Google).
OS X Lion (VMDK File)
Before we start, make sure that you have enabled Virtualization in the BIOS of your computer. This is usually disabled by default by computer manufacturers.
Now follow These steps.
- From the file downloaded, double click on Mac OS X Lion VMware Files.exe. Click Run then Yes. This will decompress the files.
- Once done, a folder named Mac OS X Lion VMware Files will appear, double click it.
- You will need to unlock VMWare. for this As the Administrator user, run the "windows.bat" program (located in the Workstation - Windows directory) from the command line (Command Prompt). follow readme.txt for help.
- From Step 1, there should be a folder named Mac OS X Lion inside Mac OS X Lion VMware Files. Copy the OS X Lion (VMDK File) to this locationOpen that up and open the file named Mac OS X Lion.vmx. Double-click this file. It will open in VMWare Workstation.
- On the left column, click on Edit Virtual Machine Settings. In the Memory tab, you can edit how much RAM OS X will get (Minimum 2 GB). At the bottom of the box is an Add button, click it. Select Hard Disk from the left, click Next. Choose Use and existing virtual disk.
- Browse for the Mac OS X Lion Installer.vmdk that was downloaded from the torrent. Click Finish. Click OK to close the box.
- On the left column, click Power on this virtual machine.
- If a box asks to repair the image, click Repair. Once the box comes up, click I copied it, click OK. A message about the CD Drive may come up, just click OK.
- You should now have a Install Mac OS X screen. At the top, click Utilities then Disk Utility. Select the 42.45 GB Hard Disk. Click on the Erase tab. Now you can name your hard drive what you want. Then click on Erase. Click Erase again.
- Once the process is done, close out of the Disk Utility box, the Install screen will come back up. Click Continue, Agree. Select the 40GB Hard Disk to install Lion. Click Install. The process will take about 30 minutes. Once it's done, the account setup will start. Once that's done, Lion will start.
Now Every thing is done Just go through your settings & its all done.
Wednesday, January 4, 2012
How to delete files older than certain time in linux
Using rm command
find
/path/to/files
* -mtime +5 -
exec
rm
{} \;
Note that there are spaces between rm, {}, and \;
Explanation
- The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
- The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
- The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.
Using delete command
First goto the Directory where we have to delete the files older than certain time/day.
CD /directory/path
Now Suppose we have to delete files older than 2 hour so we will use -mmin +120 which will list out all files older than 2 hours(120 min) & then delete to delete them as
Find . -mmin +120 -delete
Now Suppose we have to delete files older than 2 day so we will use -mtime +2 which will list out all files older than 2 days & then delete to delete them as
Find . -mtime +2 -delete
here i am using '.' after find which is showing current directory.