Severity: Warning
Message: Undefined variable $page
Filename: front/Articles.php
Line Number: 91
Backtrace:
File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 91
Function: _error_handler
File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once
Severity: Warning
Message: Undefined variable $pages
Filename: front/Articles.php
Line Number: 110
Backtrace:
File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 110
Function: _error_handler
File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once
Severity: Warning
Message: Undefined variable $page
Filename: front/Articles.php
Line Number: 111
Backtrace:
File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 111
Function: _error_handler
File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once
Severity: Warning
Message: Undefined variable $category
Filename: front/Articles.php
Line Number: 113
Backtrace:
File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 113
Function: _error_handler
File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once
Severity: Warning
Message: Undefined variable $articles
Filename: front/Articles.php
Line Number: 114
Backtrace:
File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 114
Function: _error_handler
File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once
checkLogin which will take 3 parameters (the supplied username, the supplied password and a flag indicating whether the user would like us to remember him/her on subsequent visits). The function which logs a user into a phpbb2 forum might look like this:
/*
$pu = passed username
$pp = passed password
$pr = passed remember flag
*/
function checkLogin($pu, $pp, $pr)
{
// Validate the username password combo
// using the current system. This assumes
// that you are working off a table called
// members and that all user passwords are
// stored as md5'd strings.
$sql = "SELECT * FROM members WHERE username = '$pu' AND password = '".md5($pp)."' LIMIT 1;";
$result = mysql_query($sql, $GLOBALS['db']);
if (mysql_num_rows($result)>0)
{
// At this point, we have validated the
// user credentials, we should now
// perform any perfunctory login actions,
// such as setting cookies for remembering
// the user, establishing the session
// variables. Details on this are beyond
// the scope of this article.
setSession(mysql_fetch_array($result), $pr);
// This is where it gets interesting,
// construct an array of POST variables
// that will be passed to the login script
// of the phpbb2 forum. To modify this
// function for a different forum,
// download a HTTP packet sniifer (such
// as HTTPLook), login to your forum in
// the normal manner and see what POST
// variables are passed to the login
// script in the HTTP request. Then simply
// replicate those variables here.
$post_data = array();
$post_data['username'] = $pu;
$post_data['password'] = $pp;
$post_data['autologin'] = ($pr) ? 'on' : '';
$post_data['login'] = 'Log in';
// The forum login script may attempt to
// set cookies depending on what the login
// mode is (i.e. whether the user should be
// remembered or not). To facilitate that
// functionality, we need to define a
// temporary file to hold the contents of
// the cookie.
$cookie_new = tempnam("/tmp","MKUP");
// Construct the cURL request, the
// options to note here are:
// 1) The URL of the forum login script
// using CURLOPT_URL
// 2) The incorporation of post data using
// CURLOPT_POST/CURLOPT_POSTFIELDS
// 3) The cookie handlers, CURLOPT_COOKIEFILE
// and CURLOPT_COOKIEJAR
// 4) The inclusion of the response header
// in the result using CURLOPT_HEADER
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mysite.com/forum/login.php");
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_new);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_new);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Storing the result of the request
// including the HTTP response header is
// highly recommended as it can be used most
// effectively to decipher what, if anything,
// has gone wrong.
$postResult = curl_exec($ch);
// Trigger any cURL related errors at this point
if (curl_errno($ch))
{
// Trigger error
}
// Close the cURL session
curl_close($ch);
// If everything went according to plan,
// the contents of any cookies the login
// script wanted to set will be stored in
// $cookie_new. At this point then we must
// actually set the cookies as simply requesting
// them via cURL will not set them on the client
// browser. Read the contents into a variable
// using the file_get_contents function.
$cookie_status = array();
$cookie_contents = file_get_contents($cookie_new);
// Now that we have the contents of the
// "cookie jar", we can delete the temporary
// file to save resources.
if(file_exists($cookie_new))
{
unlink($cookie_new);
}
// Split the jar into it's individual cookies
// by using the "\n" delimiter.
$cookie_contents_array = explode("\n",$cookie_contents);
// Cycle through each cookie in
// $cookie_contents_array and if the cookie
// applies to our domain "mysite.com",
// process it. It's hard to imagine a situation
// where a cookie belonging to another domain
// would get into the temporary cookie file yet
// I can't help but check!
for($i = 0; $i < count($cookie_contents_array); $i++)
{
if(strpos($cookie_contents_array[$i],"mysite.com")!==false)
{
// Process the cookie here. Each entry
// will consist of various snippets of
// information, including the path that
// the cookie belongs to, the time to
// expire the cookie, the cookie name
// and the cookie value. Each bit of
// information is separated by the tab
// character "\t".
$cookie_array = explode("\t",$cookie_contents_array[$i]);
// Small branch here for clarity sake,
// the cookie might not have an expire
// time, in which case we simply don't
// include the "expires" parameter in the
// response we send to the client. One
// other point to note that as of PHP
// version something point something, we
// have an optional boolean flag as the
// second parameter to the header
// function. To set all the cookies
// irrespective of whether they have been
// set previously, pass in false. This
// comes highly recommended!
if($cookie_array[4]!=0)
{
header("Set-Cookie: ".$cookie_array[5]."=".$cookie_array[6]."; expires=".date("r",$cookie_array[4])."; path=/",false);
}
else
{
header("Set-Cookie: ".$cookie_array[5]."=".$cookie_array[6]."; path=/",false);
}
}
}
// Depending on the settings in your
// php.ini file, you should also set the
// PHPSESSID value to the current session
// id for use in both your existing login
// system and the forum script as it will
// no doubt be used extensively.
header("Set-Cookie: PHPSESSID=".session_id()."; path=/",false);
// Phew, finito! Login is successful (at
// least in terms of the user having
// provided the correct credentials),
// you won't know whether the login worked
// at this point although, it's fairly safe
// to say that if your code gets inside
// the 'process cookie' logic, you're well
// on your way.
return true;
}
else
{
// User didn't get their username
// and/or password right so login
// is unsuccessful.
return false;
}
}
header("Set-Cookie:...");
header("Location:...");
if(checkLogin($username, $password, $remember))
{
print file_get_contents("meta_refresh.php?url=/members/index.php&delay=0");
exit();
}
meta_refresh.php might look like this:
if(empty($delay)) { $delay = "0"; }
if(empty($url)) { $url = "/"; }
?>