0

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);
    }
?>
6
Contributors
5
Replies
9
Views
4 Years
Discussion Span
Last Post by cigoL..:)
0

Dear archie.herbias,

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

Edited by rayidi

0

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.

Edited by Zagga

0

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..:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.