Skip navigation links

MySQL Forums :: PHP :: Creating Function to Register Session (user variables)


Advanced Search

Creating Function to Register Session (user variables)
Posted by: Intellect Research ()
Date: June 26, 2013 03:00AM

Please, the script below works but hbangs at the session_register("myusername") line, because the example script didn't include session_register() function. Please, how can I create one to work with this scripts. Other associated .php files are working ok. Thanks.

<?php

ob_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");


// Define $myusername and $mypassword
$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";
}

ob_end_flush();
?>

Options: ReplyQuote


Subject Written By Posted
Creating Function to Register Session (user variables) Intellect Research 06/26/2013 03:00AM
Re: Creating Function to Register Session (user variables) Barry Galbraith 06/27/2013 10:01PM
Re: Creating Function to Register Session (user variables) Intellect Research 07/04/2013 06:10AM
Re: Creating Function to Register Session (user variables) Peter Brawley 07/18/2013 03:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.