Results 1 to 5 of 5

Thread: redirection problem

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default redirection problem

    Hi again, i have problems with redirecttion in the script (header location index.php). its not working. when i log with right info, from login.php it redirects me to the same page - not index.php... Can some1 fix this??? i will be thankfull if you bold your changed place. Many thanks
    PHP Code:
    <table>
    <?php
    include('db_conn.php');

    if(isset(
    $_POST['submit'])) {
        
        
    $password md5($_POST[password]);
        
    $q mysql_query("SELECT * FROM reg_users WHERE Nick='$_POST[nick]' AND Password='$password'") or die(mysql_error());
        
        if(
    $_POST['password'] == '') {
            
    $error .= "<li>Neįrašėte slaptažodžio!</li>";
        }
        if(
    $_POST['nick'] == '') {
            
    $error .= "<li>Neįrašėte vartotojo -Niko- !</li>";
        }
        
        if(
    mysql_num_rows($q) == 0) {
            
    $error .= "<li>Prisijungimo duomenys neteisingi.</li>";
        }
        
        if(isset(
    $error)) {
            echo 
    '<font color="#ff0000">Prisijungimas neįvyko. Priežastis:';
            echo 
    '<ol>'.$error.'</ol></font>';
            
        } else {
            
            
    $r mysql_fetch_array$q ) or die(mysql_error());
            
            
    session_start();
            
    $_SESSION['nick'] = $_POST['nick'];
            
    $_SESSION['password'] = md5($_POST['password']);
            
    $_SESSION['authID'] = $r['id'];
            
    header("Location:index.php");
        }
    }

    if(
    $_GET['act'] == 'logout') {
        echo 
    '<center><font color="Green">You\'re successfully logged out.</font></center>';
        
    session_unset();
        
    session_destroy(); // remove the entire session
    }

    ?>
    </table>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <table align='center' width='700px' height='450px' background='images/login_langas.jpg' alt='Fonas'>
        <tr valign='center'>
        <td align='center'>
        <font size="3" color='yellow' face="Verdana"><b>Prisijungimas</b></font><br><br><br><br><br>
        <table align='center' width='400px' height='20px'>
        <tr valign='center'>
        <td>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                    <font size="1.5" color='blue' face="Verdana">
                    <td align="right"><font size="1.5" color='yellow' face="Verdana">Vartotojas</font></td>
                    <td><input type="text" name="nick"></td>
                    <td align="right"><font size="1.5" color='yellow' face="Verdana">Slaptažodis </font></td>
                    <td><input type="password" name="password"></td>
                    <td colspan="2" align="center">
                    <input type="submit" name="submit" value="Prisijungti">
                    </td>
        </form>
        </td>
        </tr>
        </table>

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    2 corrections before starting to work on your problem:

    1) You need quotes around password in this line: $password = md5($_POST[password]);

    2) You've got html output above your call to header("Location:index.php");. This is not going to work.

    Also you should format your header like this:
    PHP Code:
    header("Location: http://www.yoursite.com/index.php"); 
    and always call exit; after calling header.

  3. The Following User Says Thank You to JasonDFR For This Useful Post:

    auriaks (08-31-2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    Thanks... i solved this problem by putting all php before <html>

  5. #4
    Join Date
    Jul 2009
    Location
    Coquitlam BC Canada
    Posts
    46
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    yes...because php will not redirect if output is sent to the browser already...i think

  6. #5
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    hi again, i have problem with redirection again, but it's different: i write message, the page redirects and stands still. but when i refresh it, it ask: resend or cancel. when i resend, may message doubles... maybe i have to write something more? If you need a script ask me, thanks. [btw, im using firefox ]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •