Why this code doesn't redirect to profile page? i need help..

<?php
    include('connectvars.php');

    if(isset($_POST['login']))
    {
        $con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);

        $user_username = mysqli_real_escape_string($con,trim($_POST['username']));
        $user_password = mysqli_real_escape_string($con,trim($_POST['password']));

        if(!empty($user_username) && !empty($user_password))
        {
            $query = "SELECT * from Account where Username = '$user_username'";
            $data = mysqli_query($con,$query);

            if(mysqli_num_rows($data) == 1)
            {
                $row = mysqli_fetch_array($data);
                $_SESSION['user_id'] = $row['user_id'];
                $_SESSION['username'] = $row['username'];
                setcookie('user_id', $row['user_id'], time() + 60);    // expires in 30 days
                setcookie('username', $row['username'], time() + 60);  // expires in 30 days 
                $profile_url = 'http://localhost/RegenWeb/profile.php';
                header('Location: ' . $profile_url);
            }
        }
        mysqli_close($con);
    }
?>

have you even assigned $profile_url ? to a URL?

Dear archie.herbias,

Try header("Location: " . $profile_url);

Member Avatar for Zagga

Hi archie.herbias,

There are several places this code could be failing.

Is there a problem in connectvars.php?
Is $_POST['login'] set from a form?
Is the database connecting correctly?
Are $username and $password set?
Is the database query working?
Is there 1 username + password match in the database?
Is there any reason you aren't hard coding the header? header('Location: http://localhost/RegenWeb/profile.php');

If you add some echo $var or or die statements in your code it will help pinpoint the problem.

Dude, Just simply try this

$profileURL = 'localhost/whatever.php';
// or for more advance.
//make sure you create a configuration file(Session.inc) . Google it you'll see ;)
$profileURL = $dir. '/whatever.php';

why not include "http:"... ? because it's a LOCALHOST! you're just using an Apache, it won't redirect the URL. so i suggest that you ommit the 'http://' part..

Happy Coding!:)
-CigoL..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.