Basic Login w/ PHP 05-18-2013, 02:45 AM
#1
Hey there SL, today I'm going to show you how to make a super basic login system using PHP. First of all, open a new form and add: 3 Labels, 2 Textbox's and 1 button to your form. It should look like this:
![[Image: etAC.png]](http://snaplr.net/i/etAC.png)
Next, you want to double click on the button and paste this code which I will explain. Above Public Class Form1 you want to put:
After you do that, paste this code under the button click event.
Next edit where it says "yourwebsite.com/" to the url of your website. You are done with the visual basic portion now!
Alright, now we start the PHP section.
Paste that in to a new file and save it as login.php, upload it to the website you set in the visual basic app.
I have explained each line in the PHP code if you don't know what your doing.
Now all thats left to do is run your app and enter in the username and password, if you did it all right you should see this:
![[Image: c4ll.png]](http://snaplr.net/i/c4ll.png)
If you did something wrong you will see this:
![[Image: nqh9.png]](http://snaplr.net/i/nqh9.png)
If you have any questions feel free to ask!
![[Image: etAC.png]](http://snaplr.net/i/etAC.png)
Next, you want to double click on the button and paste this code which I will explain. Above Public Class Form1 you want to put:
Code:
Imports System.Net
Code:
Dim url As String = "http://www.yourwebsite.com/" 'This is the baseURL for your website. Remember to leave the slash!
Dim wc As New WebClient
Dim result As String = wc.DownloadString(url & "login.php?username=" & TextBox1.Text & "&password=" & TextBox2.Text) 'This will download the results of the page from your PHP file checking the username and password you have just submitted to the server.
If result = "1" Then 'If its right
MsgBox("You have succesfully logged in!", MsgBoxStyle.Information)
Label3.Text = "Status.... logged in!"
Else 'If its wrong
MsgBox("An error has occured, please try again!", MsgBoxStyle.Critical)
Label3.Text = "Status.... error occured!"
End If
Next edit where it says "yourwebsite.com/" to the url of your website. You are done with the visual basic portion now!
Alright, now we start the PHP section.
Code:
<?php
$username = $_GET['username']; //Set the username
$password = $_GET['password']; //Set the password
if($username == "admin" && $password == "test") { //This line will check and see if the username and password you submitted are correct
echo "1"; //If correct display 1
} else {
echo "2"; //Else display 2
}
?>
I have explained each line in the PHP code if you don't know what your doing.
Now all thats left to do is run your app and enter in the username and password, if you did it all right you should see this:
![[Image: c4ll.png]](http://snaplr.net/i/c4ll.png)
If you did something wrong you will see this:
![[Image: nqh9.png]](http://snaplr.net/i/nqh9.png)
If you have any questions feel free to ask!
![[Image: GiXvY27.png]](http://i.imgur.com/GiXvY27.png)