Zola Posted January 24, 2012 Share Posted January 24, 2012 Hi, I am having difficulties with the login section on a website. I have tried to update the old funtion names which have been deprecated, but when I do this the login will not work. This is the log.php file, (this is required by index.php on the restricted directory to access the page). <?php session_start(); ?> <?php $hostname = ".."; $username = ".."; $password = ".."; $database = ".."; $link = MYSQL_CONNECT($hostname,$username,$password); mysql_select_db($database); ?> <?php if($_GET['action'] == "login") { $conn = mysql_connect("..","..","..); $db = mysql_select_db(".."); //Your database name goes in this field. $name = $_POST['user']; $ip=$_SERVER['REMOTE_ADDR']; $var = mysql_real_escape_string($var); $country = file_get_contents('http://stonito.com/script/geoip/?ip='.$ip); $q_user = mysql_query("SELECT * FROM customer WHERE username='$name'"); ?> <?php $insert_query = ("INSERT INTO login(username, ip, country) VALUES ('$name','$ip','$country');"); mysql_query($insert_query) or die('Error, insert query failed'); ?> <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { session_register("name"); header("Location: ../index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: .."); exit; } } else { header("Location: .."); exit; } } // if the session is not registered if(session_is_registered("name") == false) { header("Location: login.php"); } ?> The two old code parts. causing the problems are session_register("name"); session_is_registered . When I change update elements in the code block shown below, it will not work. Can anyone tell me why please? <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { $_SESSION['name']; header("Location: ../download/index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: .."); exit; } } else { header("Location: .."); exit; } } if(!isset($_SESSION['name'])) { header("Location: http://www.myurl.com"); } Any help would be very gratefully received. Link to comment https://forums.phpfreaks.com/topic/255665-why-does-this-only-work-with-deprecated-code-please-help/ Share on other sites More sharing options...
trq Posted January 24, 2012 Share Posted January 24, 2012 You never actually set $_SESSION['name'] to anything. Link to comment https://forums.phpfreaks.com/topic/255665-why-does-this-only-work-with-deprecated-code-please-help/#findComment-1310582 Share on other sites More sharing options...
Zola Posted January 24, 2012 Author Share Posted January 24, 2012 I thought that session_register("name"); and $_SESSION['name']; would be the same thing? I am new with PHP, please bear with me. What would I need to change it to? Link to comment https://forums.phpfreaks.com/topic/255665-why-does-this-only-work-with-deprecated-code-please-help/#findComment-1310588 Share on other sites More sharing options...
Zola Posted January 24, 2012 Author Share Posted January 24, 2012 I updated it to this: $_SESSION['name'] = true; It now works. Thanks Link to comment https://forums.phpfreaks.com/topic/255665-why-does-this-only-work-with-deprecated-code-please-help/#findComment-1310590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.