Posts Tagged ‘MySQL’
Custom error pages with htaccess
A tutorial to enable custom error pages with an htaccess file. Note htaccess files only work on a linux server
To create an htaccess file open notepad or any plain text editor and save the file as .htaccess, if using notepad make sure the file type is set to all files or you will create a txt file.
There are five types of error pages that your server has to offer which are:
400 – Bad request
401 – Authorization Required
403 – Forbidden directory
404 – Page not found
500 – Internal Server Error
if you don’t have the right page like say a 404 page then the server issues you the error and informs you it could not find an error document. Making your own custom error page is very easy with htaccess on an htaccess file enter the command ErrorDocument then the error number then a forward slash then the path to the error page which tells the page where to go like this:
ErrorDocument 404 /errors/404.php
The final file will look like this:
ErrorDocument 400 /400.html ErrorDocument 401 /401.html ErrorDocument 403 /403.html ErrorDocument 404 /404.html ErrorDocument 500 /500.html
Save the htaccess file in the root of the server then if their is an error the custom error page is served.
Credit : phphelptutorials.com
Insert Your Recent Comments from Facebook to Database
Here php code will pass the variables by POST method to https://login.facebook.com/login.php page and login into facebook account then other curl call will call my home page to get the home page HTML.
<?PHP
$first_name = 'First Name';
$login_email = 'facebookloginemail';
$login_pass = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);
/*
Here it will print the facebook home page with your recent updates
*/
echo $page;
// Parse the HTML information and return the results.
$dom = new DOMDocument();
@$dom->loadHtml($page);
$xpath = new DOMXPath($dom);
// Get a list of articles from the section page
$articleList = $xpath->query("*/div[@id='m_stream_stories']");
print_r($articleList);
// Add each articles url to the Articles array
// This way we can scrap any part of data of any sites.
$articles = array();
foreach ($articleList as $item){
$articles[] = array(
'url' => $item->getElementsByTagName('a')->item(0)->getAttribute('href')
);
}
print_r($articles);
// Here we can loop for the article array and insert it into database.
?>
If you have any trouble in getting it work let me know i will help you.
















