Inserting PHP code onto every topic page in Webhelp

Please post all questions on Help+Manual 8 here

Moderators: Alexander Halser, Tim Green

Post Reply
Pshooter
Posts: 18
Joined: Tue Aug 19, 2008 3:55 am

Inserting PHP code onto every topic page in Webhelp

Unread post by Pshooter »

Inserting PHP code onto every topic page in Webhelp.

Not sure if this topic should be here or in the Premium skin section, but here goes:

I want to insert code like this:

Code: Select all

if (!isset($_COOKIE["cookiename"])):
    header("Location: /member-login/");
endif;
into every topic page that is output to webhelp. Is this possible using H&M 8/Premium Skin?

Thanks,

Paul
User avatar
Tim Green
Site Admin
Posts: 23178
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Inserting PHP code onto every topic page in Webhelp

Unread post by Tim Green »

Hi Paul,

Do you want this to be executed the when the user first accesses the help or on every page display within the help? The V3 and V4 Premium Pack skins use dynamic browsing, so only the first visit is actually a page load. Once the user has loaded the WebHelp new pages are displayed by replacing content on the existing page from a compressed JSON version of the target page and changing the DOM history stack for the Address bar and history and search engine indexing, so the current page doesn't actually change physically.

If it's just for the first visit you can insert your code in the HTML page template, which you can open in your code editor with Toolbox by selecting the Page Template button. (You need to set up your editor and activate advanced features with Preferences in the Edit menu first.)

There is a mechanism for executing JavaScript code on every topic visited, but that won't help you with PHP because there is no page reload and thus no access GET or POST and nothing that PHP could rewrite, as the DOM is not rewritten from the server. That is why the pages load so fast -- all the assets are just loaded once on the first visit. Everything after that is just local content replacement. :?
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
Pshooter
Posts: 18
Joined: Tue Aug 19, 2008 3:55 am

Re: Inserting PHP code onto every topic page in Webhelp

Unread post by Pshooter »

If we did the first option, which checks if the user is logged in on first load, the code might look something like this. Do I need the php headers? Where in the skin configuration would this go?

Sorry for being such a noob. I'm sort of playing the go-between between the tech support here and my pal who is helping me with the php.

Code: Select all

<?php
# Make sure the user has logged in to our WordPress site:
$wpLoggedIn = false;
foreach ($_COOKIE as $key => $value):
  if (stripos($key, 'wordpress_logged_in_') === 0):
    $wpLoggedIn = true;
    break;
  endif;
endforeach;
if(!$wpLoggedIn):
  Header("Location: /member-login/");
endif;
?>
User avatar
Tim Green
Site Admin
Posts: 23178
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Inserting PHP code onto every topic page in Webhelp

Unread post by Tim Green »

Hi Paul,

You didn't mention you are using WordPress. When you use a V3 or V4 skin with the WordPress plugin it is not really part of the WordPress site. It displays itself in an iFrame overlaid on the site and is completely separate from your entire WordPress page rendering and display system. And since it is displayed in an iFrame it remains a separate site, so there would be no way of checking whether the user is logged in or not from there -- no more than you could check it from any other website.
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
Post Reply