Understanding the basics

Hi Happy new year to you all!

Im learning php…I havent gotten my head around something and was hoping a pro could explain or help…

This is my code I have to insert into my website (joomla) index.php…


<?php
require_once('37603303e9f36186bcc6bac.php');
$voltRank = new VoltRank();
echo $voltRank->display();
?>

Ok What I am trying to achieve:

This code displays on ALL my pages, therefore I want it to display on only this page: http://www.insight-design.co.za/index.php?option=com_content&view=article&id=48&Itemid=43

(Excuse the long url?..)

What I thaught is to add an if statement, but please can someone show this girl how to do this?..makes sense?

Thanks:blush:

In Joomla you should not (at least I don’t recommend) add any custom codes directly index.php file. Instead you should develop simple extension (possibly a system plugin for your purpose I guess, or a module) so that your code does not overwritten when you upgrade Joomla later on. Otherwise though I am not sure what exactly the function does, you can even place it on the template file as well. If it displays something then develop a simple module and install it to a position in the current template.

I know you shouldn’t add code for when things get upgraded…I simply needed the help with the code, to learn php

thanks

Rajugs answer covers it, but seeing as you still ask:

if the incoming url contains the url arguments, using the GET method in the url string

?option=com_content&view=article&id=48&Itemid=43

And you have something that should only show up when those exact values appear, you would add this conditional check:


if( $_GET['option'] == 'com_content' 
 && $_GET['view'] == 'article'
 && $_GET['id'] == 48
 && $_GET['Itemid'] == 43 ){

// do something special

}

In fact it is worse than that, you’d also have to have previously checked each of those $_GET keys was set to stop loads of warnings appearing in your log files and potentially on your site if one or more of them was not set.


if( isset($_GET['option'] ) && // and so on

You are best off getting as close as you can to the template which governs the behaviour of this particular set of pages (articles?) and just check for the existence of say, id : 48


f( isset($_GET['id'] ) && $_GET['id'] == 48 ){

// do something special

}

There may well be a Jommla-esque way of doing what you want, you could seek out Joomla users to ask them.

Thank you, both comments helped me in my coding thanks for your support

I have another code question…if somone is around :slight_smile:

In my joomla website I need to create some funny custom “prize-image designed with links to different pages” where the prizes are…very silly but its what the client wants…all people have to log in first…

What I need is that once a certain user is on the main page and clicks to the next page, he IS NOT ALLOWED to go back to the main page…so I need some sort of code that will be inserted into the article, not allowing the user to go back to the page…

Please can anyone of the gurus help. Thank you Cups

I think you are developer you must know that you cannot insert any codes in the articles. So that has to be done via code and possibly with your controllable component or module/plugin. The idea would be to store the visited page numbers (I would assign numbers to each step or page) in session/cookie and check if he/she current page is less than the maximum reached page number then always redirect or give some warning/error message to the user.

If someone wants to go back to the home page, they will workaround any kludge you try and fix up.

Might be better to instantiate a session when they arrive on the home page, show them the link.

Set a session variable:


$_SESSION['visited_home_page'] = true;

When they go back to the home page, do not show the link if that session variable is set.

Even then, all they have to do is open a new browser session and revisit the home page with a new empty session, this might satisfy your client.

*Edit, actually I think that is what Rajug just said – never mind, I will leave this comment.

Wow! Thanks fo the response!

Better yet, I found this plugin after nights of research :which will allow me to add the code I need:

http://www.metamodpro.com/metamod/recipes/40-general/78-page-redirection

Now I need to know what the right code is to inset to my page, let me give a clear explanation as I did not before…

When any of my users to my website falls on THIS page:http://topplacestravel.co.za/index.php/quiz-pop (via a url sent to their email box)

When they navigate AWAY from this page they wont be allowed to view that page again, therefore each user is restricted to only view the page ONCE -make more sense?

This is exactly what I need. Please can someone help???

I think you are developer you must know that you cannot insert any codes in the articles. So that has to be done via code and possibly with your controllable component or module/plugin.

You are quite right, I have found a plugin thank you

What is your page? A file having .php extension or an article (if it is Joomla) having a separate menu is a page? In either case you have to track/store visited pages either in a session variable or cookie. If a page meant to be a Joomla article having a menu (Itemid) then you have to store Itemid or id (id of a content) once it is visited. And check the Itemid it is already visited. You need to write something like below code in a system plugin.


if(!in_array(JRequest::getVar('Itemid'), $_SESSION['_visited_page']){
    $_SESSION['_visited_page'][] = JRequest::getVar('Itemid', 0);
}
else{
    die('Sorry you are allowed to visit this page only once!'); // or anything
}

Hi

Thank you !!!

Sorry, I have an ARTICLE http://topplacestravel.co.za/index.php/quiz-pop… I hope I understand…

Do I need to use the id of this article then? …and most important - can I use this code?

Thanks
God Bless!

Hi, I am working on a tight deadline here…:x

I have inserted your code into my article and also used a better plugin: http://extensions.joomla.org/extensions/edition/custom-code-in-content/4470?qh=YTo0OntpOjA7czozOiJwaHAiO2k6MTtzOjQ6InBocCciO2k6MjtzOjU6InBocCdzIjtpOjM7czoxNToicGhwJywnbW9zY29uZmlnIjt9

I inserted your code into my article http://topplacestravel.co.za/index.php/quiz-pop, but It did still allow me to enter the page :frowning:

What am I doing wrong? please help?

As I already told that PHP codes cannot be inserted directly into the article but you need to add the code in a plugin (possibly the system plugin and I presume you are quite aware of different types of plugins in Joomla since you are a Joomla developer). The code I gave above is just an idea how you can do to achieve the goal and you are the one to manage accordingly.

I don’t know what you have written, but when I tried to visit the page http://topplacestravel.co.za/index.php/quiz-pop I got the message ‘You are not authorised to view this resource.’. What it should show? Is it the article to be shown on the page? If you are not a Joomla developer and cannot operate with Plugins then you have to hire someone to look in to it.

Good luck!

log in with

name:corpt
password:corpt

Then you should see the article WHICH is only allowed to be seen ONCE. I have used a PLUGIN
http://extensions.joomla.org/extensions/edition/custom-code-in-content/4470?qh=YTo0OntpOjA7czozOiJwaHAiO2k6MTtzOjQ6InBocCciO2k6MjtzOjU6InBocCdzIjtpOjM7czoxNToicGhwJywnbW9zY29uZmlnIjt9to allow php in an article and I am a Joomla developer

:frowning: