Call a PHP page from another PHP page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
StorM_GmA
Forum Newbie
Posts: 4
Joined: Mon Jun 30, 2008 9:42 am

Call a PHP page from another PHP page

Post by StorM_GmA »

Hello! My first post here :D

I'm making a website for the university and I want to create a log In page. My website has some iframes and one of them is displaying the Username and Password textboxes with a submit button. After user presses the Submit, the website is calling another PHP (LogInValidate.PHP) which checks if the username and password are ok. The problem is that I want to create a cookie when the user has succesfuly logged in and I've read that the cookie should be created at the top of the page before the <html>. So if the LogInValidate.PHP page says that the user is logged in, I want to call another PHP page (Welcome.PHP) which will create the cookie and then it will display a welcome message...

So, how can I call the Welcome.PHP without using a form? (because forms should have a submit button to work and I want to be done automatically).
Sorry if the question is stupid but I couldn't find anything useful in google...maybe I didn't search for the correct keywords...

Thanks alot!

edit: I have tried the header("Location: welcome.PHP") but I get this error: Warning: Cannot modify header information - headers already sent by (output started at c:\http\site\loginvalidate.php:7) in c:\http\site\loginvalidate.php on line 15


here's the code of LogInValidate.PHP

Code: Select all

<html>
    <head>
        <title>
        </title>
    </head>
    <body>
        <?php
            extract($_POST);
            if(!($conn=odbc_connect("dbWSM", "", ""))) { die("could not connect to the database."); }
            $sql="SELECT username FROM Customers WHERE 
            username= '" . $txtUsr . "' AND password= '" . $txtPass . "'";
            if(!($rs=odbc_exec($conn,$sql))) { die(mysql_error); }
            if (odbc_result($rs,1) != "") {
                echo odbc_result($rs,1);
                header("Location: welcome.php");
            }
            else { header("Location: invalid.php" }
        ?>
        <a href="logout.php">(Log out)</a>
    </body>
</html>
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Call a PHP page from another PHP page

Post by Bill H »

Code: Select all

 
<?php
extract($_POST);
if(!($conn=odbc_connect("dbWSM", "", ""))) { die("could not connect to the database."); }
   $sql="SELECT username FROM Customers WHERE
    username= '" . $txtUsr . "' AND password= '" . $txtPass . "'";
    if(!($rs=odbc_exec($conn,$sql))) { die(mysql_error); }
         if (odbc_result($rs,1) != "") {
              echo odbc_result($rs,1);
              header("Location: welcome.php");
              exit;
    }
    else { 
        header("Location: invalid.php" 
        exit;
}
?>
<html>
    <head>
        <title>
        </title>
    </head>
    <body>
        <a href="logout.php">(Log out)</a>
    </body>
</html>
StorM_GmA
Forum Newbie
Posts: 4
Joined: Mon Jun 30, 2008 9:42 am

Re: Call a PHP page from another PHP page

Post by StorM_GmA »

duh...that was very simple :banghead:

Thanks alot for your help!
Post Reply