Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Your own Mysql/Php/Swish Username/Password script

software


Your own Mysql/Php/Swish Username/Password script





Part I: Swishmax

Hey guys,

First you will need two textboxes, with the VARIABLE names of user and pass(I always keep the names relevant, to help remember)

Second, I made a little submit button, with only an onpress gotoandplay(13)
(Actually, I used a label)
Actual code:



Code:

on (release,keyPress("<Enter>"))




Now we will start with the code for the label and login, and then go from there.

Code:

onFrame (13)
onFrame (19) else if (login == 'fals 555c219f e')
}



Line 1: Do this on frame 13(Kinda self explanatory)
2: Set label for my submit button, I use labels to keep things organized
3: I am using loadvariable for a SPRITE, so make sure you group everything as a sprite
4: Close tag
5: On frame 19, The reason I have the delay in here is it takes a little while for php to run through the code and give us back the response, so give it a few frames.
6: You will understand this once we get to php, because the php sends us back a variable &login and then we check that variable.
7: On nothing I have removed what I don't want if the login correctly
8: The reason I do this is because I want to be able to reference the variable user later, to show them their username(You would reference by using _root.user)
9: What? Php says you logged in wrong.
10: This is another textfield with the variable name of 'res', I use this to display the message try again. You can also go to a different frame, anything you want here.

You can include this code in any swishmax file you want. As long as your php file is in the same place, it will work in any swishmax file


Part II: Php

To start things off, you will need a simple mysql table in your database with the fields Username and PASSWORD. These are how they are referenced in this code. Also, the table's name will be login in this example

To create this database:

Code:

CREATE TABLE `login` (
  `Username` varchar(255) default NULL,
  `PASSWORD` varchar(255) default NULL
) TYPE=MyISAM;



Now we can FINALLY get to our php

Code first, explain later (The name is login.php)

Code:

<?php
/*
If you have read the other tutorials, you understand the post, you understand also the connecting to the mysql database, so I will explain the login check only
*/
$user = $_POST['user'];
$pass = $_POST['pass'];
  $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dsistu48_forum");

//Regular Login Check, No admin or Banned

$query = "SELECT Username, PASSWORD FROM login WHERE Username = '$user' AND PASSWORD = '$pass' AND position = 'Member'"; //Select the correct row for the username
$rows = mysql_query($query) or die ("You has an Error in login.php; $query.". mysql_error()); //Query the db
$numrows = mysql_numrows($rows);
if($numrows > 0) else
//BELOW CODE IS OPTIONAL
$result = @mysql_query("SELECT Username FROM login WHERE Username='$user'");
  while ( $row = mysql_fetch_array($result))
?>




Ok guys, I will explain only the lines I said before(In my comment about understanding other tutorials..

$query = "SELECT Username, PASSWORD FROM login WHERE Username = '$user' AND PASSWORD = '$pass' AND position = 'Member'";
$rows = mysql_query($query) or die ("You has an Error in login.php; $query.". mysql_error()); //Query the db
$numrows = mysql_numrows($rows);

Here we check for the entry. First, you see the mysql_query, which gets the info from the database. The main thing here is mysql_numrows. This returns the number of rows I get from the database. If there would be a matching username and password, then it would return a 1, otherwise, it would be 0



if($numrows > 0) else
If we don't get any rows back, then we tell swish the password and username is wrong.


THE CODE BELOW IS OPTIONAL
$result = @mysql_query("SELECT Username FROM login WHERE Username='$user'");
while ( $row = mysql_fetch_array($result))

Here we are getting the information from that row. Since I have _root.user = user, this is what that is for. Say you wanted to know the username for later use, like a welcome message? That is where this comes in at.


Document Info


Accesari: 1593
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )