Page 1 of 1

How to make a custom server page for smart fox bits

Posted: 06 Jul 2012, 17:12
by Sfulk
There is really no documentation on how to create a custom server page for access validation, so I have no idea how to do it. The only thing I could find on it was on the Smartfoxbits documentation:

customLoginPage
public customLoginPage:String
(read,write)

The custom server-side page url for access credentials validation.
If this property is set, before attempting the SmartFoxServer login, the LoginBox will send the entered username and password to the provided url for validation.
Two parameters are passed to the custom server-side page via POST: name (the entered username) and pass (the entered password). The page must return res=OK if the credentials are valid or res=KO if the credentials are invalid.
Example:

To set the server-side page for custom login in MXML:

<sfb:LoginBox customLoginPage="http://localhost/sfsLogin.php" />

To set the server-side page for custom login in ActionScript:

loginBox.customLoginPage = "http://localhost/sfsLogin.php"

Component metadata:

Bindable
"customURLChanged"
Inspectable
category:
"General"
defaultValue:
""
name:
"Custom server page for access validation"

Re: How to make a custom server page for smart fox bits

Posted: 06 Jul 2012, 19:57
by rjgtav
Hi.

If I'm understanding it right, that custom page for access validation is a regular PHP file which checks the credentials received from the flash client as POST and then, after checking these credentials against a database, returns a res=OK in case the credentials were correct or a res=KO if they were wrong.
You can find lots of examples using PHP for checking credentials against a database on the web.

You can also check this chapter of the SmartFoxServer1X documentation, which has a simple example of how to create a PHP file which returns a res=OK or res=KO (it doesn't include database integration)

Re: How to make a custom server page for smart fox bits

Posted: 07 Jul 2012, 23:50
by Sfulk
Thanks for the help.

Re: How to make a custom server page for smart fox bits

Posted: 08 Jul 2012, 00:18
by Sfulk
Do you know why the php script from the documentation wont work with the avatar chat example from smartfoxserver 2x. I looked through the code and don't see any reason why its not working correctly with Avatarchat. Its saying that the login credentials are invalid, when they are indeed valid.

Code: Select all

<?php
    // A Simple List of allowed users
    // You could substitute this code with a database connection
    $allowedUsers =  array ("Admin" => "test",
                            "test" => "test",
                            "Moderator" => "test");
   
    // The response variable
    $res = "res=KO";


    // Check incoming data
    if ($_POST['name'] != "" && $_POST['pass'] != "")

    {
        foreach($allowedUsers as $name => $password)
        {
            if ($_POST['name'] == $name && $_POST['pass'] == $password)

            {
                // Ok, user found
                $res = "res=OK";
                break;
            }
        }
    }
   
    print $res;
?>

Re: How to make a custom server page for smart fox bits

Posted: 08 Jul 2012, 11:40
by rjgtav
I never actually tried the PHP file which is in the documentation page... If you return always res=OK, does it actually work correctly on the client side?

Re: How to make a custom server page for smart fox bits

Posted: 08 Jul 2012, 15:42
by Sfulk
I tried setting it so that either way so if the login credentials are wrong or right it should still allow me access. It still says login Credentials are invalid, I dont understand why. :x

Re: How to make a custom server page for smart fox bits

Posted: 08 Jul 2012, 19:07
by rjgtav
Please post the PHP code you're using

Re: How to make a custom server page for smart fox bits

Posted: 08 Jul 2012, 21:19
by Sfulk

Code: Select all

<?php
    // A Simple List of allowed users
    // You could substitute this code with a database connection
    $allowedUsers =  array ("Admin" => "test",
                            "test" => "test",
                            "Moderator" => "test");
   
    // The response variable
    $res = "res=KO";


    // Check incoming data
    if ($_POST['name'] != "" && $_POST['pass'] != "")

    {
        foreach($allowedUsers as $name => $password)
        {
            if ($_POST['name'] = $name && $_POST['pass'] = $password)

            {
                // Ok, user found
                $res = "res=OK";
                break;
            }
        }
    }
   
    print $res;
?>


I changed the one that says $res = "res=KO" I tried changing to OK so that way even if the login credentials didnt match the ones in the array it should still let me in but it wont.

Re: How to make a custom server page for smart fox bits

Posted: 12 Jul 2012, 07:45
by Bax
Have you tried calling your php page from a browser instead of the Flash client? It should simply display res=OK. If not, then something is wrong with your code.
As a side note, we really don't recommend the "server side page" approach to access validation.
It would be much better to use a SFS Extension and a custom login procedure as described in the documentation.

Re: How to make a custom server page for smart fox bits

Posted: 12 Jul 2012, 23:04
by Sfulk
Bax wrote:Have you tried calling your php page from a browser instead of the Flash client? It should simply display res=OK. If not, then something is wrong with your code.
As a side note, we really don't recommend the "server side page" approach to access validation.
It would be much better to use a SFS Extension and a custom login procedure as described in the documentation.


Yes, I tried calling the php file from a browser it displayed res=OK. I still did not have any luck so I ended up figuring out how to use a SFS extension and custom login last night. The smart fox server 2x documentation is a little too vague in some areas, but may I ask why no one here recommends using the custom server page for login?

Re: How to make a custom server page for smart fox bits

Posted: 13 Jul 2012, 10:23
by Bax
Sfulk wrote:may I ask why no one here recommends using the custom server page for login?

Why using an external system, which requires you to setup a specific php web page on a separate server, when you can do everything (an much more securely) inside SFS? Also take into account that often a login system also returns other data to the application. With the internal approach you can retrieve any data from your database and transmit it to the client.