Results 1 to 11 of 11

Thread: Easy Question about loading another page.

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Easy Question about loading another page.

    Hi guys,

    I have this code to verify the login of a certain user. What I want is when the login succedd it will load another page.

    PHP Code:
    <?php
    if(verify($name,$pass)!=1) echo "User Name or password is incorrect!";
    else{
    echo 
    "Welcome: $name";
    //Call here the page. mypage.php

    ?>
    How can I do that?

  2. #2
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Easy Question about loading another page.

    use this
    PHP Code:
    header("Location: mypage.php\n \r"); 
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  3. #3

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Easy Question about loading another page.

    thanks for the quick reply but I got this error: Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\connectmssql.php:31) in C:\Program Files\Apache Group\Apache2\htdocs\verifylog.php on line 32]

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Easy Question about loading another page.

    You can't use header() to redirect once you've sent data output (echo "Welcome: $name") - you can either use a meta tag to redirect after a timeout, or you can redirect straight away without sending any output (the quicker way).

  5. #5

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Easy Question about loading another page.

    pen I tried to remove the echo thingy in the else statement but nothing happens it still throws an error.

    PHP Code:
    if(verify($name,$pass)!=1) echo "User Name or password is incorrect!";
    else{
    header("Location: mypage.php");}
    ?>

    //and here's the verify function
    function verify($name,$pass){
    $query="select 1 from table where name='$name' and password='$pass'";
    $r=mssql_query($query);
    $max=mssql_num_rows($r);
    return $max;


  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Easy Question about loading another page.

    See the bit in the error where it says
    (output started at C:\Program Files\Apache Group\Apache2\htdocs\connectmssql.php:31)
    The file and line it points to, look there - that is the bit you need to change. Anything like echo, print, or anything outsite <?php ?> tags needs to go.

  7. #7

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Easy Question about loading another page.

    Pen here's the code about connectmssql.php. It'a class for the connection through my database. What thing should I remove here? Sorry to ask such a noob question but this is my first time playing w/ php, actually this is my first project in php. So please bear w/ me.
    PHP Code:
    <?php

    class DBConnect{

    private 
    $host;
    private 
    $user;
    private 
    $pw;
    private 
    $link;

    public function 
    myconnect($host,$user,$pw)
    {
        
    $this->host=$host;
        
    $this->user=$user;
        
    $this->pw=$pw;
        
    $this->link=mssql_connect($this->host,$this->user,$this->pw);
        if(!
    $this->link)
        {
            die(
    'could not connect'.mssql_error());
        }
    }

    public function 
    myclose()
    {
        
    mssql_close($this->link);
    }
    }
    ?>

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Easy Question about loading another page.

    Seems fine. Make sure there are no trailing characters after the closing ?> tag. < must be the first character and > the last, as anything outside them will be outputted.

  9. #9

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Easy Question about loading another page.

    Pen here's my full code. Any wrong w/ it?
    PHP Code:
    <?php
    require 'connectmssql.php';

    $db=new DBConnect;

    $name=$_POST['name'];
    $pass=$_POST['pass'];

    $db->myconnect('xx','xx','xxxx');

    mssql_select_db('xx');
    function 
    verify($name,$pass){
    $query="select 1 from dtrlog where name='$name' and password='$pass'";
    $r=mssql_query($query);
    $max=mssql_num_rows($r);
    return 
    $max;
    }
    $db->myclose();
    ?>

    <html>
    <head><title>DTR</title>
    <link rel='stylesheet' type='text/css' href='mystyle.css'>
    </head>
    <body>
    <table>
    <tr><td><img src='images/xxx.jpg'></td></tr>
    </table>
    <table cellpadding='3' cellspacing='3'>
    <tr><td class='small'>
    <?php
    if(verify($name,$pass)==1){ header("Location: dtrshow.php");}
    else{echo
    "<p class='bold'>User Name or password is incorrect!</p>";}
    ?></td></tr>
    </table>
    <hr>
    </body>
    </html>

  10. #10
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Easy Question about loading another page.

    you see me... i don't like the problems i encounter when i try using the
    PHP Code:
    header("Location: page.html"); 
    so my own way of always doing the redirection is
    Code:
    <script>
    window.location = 'somepage.php';
    </script>
    and since i always use this JS function, i make it in to a php function so i can use it anytime(even when it subject to changes)
    this is how i do it.
    PHP Code:
    function jsredir($url){
    <
    script>
    window.location '$url';
    </
    script>

    so anytime i want to use it i do this
    PHP Code:
    jsredir("mypage.html"); 
    and viola...
    i like it when i do things like this(so simple)...
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Easy Question about loading another page.

    Quote Originally Posted by mar_zim
    Pen here's my full code. Any wrong w/ it?
    Sorry, missed that post

    It looks OK, but check that it is connecting to the DB properly. It might be that an error is being outputted and stopping the header from working.

    modpluz - Never rely on Javascript.

Posting Permissions

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



Click Here to Expand Forum to Full Width