Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php/mysql login redirection

Posted on 2006-07-12
3
Medium Priority
?
428 Views
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");
exit;
}
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.

Thx,


<?

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

$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");
exit;
}

?>

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

</body>
</html>
0
Comment
Question by:steelthundr
[X]
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
3 Comments
 
LVL 7

Expert Comment

by:kayrules
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..
0
 
LVL 10

Accepted Solution

by:
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'>";
    exit;
   

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


Let me know if that works.
0
 

Expert Comment

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

ob_start();

and finish the script with:

ob_end_flush();

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

Hope it helps.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
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

604 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