•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,417 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,120 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 796 | Replies: 4 | Solved
![]() |
•
•
Join Date: Apr 2007
Location: New Zealand
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I am trying to make a login page using php.
index.php contain form for "login" and "password" which will be check by "process.php"
My intention is: if the login or password is incorrect, an alert box will pop up telling the user the case, and redirect back to index.php
Here is the code for process.php
I got the error message in "cannot modify header information". From the php textbox that I got, I know that the error was caused because I put "echo" code before "header"
Is there anyway to achieve what I want to do without putting anything before the header?
Thanks!
index.php contain form for "login" and "password" which will be check by "process.php"
My intention is: if the login or password is incorrect, an alert box will pop up telling the user the case, and redirect back to index.php
Here is the code for process.php
<?php
session_start();
include('db.php');
if(isset($_POST['submit'])) :
// Username and password sent from signup form
// Remove all HTML-tags and PHP-tags
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
// Make the query a wee-bit safer
$query = sprintf("SELECT ID FROM users WHERE username = '%s' AND user_password = '%s' LIMIT 1;", mysql_real_escape_string($username), mysql_real_escape_string($password));
$result = mysql_query($query);
if(1 != mysql_num_rows($result)) :
// MySQL returned zero rows (or there's something wrong with the query)
echo "<script>alert('Wrong login or password')</script>";
header('Location: index.php');
else :
// We found the row that we were looking for
$row = mysql_fetch_assoc($result);
// Register the user ID for further use
$_SESSION['member_ID'] = $row['ID'];
header('Location: members-only.php');
endif;
endif;
?>I got the error message in "cannot modify header information". From the php textbox that I got, I know that the error was caused because I put "echo" code before "header"
Is there anyway to achieve what I want to do without putting anything before the header?
Thanks!
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 554
Reputation:
Rep Power: 3
Solved Threads: 57
you can't use header() like that. you would need to make the javascript redirect using:
window.location = 'index.php';
•
•
Join Date: May 2008
Location: Kingdom of Saudi Arabia
Posts: 25
Reputation:
Rep Power: 1
Solved Threads: 1
•
•
Join Date: May 2008
Posts: 13
Reputation:
Rep Power: 1
Solved Threads: 1
hi,
As in above reply you cant have to left any line before code starting
and one thing is that , you include file like include('db.php');
so you have to check if there is another session_start(); in your db.php file then also you get this same error.
check all thing and run it again you sure get output
As in above reply you cant have to left any line before code starting
and one thing is that , you include file like include('db.php');
so you have to check if there is another session_start(); in your db.php file then also you get this same error.
check all thing and run it again you sure get output
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
- Cookies problem - not working (PHP)
- "Forbidden / You don't have permission to access / on this server." error (Linux Servers and Apache)
- This ought to be simple - extra spaces (PHP)
Other Threads in the PHP Forum
- Previous Thread: preg_match occurence position.
- Next Thread: Creating a Forum website


Linear Mode