Home
In Development
Adding PHP to Joomla! Pages
Adding PHP to Joomla! Pages
I'm going to try out the DirectPHP plugin next. It claims to allow you to insert PHP right into your articles.
Installation was automatic - no errors generated.
Now, I have a table in one database that has a contact list and a second table that has a list of authorized users.
I added a joomlaid field (int default 0) to that table, and put my joomla userid in my user row of that table.
I want to have a page in my Joomla! site which, when requested, will check that table to see if I have access to it (through joomlaid association), and if I do have access to the page, I want it to display the options to which I am entitled (view all contacts, edit a contact, etc.). If I do not have access to the page, I need to redirect to somewhere else or offer subscription service to access the page. Ideally, the link to the page would not even show up if I wasn't authenticated to the table, but the point of this exercise is to play with php in pages and not re-writing the rather limited JACL.
My ultimate goal is to create a user check script for each app I have user accounts in. I'll add an article to the user menu that includes these scripts and displays appropriate links to the validated to be available apps. (All of which I wouldn't have to do if the JACL didn't suck *imho*)
I made an article, next, and put in the one line
I left it in the Uncategorized Section since I would be putting it on a menu link. I then added it to my User Menu as an Articles->Article Layout. I named it Subscriber Links and gave it Registered Access.
Here's how it works:
Make an access file somewhere. I've not tested whether it must be under the Joomla! install or not. My file is called get_user.php.
get_user.php:
defined('_JEXEC') or die('Restricted access');
include_once $_SERVER['DOCUMENT_ROOT'] . "/db_access.php" ;
$user =& JFactory::getUser(); // an Object
$db = new db_access();
if ($db->connect()) {
$sql = "select * from webapp_users_table where joomlaid=" . $user->id;
//echo $sql . "
";
$result = $db->query($sql);
$_SESSION['loggedin_webapp_user'] = false;
if ($result) {
while ($row = mysql_fetch_array($result)) {
$_SESSION['loggedin_webapp_user'] = true;
}
}
}
$db->close();
if ($_SESSION['loggedin_webapp_user']) {
echo "Click Here To See Your Contacts";
} else {
echo "You are not subscribed to this service. Click here to sign up right now!";
}
Inside your article, just use standard php syntax to include this get_user.php file. When you navigate to the article you will see either "Click Here To See Your Contacts" or "You are not subscribed to this service. Click here to sign up right now!"
Trackback(0)
TrackBack URI for this entryComments (1)
Subscribe to this comment's feedWrite comment

Last Updated (Sunday, 22 March 2009 19:05)





