php/mysql login redirection

Posted on 2006-07-12
Medium Priority
Last Modified: 2013-12-12
The script works as is, but I want to take this block of code:
if ($num !=0) {
$msg = "<P>Congratulations, you're authorized!</p>";
} else {
header ("Location: login.html");
and redirect the user to another html page, and not have it say: $msg="<p>.........</p>";
I commented out $msg and put another header ("Location: newpage.html"); but got an error.



if ((!$_POST[username]) || (!$_POST[password])) {
header ("Location: login.html");

$db_name = "DBtest";

$table_name = "auth_users";

$connection = @mysql_connect("localhost", "", "")
or die(mysql_error());

$db = @mysql_select_db($db_name, $connection) or
die (mysql_error());

$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]'
AND password = password('$_POST[password]')";

$result = @mysql_query($sql, $connection) or die(mysql_error());

$num = mysql_num_rows($result);

if ($num !=0) {
$msg = "<P>Congratulations, you're authorized!</p>";
} else {
header ("Location: login.html");


<title>Secret Area</title>
<? echo "$msg"; ?>

Question by:steelthundr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 17096783
make sure when you use header() function, don't print any other character before it.. not even a space character.. to make sure, view your source code..
LVL 10

Accepted Solution

Kshitij Ahuja earned 200 total points
ID: 17097841
and redirect the user to another html page, and not have it say: $msg="<p>.........</p>";
I commented out $msg and put another header ("Location: newpage.html"); but got an error.

1. What was the error ?
2. Try this where you want to put the redirection:
    echo "<META http-equiv = 'refresh' content = '0; URL = RedirectToThisPage.html'>";

This is basically a substitute of
  header("LocationL NewPAge.html");

Let me know if that works.

Expert Comment

ID: 17098074
Alternatively, put the following line of code at the top of your script:


and finish the script with:


that way any output is suppressed by the "output buffer", and any headers found will take priority.

Hope it helps.

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question