Phpbb3 sessions integration with existing site - integration

I hope I am in the right place!!
http://www.phpbb.com/kb/article/phpbb3-cross-site-sessions-integration/
http://www.phpbb.com/kb/article/phpbb3-sessions-integration/
What I am trying to do is integrate the phpbb forum with my existing site. I have already looked at the links above, and it doesn't seem to work. I have copied this code
define('IN_PHPBB', true);
define('ROOT_PATH', "/path/to/forums");
if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
exit();
}
$phpEx = "php";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
into a loginforum.php file, which I include in every page I want the sessions to be kept. I have done the three steps indicated in the sessions integration section, but when I try to check whether the user is authenticated, it doesn't seem so. Using the same code here:
<?php
if ($user->data['user_id'] == ANONYMOUS){
echo 'Please login!';
}
else{
echo 'Thanks for logging in, ' . $user->data['username_clean'];
}
?>
I only get the "Please login" phrase, even when I login.
I've been over this for hours, I don't understand where the problem is. Shouldn't it work after the three miraculous steps?? :(
I would be thankful to anyone who would try to help!
Cheers,
Den

This appears to be a duplicate of this question
However, try this answer:
if ($user->data['username'] == 'Anonymous')
{
echo 'Please login!';
}

Related

Wordpress multisite with same contents

Trying to accomplish the following. Any help/advice is greatly appreciated.
I have multiple domain names (e.g., site1.com, site2.com, site3.com).
I need each domain to display the same content
But show a different wordpress theme.Plugins are same...etc
Thank you
With regards to accessing the same site over different domains; although there may be recommendations against it as a general practice, you can add the following lines to your wp-config.php file:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
With that, you're basically saying to Wordpress 'treat whatever domain that's pointing this way as my base URL'.
For switching themes accordingly, you could try something like this in your functions.php (untested):
if (strpos($_SERVER['HTTP_HOST'], 'site2.com') !== FALSE) {
add_filter('stylesheet', 'siteTwoTemplate');
add_filter('template', 'siteTwoTemplate');
}
function siteTwoTemplate() {
$themeToGrab = 'site2theme';
$themeList = get_themes();
foreach ($themeList as $theme) {
if ($theme['Name'] == $themeToGrab) {
return $theme['Stylesheet'];
}
}
}
There may well be more efficient/safer means of achieving this, but it should do what you're after.

Does mediawiki allow me to make www.site.com/wiki/ the "main page" of the wiki?

...I know how to establish short URLs (using .htaccess) that remove the "index.php" from URLs. Now my Wiki main page URL looks like www.site.com/wiki/Main_page. However, i want it to simply look like www.site.com/wiki/ . Is it possible to do this without heavy modifications to the source code?
Yes, this can be done now. The main trick is to tell MediaWiki what the canonical URL of your main page is. To have the main page in the domain root:
$wgHooks['GetLocalURL'][] = function ( &$title, &$url, $query ) {
if ( $title->isExternal() || $query != '' && $title->isMainPage() ) {
$url = '/';
}
};
See http://laxstrom.name/blag/2015/08/31/mediawiki-short-urls-with-nginx-and-main-page-without-redirect/ for full details.

Overriding Drupal 7 Theme functions

I am new to Drupal as well as Drupal theme development. After learning how to override drupal template, I wanted to know how to override drupal 7 theme function. From the node Using the theme layer, the following things I have learned :
For every hook in a module, we need to register a hook function
Im plementation is 'template' file if it is defined in return array of the function. Otherwiaw implementation is through function.
Now following the book A definative guide to Drupal 7, to override a theme function
1. Copy - paste the theme function to my theme's template.php file
2. Change the beginning of filename from theme_ to yourtheme_
3. Save
To give example, it overrides the following function :
function theme_more_link($variables) {
return '<div class="more-link">' . l(t('More'), $variables['url'], array('attributes' => array('title' => $variables['title']))) . '</div>';
}
Now if I want to override the theme function comment_help() in comment.module:
function comment_help($path, $arg) {
switch ($path) {
case 'admin/help#comment':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the online handbook entry for Comment module.', array('#comment' => 'http://drupal.org/documentation/modules/comment/')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Default and custom settings') . '</dt>';
$output .= '<dd>' . t("Each <a href='#content-type'>content type</a> can have its own default comment settings configured as: <em>Open</em> to allow new comments, <em>Hidden</em> to hide existing comments and prevent new comments, or <em>Closed</em> to view existing comments, but prevent new comments. These defaults will apply to all new content created (changes to the settings on existing content must be done manually). Other comment settings can also be customized per content type, and can be overridden for any given item of content. When a comment has no replies, it remains editable by its author, as long as the author has a user account and is logged in.", array('#content-type' => url('admin/structure/types'))) . '</dd>';
$output .= '<dt>' . t('Comment approval') . '</dt>';
$output .= '<dd>' . t("Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href='#comment-approval'>Unapproved comments</a> queue, until a user who has permission to <em>Administer comments</em> publishes or deletes them. Published comments can be bulk managed on the <a href='#admin-comment'>Published comments</a> administration page.", array('#comment-approval' => url('admin/content/comment/approval'), '#admin-comment' => url('admin/content/comment'))) . '</dd>';
$output .= '</dl>';
return $output;
}
}
How can I do it? Its name does not starts from theme_.
The core comment module is uging hook_help function. You have to use the same function in your custom module. Notice that you should first clean any $output data using $output = "";

Prevent users from accessing admin area

Good Day,
am Facing a code error with my Admin control panel PHP page.
I want to prevent any other user from accessign this page unless his job_title= admin.
it works but even the admin himslef redirects back to login page again !!
here is the code
<?php
include('db.php');
?>
<?php
// Inialize session
#session_start();
ob_start();
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['name']) || ($_SESSION['job_title'] != "admin")) {
header('Location: index.php');
}
ob_flush();
?>
>?
<!-- STARTING HTML FORMAT !-->
?>
Any help ?
Try this, if still problems, let me know.
$_SESSION['name'] = 'dennis';
$_SESSION['job_title'] = 'admin';
if (!isset($_SESSION['name']) || (!isset($_SESSION['job_title']) ? false: ($_SESSION['job_title'] !== 'admin'))) {
echo 'Redirecting';
} else {
echo 'You\'re good! Not redirecting!';
}
This may be an easier way to understand, just put into a function.
$_SESSION['name'] = 'dennis';
$_SESSION['job_title'] = 'admin';
if (!isset($_SESSION['name']) || !isBoss()) {
echo 'Redirecting';
} else {
echo 'You\'re good! Not redirecting!';
}
function isBoss() {
if (isset($_SESSION['job_title']))
if ($_SESSION['job_title'] === 'admin')
return true;
return false;
}
I think your problem is a fubar newline :) Have added login page reference, which is unsetting the session variables you check for if logins fail.
Be very careful with where you put your <?php ?> tags - and in .inc files, such as db.php include - you may leave out the closing ?> tag on last line to avoid accidental ENTER, then CTRL + S failures, sneaking in an unwanted newline char in your output buffer (ob). IF ob_start is activated, nothing is written from server before you choose or script ends. ELSE if its not, default is that every \n will flush output and start the Content part of the payload.
login.php:
<?php
session_start(); // put this on top-most line in your script
$ok = check($_POST['user'], $_POST['pass']);
if($ok) {
$user = db_get_user_creds($_POST['user']);
$_SESSION['name'] = $user['name'];
$_SESSION['job_title'] = $user['job_title'];
} else {
// session_unset();
unset($_SESSION['name']);
unset($_SESSION['job_title']);
}
?>
admin.php
<?php
session_start(); // put this on top-most line in your script
// or, use ob_start at the very first line
// (with no widespace what so ever written out before it)
include('db.php');
?> I am writing out a newline here, session / header section is going to become unstable
<?php
// Inialize session
// #session_start(); moved up top
ob_start();
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['name']) || ($_SESSION['job_title'] != "admin")) {
header('Location: index.php');
}
ob_flush();
?>
See the 'I am writing out newline here' bit
A little deeper down rabbithole goes; the communication flow is like this:
1) HEADERS such as
Connection: keep-alive\r\n
Content-Type: text/html\r\n (etc)
2) DOUBLE NEWLINE (one newline with no previous chars on that line)
\r\n
3) CONTENTS
Body
Of Page

Missing image in cakephp blog post

I am new to cakePHP and I am tring the blog example of cakePHP 1.3 book .
I correctly upload image in this blog example.The image name in database and image in DOCUMENT_ROOT/....correctly
but now I am wanted to show image in my blog with related post.
I am using this code for image upload...
function add() {
if (!empty($this->data)) {
if(isset($this->data["Image"]["image"]["name"])){
$file = new File($this->data["Image"]["image"]["name"]);
$ext = $file->ext();
if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
$this->Session->setFlash('You may only upload image files.');
}else{
if(move_uploaded_file($this->data["Image"]["image"] ["tmp_name"],$_SERVER["DOCUMENT_ROOT"]."test_om/blog/app/webroot/img/upload_image/"
. $this->data["Image"]["image"]["name"]) == true){
$this->data["Post"]["image"] = $this->data["Image"]["image"]["name"];
}
$this->Post->save($this->data);
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
}
}
}
and i am showing image form this code
<?php echo $this->Html->image('/img/upload_image/1.gif'); ?>
and this show same image with all post.
but i am wanted to set specfic image with its related post....
If you are sure you are getting everything correct (in the database and the file where it should be) you should use something like this in the view.
<?php echo $this->Html->image($this->data['Post']['image']); ?>
this is assuming you are passing the data from the controller in the way described in the tutorial to a view view :)
if is an index view you should have a variable posts that have all post info, and in the view you will be in a loop like a foreach ($post as $post). Assuming this your view should have something like this:
<?php echo $this->Html->image($post['Post']['image']); ?>
Suggestion: use debug kit (cakephp plugin) so you can see what variables are passed down and the structure (like a pr($variable))
Hope all this helps you, if not, comment this post so i can try to extend my answer if needed