Jump to content

Why does this only work with deprecated code? Please help


Zola

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.