Jump to content

Recommended Posts

Hi all,

 

I have made so far a login and action what to do... Maybe i'm to tired to see what i have to do.. I have stuck on 3th script where it have to say "Welcome, $Username"

 

Login_Screen.php

<html>

<head>
<style type="text/css"> 
body 
{ 
margin: 0; 
padding: 0; 
padding-top: 10px;
text-align: center; 
} 
#centered1
{ 
width: 800px; /* set to desired width in px or percent */
text-align: Center; /* optionally you could use "justified" */
border: 0px; /* Changing this value will add lines around the centered area */
padding-top: 90px;  
margin: 0 auto; 
} 
#centered2
{ 
width: 800px; /* set to desired width in px or percent */
text-align: Center; /* optionally you could use "justified" */
border: 0px; /* Changing this value will add lines around the centered area */
padding-top: 0px;  
margin: 0 auto; 
} 
</style>


<title><?php echo "Prijava_Korisnika";?></title>

<div id="Centered1">
<?php
Setlocale(LC_ALL, 'hr_HR');
$Datum = strftime("%d %B, %Y");
echo "Danas je ",$Datum, " 
<br> Ulogirajte se kako bi započeli sa radom";
$loc_cro = setlocale(LC_ALL, 'cro_Cro@euro', 'cro_Cro', 'hr', 'cro');
?>
</div>
</head>

   <body>
   <div id="Centered2">
  <h1>Login</h1> 
<FORM NAME ="LoginPanel" METHOD ="pOST" ACTION = "checklogin.php">
<p><INPUT TYPE = "Text" VALUE ="Korisničko Ime" NAME = "Korisnik"><p>
<p><INPUT TYPE = "Password" VALUE ="Lozinka" NAME = "Lozinka"><p>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Ulaz">
</FORM>	
<div>
    </body>
    
</html>

 

checklogin.php

<?php
// Podaci za login i spajanje na tablicu koja me zanuma
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$Baza="test"; // Database name
$tablica="members"; // Table name


// Spajanje na server koristeći gornje verijable i odabir baze i tablice
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$Baza")or die("cannot select DB");

// Definiramo Korisnika i njegovu lozinku
$Korisnik=$_POST['Korisnik'];
$Lozinka=$_POST['Lozinka'];

// Zaštita MySQL injection
$myusername = stripslashes($Korisnik);
$mypassword = stripslashes($Lozinka);
$myusername = mysql_real_escape_string($Korisnik);
$mypassword = mysql_real_escape_string($Lozinka);

// Spajanje na tablicu i potraga za korisničkim imenom i lozonkom  
$sql="SELECT * FROM $tablica WHERE username='$Korisnik' and password='$Lozinka'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);


//Ako pronađe barem jedan rezultat koji odgovara opisu 
if($count==1){

// registriraj ga i preusmjeri na "login_success.php"
session_register("$Korisnik");
session_register("$Lozinka");
header("location:login_success.php");
}
else {
echo "Krivo Korisničko ime ili lozinka, pokušajte ponovo";
}

ob_end_flush();
?>

 

 

login_success.php

Here i have to add Username of pearson that has logged in.. anbody

<html>
<body>

Dobrodošao, <?php
?>
</body>
</html>

 

Tnx in advance,

Link to comment
https://forums.phpfreaks.com/topic/244801-get-username/
Share on other sites

missing session_start(); at the top of checklogin.php.

 

Will also need it at the top of login_success.php, Then you can...

if(isset($_SESSION['username'])) { echo "welcome ".$_SESSION['username']; }

 

also with checklogin.php you want to assign the username from the database into a session variable called 'username', instead of assigning the same name for the key and the value. You won't know what to check then! Also don't assign the password to a session variable. That's a big security issue.

Link to comment
https://forums.phpfreaks.com/topic/244801-get-username/#findComment-1257462
Share on other sites

Yeah i try this in checkLogin.php

 

If Ihave understand well. I have to encrypt password from inputbox and then in sql query i tell him to compare encrypted password from password box with password in database... That didn't work.

 

Should i even bother with pass encryption??

 

$encrypt = crypt('$Lozinka');

// Spajanje na tablicu i potraga za korisničkim imenom i lozonkom  
$sql="SELECT * FROM $tablica WHERE username='$Korisnik' and password='$encrypt'";
$result=mysql_query($sql);

Link to comment
https://forums.phpfreaks.com/topic/244801-get-username/#findComment-1257657
Share on other sites

Don't EVER store passwords unencrypted.. Consider using MD5 or SHA1 to encrypt the password when they register and when they login, use the same encryption method to check if it matches the database encrypted pass. It's also good to use a dynamic (something different for each user) string (maybe random string or possibly a timestamp??) and add that to their password to make it more secure.

 

SHA1 Example

// here you would query the database to get the users encrypted pass from database and store it in $encryptedPassFromDatabase
$pass = $encryptedPassFromDatabase;
$ecnryptedPass = sha1($pass);

 

SHA1 Example WITH SALT (random string added to pass for more security)

// here you would query the database to get the users encrypted pass AND random string from database and store it in $encryptedPassFromDatabase and $SALT
$pass = $encryptedPassFromDatabase.$SALT;
$ecnryptedPass = sha1($pass);

 

 

again just remember to use the same method of encryption when registering the user and when checking their login info

so if you add a SALT to the end of the pass when registering, remember to also put the SALT at the end when checking login, if you added the SALT before their password during registration, again when checking login remember to add the same SALT before their pass when checking login.

 

Best of luck :)

Link to comment
https://forums.phpfreaks.com/topic/244801-get-username/#findComment-1257773
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.