Skip Navigation

[Resolved] Auto login with passed values

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by salimA 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1971963

Hi

I have a user form where users can register on it. but the username and password passed through the session he should not enter it manually. when the user completes the registration, it will login and redirect him to his profile. (this part is completed)

If the user is already registered wants to access again, the system should pass the credentials from the session and login then redirect him directly to his profile. I have used the below code in the PHP snippet plugin and insert it on the profile page, but it redirects without login. what is wrong?

briefly ( we want an already registered user to login when he accesses his profile page and the username and password coming from the session)

<?php
/**
* New custom code snippet (replace this with snippet description).
*/
session_start();
toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

// Automatic login //

// Automatic login //
$username = $_SESSION['i'];
$user = get_user_by('login', $username );

// Redirect URL //
if ( !is_wp_error( $user ) )
{
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );

$redirect_to = "hidden link..../sarh-profile/";
wp_safe_redirect( $redirect_to );
exit();
}

#1972659

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Salim,

Thank you for getting in touch.

For clarity can you explain in a bit more detail the comment below.


If the user is already registered wants to access again, the system should pass the credentials from the session and login then redirect him directly to his profile. I have used the below code in the PHP snippet plugin and insert it on the profile page, but it redirects without login. what is wrong?

Is it that when the user logs in you want them to get redirected to their profile page? Is the profile page set to display the login form if the user isn't logged in ?

Finally what is the code that you are using for the login form.

Thanks,
Shane

#1973135

Hi Shane

thank you for your reply.

I mean I want to allow the user to auto-login when he accesses a specific page.

I found this code that solves it for me. hidden link