dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Error When Redirecting a Page

  1. #1
    Join Date
    May 2014
    Posts
    7

    resolved [RESOLVED] Error When Redirecting a Page

    Hi,
    I am New in PHP and developing a login system. I want that if user provide correct info, the page redirects to welcome.php , but its giving an error "Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\MyWork\LoginDemo.php:18) in C:\xampp\htdocs\MyWork\LoginDemo.php on line 33"
    my code is as under
    Code:
     if ($count >= 1) {
            echo "My User Name : " . $username . "<br/>";
            echo "My password  : " . $password;
            header('Location: WelcomePage.php'); /* Redirect browser */
        } else {
            echo "Invalid User";
        }
    If I write the same code "header('Location: WelcomePage.php'); /* Redirect browser */" in a blank PHP file, it works

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,307
    Quote Originally Posted by hafizfarooq View Post
    Hi,
    I am New in PHP and developing a login system. I want that if user provide correct info, the page redirects to welcome.php , but its giving an error "Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\MyWork\LoginDemo.php:18) in C:\xampp\htdocs\MyWork\LoginDemo.php on line 33"
    my code is as under
    Code:
     if ($count >= 1) {
            echo "My User Name : " . $username . "<br/>";
            echo "My password  : " . $password;
            header('Location: WelcomePage.php'); /* Redirect browser */
        } else {
            echo "Invalid User";
        }
    Notice what I highlighted in red, above. If you still don't get it, see the online manual page for header(), in particular the 2nd paragraph under "Description".
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Apr 2008
    Location
    Earth
    Posts
    31
    Seems there is a downside to browsing multiple forums...

    http://www.vbforums.com/showthread.p...recting-a-Page

  4. #4
    Join Date
    May 2014
    Posts
    7
    Thanks NogDog,
    There were few HTML commands like <br> , <hr> etc before HEADER, deleted all. Now its working fine.

  5. #5
    Join Date
    May 2014
    Posts
    7
    Thanks dclamp.... followed your way

  6. #6
    Join Date
    Apr 2008
    Location
    Earth
    Posts
    31
    :wave:

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles