We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,668 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

php fatar error ,please help

Fatal error: Call to undefined function session_register() in C:\xampp\htdocs\4\admin\checklogin.php on line 33

<?php
error_reporting(0);
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="phplogin"; // 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 
$username=$_POST['username']; 
$password=$_POST['password']; 


// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$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("username");
session_register("password"); 
header("location:index.php");
}
else {
echo ( " <script language='JavaScript'>  
             if(confirm('Error logging in: The Username & Password does not match.'))
             window.location = 'login.php';
        </script>
      ");
}
?>
4
Contributors
5
Replies
1 Week
Discussion Span
7 Months Ago
Last Updated
8
Views
shhh
Light Poster
36 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@godslove

Fatal error: Call to undefined function session_register() in C:\xampp\htdocs\4\admin\checklogin.php on line 33

You can't used session_register() because it's outdated

Read this:

http://php.net/manual/en/function.session-register.php

If you are using PHP 5.4.0 then this function is no longer available.

Please update to PHP 5.4.7

If you want still want to used that

Then do this : $_SESSION['username'] = '$username';

My advice right now learn the current code because you will get alot of errors later on and it's getting harder for you to make the code work.

LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 349
Skill Endorsements: 47

@LastMitch

Thank you, thank you, thank you!

Am currently testing Ubuntu 12.10 as my new develop environment. I found some on advice online suggesting one check logs with this particular error (cat /var/log/apache2/error.log). Accordingly; I searched on the PHP Fatal error found in these logs & ended up here. I guess it is to be expected that certain functions etc get deprecated with time, but it can be a hassle finding out the hard way! Once again thanks!

phlinuks
Newbie Poster
2 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Before assigning any session variables like $_SESSION['username'] = ...
ensure that you have session_start(); at the top of every page.

diafol
Keep Smiling
Moderator
10,826 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,532
Skill Endorsements: 61

@diafol

I'm not sure if you are replying to me, but if you are firstly, thank you and rest assured I have session_start(); at the top of pages where required. My problem was just getting caught out by the deprecation of session_register();. Everthing is cool now.

phlinuks
Newbie Poster
2 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Sure, no problem. As it wasn't in your original code, I thought I'd add it 'just in case'.

Everthing is cool now.

:)

diafol
Keep Smiling
Moderator
10,826 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,532
Skill Endorsements: 61

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0700 seconds using 2.69MB