GlobalOne Posted June 29, 2012 Report Share Posted June 29, 2012 Hey everyone got another technical question. I am developing a external module which will be run under the same domain but different directory to my local phpbms installation and I want to integrate the login feature, so it only displays content to users who are logged in and redirects other users to the login form. Thanks for the help. 2 Quote Link to comment Share on other sites More sharing options...
MaciejO Posted June 30, 2012 Report Share Posted June 30, 2012 Hi there, its quite simple! <?php require('core/codon.config.php'); /* Call the PHPVms Config File */ if(Auth::LoggedIn()) { ?> Display content you want to display for users which are logged in! <?php } else { ?> <script type='text/javascript'> window.location = '<?php echo url('login"); ?>' <?php /*javascripts redirect as php headers error will display if php function is used*/ ?> </script> <?php } ?> Mac... Quote Link to comment Share on other sites More sharing options...
Tom Posted June 30, 2012 Report Share Posted June 30, 2012 You can also redirect server-side, in case they don't enable javascript - more reliable <?php require('core/codon.config.php'); // Call the phpVMS config file if(Auth::LoggedIn()) { ?> Display content you want to display for users who are logged in! <?php } else { header("Location: ".url('/login')); exit; } ?> Quote Link to comment Share on other sites More sharing options...
GlobalOne Posted June 30, 2012 Author Report Share Posted June 30, 2012 You can also redirect server-side, in case they don't enable javascript - more reliable Display content you want to display for users who are logged in! Worked perfectly. Thanks! Quote Link to comment Share on other sites More sharing options...
freshJet Posted January 19, 2013 Report Share Posted January 19, 2013 Just a quick advance on this, I already have my code which is similar to what was posted but what needs to be modified for the login form? I have copied and pasted the login form into my new file which submits but does not redirect where I want it to. Nor does it show the logged in content once the form is submitted. I'm guessing I'm trying to log myself in on my main site? Quote Link to comment Share on other sites More sharing options...
freshJet Posted March 3, 2013 Report Share Posted March 3, 2013 I have an external module where the login was fine and the logout works, but produces the 'headers already sent' error. Here is my logout.php: <?php include('/home/freshjet/public_html/core/codon.config.php'); ?> <title>Page title</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <?php function logout(){ $ret = Auth::LogOut(); if($ret == true){ echo 'You are now logged out'; } } logout(); ?> And the error: Warning: Cannot modify header information - headers already sent by (output started at /home/freshjet/public_html/portal/logout.php:5) in /home/freshjet/public_html/core/common/Auth.class.php on line 341 Quote Link to comment Share on other sites More sharing options...
Tom Posted March 3, 2013 Report Share Posted March 3, 2013 I believe you have to run the header() function before any php tag is closed. Quote Link to comment Share on other sites More sharing options...
freshJet Posted March 3, 2013 Report Share Posted March 3, 2013 For example? Quote Link to comment Share on other sites More sharing options...
Tom Posted March 3, 2013 Report Share Posted March 3, 2013 Just make everything inside the php: <?php include('/home/freshjet/public_html/core/codon.config.php'); echo '<title>Page title</title> <link href="styles.css" rel="stylesheet" type="text/css" />'; function logout(){ $ret = Auth::LogOut(); if($ret == true){ echo 'You are now logged out'; } } logout(); ?> Quote Link to comment Share on other sites More sharing options...
freshJet Posted March 3, 2013 Report Share Posted March 3, 2013 Didn't. I removed the stylesheet link and page title and it works fine. Bugging me now, but might just leave it as a bare page. Quote Link to comment Share on other sites More sharing options...
Tom Posted March 3, 2013 Report Share Posted March 3, 2013 Oh ok that's wrong. You have to do the header() before you output anything on the page... so move all your echos to after that. Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted July 25, 2013 Report Share Posted July 25, 2013 Any ideas why Auth::LoggedIn doesn't work in mine? Basically, when logged in, the site still opens and shows the !Auth::LoggedIn state (a login form). <?php include_once'/home/flyeurov/public_html/core/codon.config.php';?> <html> <head> ... </head> </html> <body> <?php if(!Auth::LoggedIn()) { // Show these if they haven't logged in yet ?> <p>Login form etc</p> <?php } else { ?> <p>You have been logged in!</p> <?php } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 26, 2013 Report Share Posted July 26, 2013 <?php include('/home/flyeurov/public_html/core/codon.config.php');?> 1 Quote Link to comment Share on other sites More sharing options...
avdesigns Posted July 31, 2013 Report Share Posted July 31, 2013 Hello, I have an external application with a login built into it however when I submit the login it logins in to the site however instead of redirecting to the page I have told it to it is going to the login page that is on the phpvms system which may be something to do with <form action="<?php echo url('/login'); ?>" name="loginform" method="post">. I have used the basic login form found on the layout.tpl but changed the redirect page, any suggestions? Thanks Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 31, 2013 Report Share Posted July 31, 2013 I do it like this: <?php function login(){ $user = $_POST['username']; // username field in form $pass = $_POST['password']; // password field in form Auth:ProcessLogin($user, $pass); } ?> Add name="submit" to your submit button and then: if(isset($_POST['submit'])){ login() } Then you can do an else for errors etc... Quote Link to comment Share on other sites More sharing options...
avdesigns Posted July 31, 2013 Report Share Posted July 31, 2013 I do it like this: <?php function login(){ $user = $_POST['username']; // username field in form $pass = $_POST['password']; // password field in form Auth:ProcessLogin($user, $pass); } ?> Add name="submit" to your submit button and then: if(isset($_POST['submit'])){ login() } Then you can do an else for errors etc... Thanks for replying I keep getting fatal errors when trying this, please can you place the form so I can ensure I am placing things correctly? Thank you Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 31, 2013 Report Share Posted July 31, 2013 Have you still included the codon.config.php? Quote Link to comment Share on other sites More sharing options...
avdesigns Posted August 1, 2013 Report Share Posted August 1, 2013 Hello Yes as it is able to pull data from the site and knows not to show pages when not logged Thanks Jacob Quote Link to comment Share on other sites More sharing options...
freshJet Posted August 1, 2013 Report Share Posted August 1, 2013 This example will be done using a single page, if you want a redirect after form submit just enter an action and move the PHP over to the new page. <?php if(isset($_POST['submit'])){ login(); } ?> <form action="" method="post"> <input type="text" name="username" /> <input type="password" name="password" /> <input type="submit" value="Login" name="submit" /> </form> <?php function login(){ $user = $_POST['username']; $pass = $_POST['password']; $login = Auth::ProcessLogin($user, $pass); } ?> 1 Quote Link to comment Share on other sites More sharing options...
avdesigns Posted August 1, 2013 Report Share Posted August 1, 2013 Perfect thanks for that Quote Link to comment Share on other sites More sharing options...
avdesigns Posted November 9, 2013 Report Share Posted November 9, 2013 The code works brilliantly to login however when I try copying the php from the login I get php errors about declaring the class so cant seem to get it to direct and login at the same time. How do I make the login.php data declare the class? Thanks Quote Link to comment Share on other sites More sharing options...
avdesigns Posted December 13, 2013 Report Share Posted December 13, 2013 bump Quote Link to comment Share on other sites More sharing options...
pedrobrandine Posted September 1, 2015 Report Share Posted September 1, 2015 then hello my is not working out he does not log he is redirecting to the login page again Quote Link to comment Share on other sites More sharing options...
danydj96 Posted February 29, 2016 Report Share Posted February 29, 2016 Hello, I would like to implement it but I don't know how it really works? Could someone explain me a little bit more how to do this? Regards, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.