I'm using below code for getting session in my Joomla website from other application


if (isset($_POST["acode"]) && strlen(trim($_POST["acode"]))!=0)
    $_SESSION["bcode"] = $_POST["acode"];
else if (isset($_POST["bcode"]) && strlen(trim($_POST["bcode"]))!=0)
    $_SESSION["bcode"] = $_POST["bcode"];
else if (isset($_POST["ccode"]) && strlen(trim($_POST["ccode"]))!=0)
    $_SESSION["ccode"] = $_POST["ccode"];
}else //if(count($_SESSION)==0)
     header("Location: http://www.xyx.in/session_expired.php");

$_SESSION["desk"] = "509";

Now I want the scenario that no-one would be able to see the website without logging in from the desk, the scenario is some what set, like when I type my sites path it shows session expired error.

Now after logging from the desk, the website is getting the session, but on clicking the submenus the session expired page shows up.

I have tried every thing to my knowledge, but can't find the proper solution

  • 1
    I would suggest using Joomla's session API rather than PHP's native one – Lodder Nov 13 '15 at 9:23

Not sure if I understand your question correctly, but if you want to make the website available to registered users only, you can do like this:

  1. Set website to offline mode
  2. In your admin area, go to Global Configuration - Permissions tab, and set Offline access for the Registered group to Allow.
  3. Edit the Offline notification with a notice that users will have to log in to access the site.
  • @Bogowe: i know that scenario but you are not getting the que Website is live but i want only our clients to access it. I have 1000+ clients and they have their own dashboard where the link to the website is provided on click i'm getting their session ids, i have applied the above code in the template index.php file and it works fine(on typing the website link it shows session expired page), after they login from the dashboard they are able to view the website,but if they click on another menu, they get the session expired page that i created so i want to sort this error out – Brijesh Savaliya Nov 16 '15 at 7:26

As I have understood you want to make your site access to only logged in users. For this, in Joomla, you can take the id of login user and then check to provide site access:

$user = JFactory::getUser();
$userid = $user->id; //gives you the login user id

//check whether user is guest or not to provide access
   //perform code to provide access to registered users
  //perform code for guest users

Hope this helps

  • yes only to logged in users, but those users are logged in already in their respective dashboards, and not on the website. the above code gets their codes from the session from the dashboards and checks whether it is getting the code or not. If it is getting the code then it should allow to access the website otherwise not. initially i have succeeded in getting their session but on click of another menu it gets again redirected to the session expiry page – Brijesh Savaliya Nov 16 '15 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.