1

I want to redirect a user to a folder named by his/her phone number(the folder created when the user signed up) and here is a part of my code:

if (count($errors) == 0) {
    $password = md5($password);
    $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $results = mysqli_query($db, $query);




if (mysqli_num_rows($results) == 1) {
        $row=mysql_fetch_assoc($results);
        $folder = $row['phone'];
        $_SESSION['username'] = $username;
        $_SESSION['success'] = "You are now logged in";
        header("location:$folder"."/index.php");

It redirects the users to /index.php

johnny 5
  • 19,893
  • 50
  • 121
  • 195
  • what is the value of `$folder`? Is it the phone number? Just fyi, you could clean it up a bit as `header("Location: $folder/index.php");` and you might do a check that it isn't null or empty. – dmgig May 22 '18 at 14:25
  • ALWAYS secure your sql queries against injection – rak007 May 22 '18 at 14:28
  • Some things are just plain wrong with this code.. 1) Using MD5 2) Prone to SQL injections and this really needs to be solved before you go live this this code.. http://php.net/manual/en/faq.passwords.php and https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php... `header("location:$folder"."/index.php");` also looks suspect to allow HTTP header injection well the newer PHP versions (i believe PHP 5.1.2+) protect against this all types of this attack. – Raymond Nijland May 22 '18 at 14:29

0 Answers0