Jump to content

integrating phpvms login


GlobalOne

Recommended Posts

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.

  • Like 2
Link to comment
Share on other sites

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... :ph34r:

Link to comment
Share on other sites

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;

}
?>

Link to comment
Share on other sites

  • 6 months later...

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?

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

  • 4 months later...

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
}
?>

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
  • 1 year later...
  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...