SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple redirection help please

    I am trying to send a user to a different page depending on their user level but am getting warnings and no redirection.
    I am not sure that I am doing it correctly but have seen similar examples of redirection elsewhere.

    here is the code

    <HTML>
    <HEAD>
    </HEAD>
    <BODY>

    <?php


    // Connect to the database server
    $dbcnx = @mysql_connect("localhost",
    "root", "");
    if (!$dbcnx) {
    echo( "<P>Unable to connect to the " .
    "database server at this time.</P>" );
    exit();
    }

    //Select the relevant database
    $selection = mysql_select_db("secretDB", $dbcnx);
    if (!$selection) {
    echo (mysql_error());
    exit();
    }

    //Get user security level from table users
    $sec_level=mysql_query("SELECT** ".
    "FROM*users WHERE username='$username' AND password='$password'");

    $num_rows=mysql_num_rows($sec_level);

    while($i=mysql_fetch_row($sec_level)){

    // code here to send user to page according to 3rd item in row
    if($i[2]= 1)
    {
    header("Location:*http://192.168.0.30/test1.php/\n\n");
    }
    elseif($i[2]= 2)
    {
    header("Location:*http://192.168.0.30/test2.php/\n\n");
    }
    elseif($i[2]= 3)
    {
    header("Location:*http://192.168.0.30/test3.php/\n\n");
    }

    } //end while loop


    //output for debugging only at this stage
    echo("<P> Number of rows is $num_rows!</p>");
    echo("<P> User Name is $username !</p>");
    echo("<P> Password is $password ! </P>");

    ?>
    </BODY>
    </HTML>

    And here is the output


    Warning: Cannot add header information - headers already sent by (output started at /usr/local/apache/htdocs/login.php:6) in /usr/local/apache/htdocs/login.php on line 36

    Warning: Cannot add header information - headers already sent by (output started at /usr/local/apache/htdocs/login.php:6) in /usr/local/apache/htdocs/login.php on line 36


    Number of rows is 2!

    User Name is andrew !

    Password is andrew !



    Any help is appreciated Thanks

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those should be ==, and you don't need the \n\n on the header.

    One other thing: you can't send headers after you have output anything to the browser, which is what your <html><head></head> etc. does. You need to put the code before you output anything.

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks,

    But if I remove the <HTML> etc headers I still get the same warning from <?php ....

    How can I get around this?

    Thanks

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You cannot print anything out before you send headers.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have removed all the echo statements but still get the warning message, line 2 is <?php and line 35 is


    Warning: Cannot add header information - headers already sent by (output started at /usr/local/apache/htdocs/login.php:2) in /usr/local/apache/htdocs/login.php on line 35 header("Location:$location1");

    Here is the complete code

    <?php

    $location1="http://192.168.0.30/test1.php/";
    $location2="http://192.168.0.30/test2.php/";
    $location3="http://192.168.0.30/test3.php/";

    // Connect to the database server
    $dbcnx = @mysql_connect("localhost",
    "root", "");
    if (!$dbcnx) {
    // echo( "<P>Unable to connect to the " .
    // "database server at this time.</P>" );
    exit();
    }

    //Select the relevant database
    $selection = mysql_select_db("secretDB", $dbcnx);
    if (!$selection) {
    // echo (mysql_error());
    exit();
    }

    //Get user security level from table users
    $sec_level=mysql_query("SELECT** ".
    "FROM*users WHERE username='$username' AND password='$password'");

    $num_rows=mysql_num_rows($sec_level);

    $i=mysql_fetch_row($sec_level); //all username/passwords are unique so only one row is returned

    // code here to send user to page according to 3rd item in row
    if($i[2]== 1)
    {
    header("Location:$location1");
    }
    elseif($i[2]== 2)
    {
    header("Location:$location2");
    }
    elseif($i[2]== 3)
    {
    header("Location:$location3");
    }
    ?>

  6. #6
    SitePoint Enthusiast ErikN's Avatar
    Join Date
    Jul 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you have any html on the page? ifso, place it after the php.

  7. #7
    SitePoint Zealot NZ Joe's Avatar
    Join Date
    Apr 2001
    Location
    Kapiti, New Zealand
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use :

    <META HTTP-EQUIV="Refresh" Content= "0; URL=<?php $location1; ?>">
    Gravity always wins


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
  •