php login page

oI am new at php and need help to know what is wrong with this code below
[php]if(!session_is_registered(myusername))[/php]

as of PHP 5.4 the session_is_registered has been DEPRECIATED.

You may want to try if(!isset($_SESSION[‘myusername’]))

if(!$_SESSION[‘myusername’])

thank you the page is working!
can you help me with this code below
[php] session_register(“myusername”);[/php]

You might try posting the entire script, if an issue is occurring it might be elsewhere, more times then not you can get more help when all script is known.

Thanks here is the full script
[php]<?php

$host=“localhost”; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=“test”; // Database name
$tbl_name=“members”; // Table name

// Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// username and password sent from form
$myusername=$_POST[‘myusername’];
$mypassword=$_POST[‘mypassword’];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql=“SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword’”;
$result=mysql_query($sql);

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

// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){

// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(“myusername”);
session_register(“mypassword”);
header(“location:login_success.php”);
}
else {
echo “Wrong Username or Password”;
}
?>[/php]

dont use this
[php]
if(!session_is_registered(myusername))
[/php]

use this
[php]
if(!isset($_SESSION[‘myusername’]))
[/php]
or this
[php]
if(!$_SESSION[‘myusername’])
[/php]

please and let us know what worked

OMG! ima dork you need also this session_start();
so lets recap
[php]

<?php session_start(); $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result)){ $myusername = $row['username']; $_SESSION['username'] = $myusername; // Register $myusername, $mypassword and redirect to file "login_success.php" //session_register("myusername"); //session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?>

[/php]

is the way i do it
so try that

Thank you for your help, there is no error message now but when you login in you are not directed to the login success page can you check why for me

[php]

<?php session_start(); if(!$_SESSION['myusername']){ $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result)){ $myusername = $row['username']; $_SESSION['myusername'] = $myusername; // Register $myusername, $mypassword and redirect to file "login_success.php" //session_register("myusername"); //session_register("mypassword"); header("location:login_success.php"); }} else { //take to the login form //echo "Wrong Username or Password"; } ?>

[/php]

try it now i changed $_SESSION
to have the value of myusername instead of username

Ok I have made the changes but get an error for
[php]else { [/php]

did you put any code in it if not then take it off

Thank you for your help, I am trying to create a web login in page when I put in a username and password it does not direct to the login_success.php page. I am using 4 pages, main_login.php, checklogin.php, check.php and login_success.php, I will list the code below if you can have a look at it I will be happy

main_login.php
[php]

Member Login
Username :
Password :
   
[/php]

checklogin.php

[php]<?php
session_start();
$host=“localhost”; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=“test”; // Database name
$tbl_name=“members”; // Table name

// Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// username and password sent from form
$myusername=$_POST[‘myusername’];
$mypassword=$_POST[‘mypassword’];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql=“SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword’”;
$result=mysql_query($sql);

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

// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){

// Register $myusername, $mypassword and redirect to file “login_success.php”
//session-register(“myusername”);
//session_register(“mypassword”);

header(“location:login_success.php”);
}
else {
echo “Wrong Username or Password”;
}
?>[/php]

check.php
[php]<?php
session_start();
$host=“localhost”; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=“test”; // Database name
$tbl_name=“members”; // Table name

// Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// username and password sent from form
$myusername=$_POST[‘myusername’];
$mypassword=$_POST[‘mypassword’];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql=“SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword’”;
$result=mysql_query($sql);

while($row = mysql_fetch_array($result)){

$myusermame = $row[‘username’];
$_SESSION[‘myusername’] = $myusername

// Register $myusername, $mypassword and redirect to file “login_success.php”
//session_register(“myusername”);
//session_register(“mypassword”);
header(“location:login_success.php”);

else {
//take to the login form
//echo “Wrong Username or Password”;
}
?>[/php]

login_success.php
[php]<?php
session_start();
if(!$_SESSION[‘myusername’])
{
header(“location:login_success.php”);
}
?>[/php]

comment the else out

[php]
//else {
//take to the login form
//echo “Wrong Username or Password”;
//}
[/php]

getting a syntax error for this line[php]header(“location:login_success.php”); [/php]

is that all there is in the login__success.php

I have an entire script complete it is easy to use if you’d like to run it.

it has an admin center and all…

If your trying to write the script, please ignore this message…

If you have send me the entire script it would be great, I am trying to learn as well but can do that over time.Thanks

do you by chance use skype? if so i can send through there and walk you through he install… quite simple…

Thanks Yes I use skype name kevinwyndhamquin

Sponsor our Newsletter | Privacy Policy | Terms of Service