I have this HTML / PHP form / login.
Yes, I know it is incomplete, but as far as I can tell, the rest is unimportant.
Then I have this B4A code.
Yes, the URL address is removed, sorry, I cannot share the working website link.
As you can see, I tried 4 different versions, none of the working.
PHP should return Failure or Success.
But, tries 1, 2 and 4 return the entire HTML page.
Try 3 returns stream was reset, protocol error.
Any ideea would be great. Thank you.
Yes, I know it is incomplete, but as far as I can tell, the rest is unimportant.
PHP:
..........................................................................
elseif($_SERVER["REQUEST_METHOD"] == "POST") {
$error = false;
$authenticated = 'failed';
$username = test_input(strtolower($_POST["username"]));
$password = test_input($_POST["password"]);
foreach ($validUsernames as $key=>$value) {
if ($value == $username && $validPasswords[$key] == $password) {
$authenticated = 'valid';
break;
}
..........................................................................
<?php if ($error === true) { ?>
<div class="alert alert-danger" role="alert">
Failure
</div>
<?php } ?>
<?php if ($error === false) { ?>
<div class="alert alert-success" role="alert">
Success
</div>
<?php } ?>
..........................................................................
<form class="form-signin" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<img class="mb-4" src="mqtticon.png" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal">Sign in</h1>
<?php if ($error === true) { ?>
<div class="alert alert-danger" role="alert">
Failure
</div>
<?php } ?>
<?php if ($error === false) { ?>
<div class="alert alert-success" role="alert">
Success
</div>
<?php } ?>
<?php if ($error !== true && $error !== false) { ?>
<label for="inputUsername" class="sr-only">Username</label>
<input type="username" name="username" value="<?php echo $username;?>" id="inputUsername" class="form-control" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" value="<?php echo $password;?>" id="inputPassword" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
<p class="mt-5 mb-3 text-muted">© 2019</p>
<?php } ?>
</form>
..........................................................................
Then I have this B4A code.
Yes, the URL address is removed, sorry, I cannot share the working website link.
B4X:
#Region Project Attributes
#ApplicationLabel: AAA Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim j As HttpJob
j.Initialize("j", Me)
Dim values As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
'xui.MsgboxAsync("Hello world!", "B4X")
''''''''''''''''''''''' try 1
values.Initialize
values.Put("username","user")
values.Put("password","pass")
'j.PostMultipart("https://xxxxxxxxxxxxxxxx/index.php",values,Null)
''''''''''''''''''''''' try 2
'j.Username = "xxx"
'j.Password = "xxx"
'j.PostString("https://xxxxxxxxxxxxxxxx/index.php", "")
''''''''''''''''''''''' try 3
Dim userPwd As String = "user:password"
Dim su As StringUtils
Dim byt() As Byte = userPwd.GetBytes("UTF8")
Dim suUserPwd As String = su.EncodeBase64(byt)
j.Download("https://xxxxxxxxxxxxxxxx/index.php")
j.GetRequest.SetHeader("Authorization:","Basic "&suUserPwd)
''''''''''''''''''''''' try 4
'j.Download2("https://xxxxxxxxxxxxxxxx/index.php", Array As String("username","xxx","password","xxxx"))
wait for (j) JobDone(job As HttpJob)
If job.Success Then
Dim response As String = job.GetString
Log(response)
xui.MsgboxAsync(response, "PHP response")
Else
Log(job.ErrorMessage)
xui.MsgboxAsync(job.ErrorMessage, "PHP error")
End If
End Sub
As you can see, I tried 4 different versions, none of the working.
PHP should return Failure or Success.
But, tries 1, 2 and 4 return the entire HTML page.
Try 3 returns stream was reset, protocol error.
Any ideea would be great. Thank you.