PHP PDO Header redirect stopped working -


this question has answer here:

i've built site on test server , i'm putting on new server host site. i'm using pdo connections , once prepared statement executes redirect homepage of website sites on different server i'm getting error

error

cannot modify header information - headers sent (output started @ /home1/mlayzell/public_html/alpha/cms/includes/my-db-functions.php:17)

the code self membership activation, user signs e-mails user confirmation e-mail click link , there account gets changed active. here code if please me figuring out appreciated, in advance!

my-db-function.php

<?php require("config.php"); function connect_to_db() { global $dbhost, $dbname, $dbuser, $dbpass, $db;  try {     $db = new pdo('mysql:host='.$dbhost.';dbname='.$dbname.'', $dbuser, $dbpass);     $db->setattribute(pdo::attr_errmode, pdo::errmode_exception); }  catch(pdoexception $error) {     echo 'error: ' . $error->getmessage(); }  } ?> 

php

if($_get['action']==0) {  if(isset($_post['name'],$_post['email'],$_post['password'])) {      $key = md5(rand(0,1000));     $date = date('y-m-d h:i:s');      $statement_user = $db->prepare("insert `app_users` ( `use_name`, `use_key`, `use_email`, `use_password`, `use_date`, `use_status`, `use_typ_id`) values (:use_name, :use_key, :use_email, :use_password, :use_date, :use_status, :use_type);");      $statement_user->execute(array(':use_name' => $_post['name'], ':use_key' => $key, ':use_email' => $_post['email'], ':use_password' => $_post['password'], ':use_date' => $date, ':use_status' => "0", ':use_type' => "0"));           $to = $_post['email'];           $subject = 'signup | verification';           $message = '   signing up!  account has been created, can login following credentials after have activated account clicking link below.   ------------------------  email: '.$email.'  password: '.$password.'  ------------------------   please click link activate account:   http://theapplist.com/alpha/cms/users/handler-users.php?action=5&use_email='.$_post['email'].'&use_key='.$key.'   ';              $headers = 'from:noreply@mysite.com' . "\r\n";              mail($to, $subject, $message, $headers);                header('location:../index.php?signup=success');         }         else {              echo "fail";         }     } 

since, using header('location:../index.php?signup=success');

after outputting data browser already, error always happen.

because, header() function or headers should sent, before pages starts render html tags, before of page's contents loaded browser.

so if need small hack around of problem include echo ob_start() @ top of document. before <html>

like this:

<?php echo ob_start(); ?> <html> <head></head> //and keep going 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -