Jump to content

Recommended Posts

Posted

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
Posted

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:

Posted

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;

}
?>

  • 6 months later...
Posted

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?

  • 1 month later...
Posted

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

Posted

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

  • 4 months later...
Posted

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>

Posted

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

Posted

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

Posted

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

Posted

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
  • 3 months later...
Posted

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

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