Page 1 of 1

Opening another page

Posted: Tue Apr 15, 2008 11:30 pm
by php14user
Hi,

I have a login page and when I submit the login form, login page reloads and include a php file "get_valid_user.php" that has the code for checking whether user exists or not.
Now when user does not exists, "get_valid_user.php" echoes the message on login page that user does not exists.
My problem is how to make "get_valid_user.php" open a new page "user_info.php" if user has supplied valid credentials?

I tried following code:

Code: Select all

<?php
 
    if($_POST["submit_form"] == "login_form_submitted")
    {
           if(!isset($_FILES) && isset($HTTP_POST_FILES))
           {
                  $_FILES = $HTTP_POST_FILES;
           }
          
           $con = mysql_connect("localhost","root","xyz");
           if (!$con)
                 {
                           die('Could not connect to MySQL: ' . mysql_error());
                 }
 
           mysql_select_db("my_db", $con);
 
           $login_id = $_POST["login_id"];
           $login_password = $_POST["login_password"];
 
           $result3 = mysql_query("SELECT * FROM Company_Registration where login_id = '$login_id' && login_password = '$login_password'");
 
           $no_Of_Row_Affected = mysql_affected_rows();
 
           if ($no_Of_Row_Affected == 0)
               { 
                         echo "No user!!";
               }
           else
               {
 
                          [color=#008000]//header('Location:http://localhost/Site/user_window.php');[/color]
                          [color=#008000]//include("user_window.php");[/color]
                          [color=#0000FF]I need to include a code here to open a new page user_window.php.[/color]
                }
}
?>
FYI, when I use "include("user_window.php");" then the content of user_window.php and content of home page overlaps.
I want to open the content of user_window.php in a separate page.

And when I use "header('Location:http://localhost/Site/user_window.php');", I get following error message:

Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/Site/home_page.php:5) in /Library/WebServer/Documents/Site/get_valid_user.php on line 40

Your help will be appreciated.
Thanks.

Re: Opening another page

Posted: Wed Apr 16, 2008 3:01 am
by Phoenixheart
header('Location') is often used in such a case. You're getting a warning because you've just output something (a text, or even a white space).

As alternatives, you can use javascript (not recommended though):

Code: Select all

<script>window.location.href="http://your.new.page.php";</script>
or meta tags:

Code: Select all

<meta http-equiv="refresh" content="1;url=http://your.new.page.php">
But, as I said, header is preferred :D .

Re: Opening another page

Posted: Wed Apr 16, 2008 5:46 am
by php14user
Hi,

Could you please review my code shown above? (Please assume that I am using "header('Location')" method in else part)
Please let me know what is causing below error:

Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/Site/home_page.php:5) in /Library/WebServer/Documents/Site/get_valid_user.php on line 40

Is my code correct?

Thanks,

Re: Opening another page

Posted: Wed Apr 16, 2008 5:57 am
by onion2k
header() will only work if you use it before outputting any HTML. You need to rethink the flow of your code (eg, move the header() call to somewhere near the top).