hi,
i developped a test application with quiz module.
I need now that my website visitors could take the quiz with them login parameters already have been used to login into the website.
I think when creationg users, i have to lunch an insert request into users table ans users_roles tables in my drupal database, but i dont know how to open session with tis user without login with drupal login page.
thank you in advance
sanachr

Comments

vijaythummar’s picture

You can write function something like

<?php
                  $form_state['uid'] = $uid;
                  user_login_submit(array(), $form_state);

?>

May this will help you.

Thanks,
Vijay Thummar

sanachr’s picture

thank you for your answer,
where may I insert this code please??
Sanachr

sanachr’s picture

have some one any explanation...
I need to start session without login button (from other website)
thank you

vijaythummar’s picture

What is your thoughts/requirement to login user? What are user's actions?

Can you please specify user's steps?

Thanks,
Vijay Thummar

sanachr’s picture

thank you for your post;
I have developed a quiz with drupal: http://tanitechnologies.tn/gmat/user/login
the test is accessible for anonimous users also: http://www.tanitechnologies.tn/gmat/node/29/take
(i have to save data for such user with his email adress that's why i look for using authentificated user)
and i have my website, already developed with a simple html/php code and this is my login page:
http://www.mbacentereurope.eu/register-sign-in.php
Now i want that users of my website, could be logged into mydrupal application (quiz) when they sign into my website, and not have to log in again.
so, the button "sign in" in the page mentioned (http://www.mbacentereurope.eu/register-sign-in.php) has to access to my drupal app and open session with given parameters.
for registration, i think that i have to add a query that insert users on my drupal database, so that when logging website user would be found in mydrupal users table.
i can give more details if you want
thank you a lot for your help
Sanachr

vijaythummar’s picture

Would you mind if your users redirect to Drupal website for login and come back to your website again?

Thanks,
Vijay Thummar

sanachr’s picture

yes, but i want that it would be hidden, i hope that users dont realize the redirection to drupal website and the log in action
but when they want to pass test(there is a link in the website homepage), they find that they are already logged in

sanachr’s picture

you find here links for tests:
http://mbacentereurope.eu/at/gmat.html

in the middel of page: start micro test, start mini test, start full test

vijaythummar’s picture

There are three solutions:

1) Integrate any single sign on extension

2) Redirection with signature based authentication
Steps:
- Users login into your website
- On successful login, create one encrypted signature and redirect user to Drupal website with encrypted signature and email address (www.drupal-site.com/custom_login?email=user_email_address&signature=”encrypted_signature”&back_url = “your_Website_url”
- In Drupal website, Create custom url (www.drupal-site.com/custom_login) in Drupal website
- Create signature in Drupal and match signature with your other site’s signature
- If signature match, create user in Drupal if not exists or get the User_id by email address
- Write

$form_state['uid'] = $uid;
user_login_submit(array(), $form_state);

- and redirect user to back url with header function

3) jQuery solution
Write something like below code in login successfully page of your website

<script type="text/javascript">
                  jQuery(document).ready(function() {
                    var url="http://www.drupal-site.com/custom_login?email=user_email_address&signature=”encrypted_signature”&back_url = “your_Website_url”;
                      jQuery.ajax({
                        url: url,
                        type: 'POST',
                        //data: { userid: userid},
                        crossDomain: true,
                        dataType: 'jsonp',
                        success: function(data) {
                          // alert('success');
                        }
                      });

                  });
                </script>

- but make sure it run only once.

Hope this will help you.

Thanks,
Vijay Thummar

sanachr’s picture

for the third one,
i have to create custom_login page in my drupal test app,
what code should i integrate on it??
i have to insert this code in the login page on my website??
thank you
Sanachr

vijaythummar’s picture

Yes write the code as per case-2 for the third option too because login into Drupal will be same for both scenarios.

you have to write java script code in your login post page.

Thanks,
Vijay Thummar

sanachr’s picture

i have created this page:

<?php
$email=$_GET['email'];

// Connexion au serveur
$connect =mysql_connect('localhost','tanitechnologies','xxxx') or die ("erreur de connexion");
mysql_select_db('tanitech_gmat') or die("erreur de connexion a la base de donnees");
$query1 = "SELECT * FROM `users` WHERE `mail`='".$email."'";

$result1 = mysql_query($query1) or die("erreur de requete");
// Recuperation des resultats
while($row = mysql_fetch_row($result1)){

$uid=$row[0];

}

$form_state['uid'] = $uid;
user_login_submit(array(), $form_state);
 header('Location: http://www.mbacentereurope.eu');
?>

but when i refresh my drupal app, i m not logged in

sanachr’s picture

you can try with:
http://tanitechnologies.tn/gmat/test.php?email=sana.chroudi@yahoo.fr
there is a user in my app which has this email adress, and with id=7

vijaythummar’s picture

What you have written is custom PHP code which will not work in Drupal. You have to write your code in Drupal module.

Create custom module in Drupal, write hook_menu with custom URL and in that function write user login code.

You will get lots of help on forums about how to write custom module in Drupal.

Thanks,
Vijay Thummar

sanachr’s picture

thanks a lot :)