Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8414591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:12:21+00:00 2026-06-10T01:12:21+00:00

I am using MAMP and for some reason I am not getting redirected using

  • 0

I am using MAMP and for some reason I am not getting redirected using header in php, can someone please have a look at the following code if there is something wrong in it???

I have read similar posts and found that it is caused by a sort of white space before header tag but in my case it is not.

Please give your advices…thanx

<?php

$host="localhost"; // Host name 

$username="root"; // Mysql username 

$password="root"; // Mysql password 

$db_name="DBase"; // Database name 

$tbl_name="customers"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from the form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

$myusername = stripslashes($myusername);
$mypassword = md5($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword"); 
header("location:/Account/index.php");
}
else {
echo "Wrong Username or Password.";
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:12:22+00:00Added an answer on June 10, 2026 at 1:12 am
    header('Location: http://example.com/Account/index.php');
    exit;
    

    is one way to do this but you can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files.

    EDIT AND APPEND SOLUTION: ——>

    You can use Output Buffering as

        <?php
        ob_start();
        $host="localhost"; // Host name 
    
    $username="root"; // Mysql username 
    
    $password="root"; // Mysql password 
    
    $db_name="DBase"; // Database name 
    
    $tbl_name="customers"; // Table name 
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // username and password sent from the form 
    $myusername=$_POST['myusername']; 
    $mypassword=$_POST['mypassword']; 
    
    $myusername = stripslashes($myusername);
    $mypassword = md5($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'";
    $result=mysql_query($sql);
    
    $count=mysql_num_rows($result);
    
    if($count==1){
    session_register("myusername");
    session_register("mypassword"); 
    header("location:/Account/index.php");
    }
    else {
    echo "Wrong Username or Password.";
    }
        ob_end_flush();
        ?>
    

    The problem is that we cannot send the header after we start sending the output. To solve this we buffer the output. The function ob_start turns output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. So the echo output will be buffered. Next we send the header without any problem as we’ve not yet spit out any output. Finally we call ob_end_flush to flush the internal buffer contents and to stop output buffering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MAMP to host a website. I have index.html and index.php both
i'm using MAMP and want to activate xdebug. i've uncomment the following row in
I'm using gettext in a MAMP environment. I have locale files for es_ES ,
I have installed MAMP on my laptop and moved my web project (developed using
For some reason I can't use \n to create a linefeed when outputting to
I can't seem to get gettext working, here. I'm using MAMP Pro and phpinfo();
I'm using MAMP Pro to drive the servers so I can develop a Magento
I have always developed my projects using MAMP locally and once done simply uploaded
I'm trying to get away from using Mamp, so have recently installed mysql, edited
When I want to upload some files that I have tested with MAMP on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.