Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-07-2006, 04:22 AM Redirect after login
Super Talker

Posts: 145
Trades: 0
Hello everyone,

I am using a login area in my website in order the user to login to the website and be able to buy items online.I want when the user logins and verifies the identity to redirect to another page (page basket) in order the user to see his items. I have created the login page and verifyies the identity however my problem is that does not redirect the user to the next page it just reloads the same page.In order to redirect the user i use the function header after the verification of the user. I will post here the code and I would really appreciate your help.

HTML Code:
<table width="490" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <th width="293" valign="top" class="descriptiontitle" scope="col"><div align="left">Please fill in the details to login </div></th>
          </tr>
        <tr>
          <th valign="top" class="descriptiontitle" scope="col">&nbsp;</th>
        </tr>
        <tr>
          <th valign="top" scope="col"> 
          <form name="login" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>"> 
          
            <table width="185" border="0" align="center">
           <tr>
             <td><label><span class="body">Username:</span></label></td>
             <td><input name="user" type="text" class="body"></td>
           </tr>
           <tr>
             <td><label><span class="body">Password</span>:</label></td>
             <td><input name="pass" type="password" class="body"></td>
           </tr>
           <tr>
             <td>&nbsp;</td>
             <td><input name="submit" type="submit" class="body" value="Login"></td>
           </tr>
           </table>
      </form>      </th>
          </tr>
        <tr>
          <th valign="top" scope="col">
l
PHP Code:
          <table width="185" align="center">
          <tr>
           <td width="756">
<? if (isset($_POST['submit']))
            {
//If submit button has been clicked
                
            
            //First check if there is data and is valid
            
            
            //check for the username
            
if (empty($_POST['user]))
                {
                     $user=FALSE;
                        echo '
<class=\'errorregister\'>You forgot to enter your username</p>';
                 }else {
                             
$user=$_POST['user'];
                            }

            if (empty(
$_POST['pass']))
                {
                    
$pass=FALSE;
                    echo 
'<p class=\'errorregister\'>You forgot to enter your password</p>';
                 }else {
                             
$pass=$_POST['pass'];
                            }

            
            if (
$user && $pass){
    
    
$query "SELECT * FROM Customer WHERE user= '$user' and pass=PASSWORD('$pass')";
    
$result = @mysql_query($query);
    
$row mysql_fetch_array($result);
    
        if (
$row){
                    
$_SESSION['user']=$row['user'];
                    
$_SESSION['pass']=$row['pass'];
            
ob_end_clean();//Delete the buffer
            
echo "welcome";
            
header ("Location: http://domain.co.uk/basket.php");
            exit();
                
                }else {
                            echo 
'<p class=\'errorregister\'>Your username and password do not match</p>';
                        }
                        
mysql_close();
                        
                    }
    else { 
//if username and password had problem 
                                
echo '<p class=\'errorregister\'>Please try again';
                            }
                
}
//end of submit conditional


?>           </td>
          </tr>
      </table>
HTML Code:
          </th>
        </tr>
        <tr>
          <th valign="top" scope="col"><div align="left" class="body"><span class="confirm">Note:</span> if you don't have an account please <a href="regi.php">register</a> </div></th>
        </tr>
      </table>
Thank you,
Xenia
xenia is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-07-2006, 07:12 AM Re: Redirect after login
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
After a succeffull login I too redirect using the header function.

Your form posts to itself so there is no way that you can access basket after a post unless you redirect using header (or some other method).



Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf

Last edited by ibbo; 07-07-2006 at 07:14 AM..
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 07-07-2006, 09:41 AM Re: Redirect after login
Webmaster Talker

Posts: 626
Trades: 0
My understanding is that once you have written anything to the page (which is converted to HTML) then the headers are automatically sent, and you can't send them twice.

Have you tried using a META refresh or a javascript redirect??
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 07-07-2006, 10:22 AM Re: Redirect after login
Novice Talker

Posts: 9
Trades: 0
You cannot have any html/text before your header: location code
JimmyRcom is offline
Reply With Quote
View Public Profile Visit JimmyRcom's homepage!
 
Reply     « Reply to Redirect after login
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14556 seconds with 12 queries