General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 26th, 2004, 01:26 AM
sonu sonu is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 sonu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Weird Header("Location function

This is really pissing me off...

I use a login form to log the user in and if the username and password are correct than the user gets redirected to the 'account.php' page. But the stupid script keeps redirecting back to the <form action=".." method="post"> url which is loginp.php

here is the code for login.php:

PHP Code:
<form action="loginp.php" method="post">


<
tr>
  <
td width="361" style="font-weight: bold; color: black; border-style: none" height="31">
    <
p align="right"><b>Username:</b></p>
  </
td><td width="310" height="31">
    <
p><input type="text" name="username" size="20"> <sup>
    <
font face="Tahoma">(Case Sensitive)</font></sup></p>
  </
td></tr>

<
tr>
  <
td width="361" style="font-weight: bold; color: black; border-style: none" height="20">
    <
p align="right"><b>Password:</b></p>
  </
td><td width="310" height="20">
    <
input type="password" name="password" size="20"> <sup> <font face="Tahoma">(Case Sensitive)</font></sup>
  </
td></tr>

</
table>
  <
p align="center"><input type="submit" value="Log-In" name="B1">&nbsp;&nbsp;
  <
input type="button" value="Cancel" name="B2" onClick="parent.location.href='default.php'">

</
form


and here is the PHP code for loginp.php:

PHP Code:
<?
    
if (!isset($_POST['username']) | !isset($_POST['password'])){
        
//do nothing
    
} else {
        
//connect to database
            
include 'connect.php';
            
            
$sql mysql_query("SELECT MemberID, UserName, Password FROM members WHERE BINARY UserName = '".$_POST['username']."'") or die("Query failed : " mysql_error());
            
$fetch_em mysql_fetch_array($sql);
            
$numrows mysql_num_rows($sql);
                            
                if(
$numrows != "0" $_POST['password'] == $fetch_em["Password"]) {
                    
//echo "login successful";
                    
$_SESSION['memid'] = $fetch_em["MemberID"];
                    
$_SESSION['username'] = $fetch_em["UserName"];
                    
Header("Location: account.php");
                } else {            
                    echo 
"<b><font color=red>Login Unsuccessful</font></b>";
                }            
            
/* Free resultset */
            
mysql_free_result($sql);
                        
            
/* Closing connection */
               
mysql_close($link);
           }               
?>



the loginp.php code actually woks but for some stupid reason it redirects to "loginp.php" page rather than "account.php" page.

can anyone please explain why it is doing this?

Thanks.

Reply With Quote
  #2  
Old January 26th, 2004, 08:11 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
My guess is that the authentication actually isn't working and that rather than redirecting, it's printing the error and staying on the loginp.php page. Have you tried printing out all the variables you're testing so you can verify that everything's coming across as it should?

Reply With Quote
  #3  
Old January 27th, 2004, 08:36 PM
sonu sonu is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 sonu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thats ok worked it out

what the problem was that in the address bar it was saying URL but it was also displaying a page not found error.

so i created the accoun.php page and it went there. Because i didn't have a account.php page i was expecting that it would display URL in the address bar and the page not found page.

so my bad!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Weird Header("Location function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT