Newbie question: Login in Moodle from distant html form

Newbie question: Login in Moodle from distant html form

by Chris St-Pierre -
Number of replies: 3

Hi there,

I'm putting together a PHP site. I would like to add a simple HTML form that would allow my visitors to log directly into moodle hosted on a different server. Here is what I picked up from the current login page:

   <form action="http://myhost/moodle/index.php" method="post" name="form" id="form">
     <input type="text" name="username" size="15" value="" />
     <input type="password" name="password" size="15" value="" /> 
     <input type="submit" name="Submit" value="Connexion" />
    </form>

It does not work. There is probably another <INPUT> I'm missing to succesfully connect. Sounds simple but I can't make it work...

Could anybody please give me a hint? My site is in PHP so I can get Session Id, etc.

Thanks!

 

Chris

 

 

Average of ratings: -
In reply to Chris St-Pierre

Re: Newbie question: Login in Moodle from distant html form

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In Moodle 1.0.9, make sure "secureforms" is turned OFF in the admin's configuration page.
In reply to Martin Dougiamas

Re: Newbie question: Login in Moodle from distant html form

by Chris St-Pierre -

Thanks Martin,

I still always come back to http://myhost/login/index.php  as if there was something missing with the form. Since I have chosen to use only the course key as authentification, I wish simply to go straight to say: http://myhost/course/enrol.php?id=2 WITHOUT having to stop by /login/index first... I figured it would have been easy to logon as "guest"...

Is there a way for me to formulate a simple URL that would have me go to straight to http://myhost/course/enrol.php?id=2 by clicking on a web link from another web site? I really tried to go around the different scripts but still, I'm fairly new to php...

Thanks for your time!

 

Chris

In reply to Chris St-Pierre

Re: Newbie question: Login in Moodle from distant html form

by Chris St-Pierre -

Found it!

When you submit the form from a distant html page, $SESSION->wantsurl is empty when processed by login/index.php .

  <form action="http://myhost/login/index.php" method="post" name="form" id="form">
     <input type="text" name="username" >
     <input type="password" name="password"> 
     <input type="submit" name="Submit" value="Connexion" />
    </form>

Since you can find the following code in login/index.php:

...

     } else if (empty($SESSION->wantsurl)) {
                redirect($CFG->wwwroot);

...

it caused my attemp to submit my form to login/index.php to redirect  straight to index.php

To solve the problem:

1) With a decent php script  (Postnuke block) I generate an extra dynamic hidden <input> in the form that would submit  the desired url with value="../course/enrol.php?id=..."  I use $url

2) In login/index.php I altered the code a little:

...else if (empty($SESSION->wantsurl)) {
      if (empty(frm->$url)){
          redirect($CFG->wwwroot);
 }    else redirect(frm->$url);
}

For me it works wonderfully and does not change anything if someone decides to use the conventionnal login process.

Hope this might help one day!!!