Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Fatal error: Call to undefined function session_register()

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Fatal error: Call to undefined function session_register()

Postby dekon » Tue Dec 04, 2012 7:18 am

hi i am new to php and keep getting this error can someone bplease help me
Code: Select all
<?php

include('mysql.php');
mysql_connect("$host", "$user", "$passwd");
mysql_select_db("mdb_sn027");

$myusername=$_POST['usename'];
$mypassword=$_POST['pass'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM user WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword,table is 1 row
if($count==1){

session_register("myusername");
session_register("mypassword");
header("location:imageshow.php");
}
else {
echo "Wrong Username or Password";
}
?>
dekon
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Dec 04, 2012 7:15 am

Re: Fatal error: Call to undefined function session_register

Postby simplypixie » Tue Dec 04, 2012 9:40 am

It is because the function can't be found and if your server is using a higher version of PHP then that is why:

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0 (read here).

Therefore you need to change your code to this (I have removed the storage of the password in a session as I can't think of anything less secure - there is just no need to do so and is totally unsafe):
Code: Select all
<?php
session_start();
include('mysql.php');
.
.
.
.
.

// If result matched $myusername and $mypassword,table is 1 row
if($count==1){

$_SESSION['myusername'] = $myusername;
header("location:imageshow.php");
}
else {
echo "Wrong Username or Password";
}
?>


Make sure you have session_start(): at the very top of every page where you want to use / check your session data.
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Fatal error: Call to undefined function session_register

Postby Barrikor » Tue Dec 04, 2012 3:14 pm

The concept behind using session_register() for loading arrays into the session was fine, but the function was tied to register_globals under the hood... (register_globals was a huge mistake in PHP's development that has since been eliminated from the language)

Try using $_SESSION, like Simplypixie posted.
User avatar
Barrikor
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.