I am working on a module that allows Members to add comments to my articles. To do so, you must log-in or register.
I am testing the Article123 ---> Log In ---> Redirect to Article123 path...
My code was working last night except I was getting this annoying "Headers Already Sent" error message unless I added Output Buffering.
Late last night I moved most of my PHP before my HTML to eliminate this issue, but now my re-direct is broken?!
In my article.php I am setting the return page here...
When a User chooses to "Log In", the button that they click takes them to log_in2.php and this code is supposed to re-direct them back to the original article...
log_in2.php
I am also using the following mod_rewrite...
As far as I can tell, when flow is re-directed back to "article.php", the GET variable is not getting set and this code is failing...
article.php
And this path gets run...
Any ideas what my code re-write did to break things?!
Thanks,
Debbie
I am testing the Article123 ---> Log In ---> Redirect to Article123 path...
My code was working last night except I was getting this annoying "Headers Already Sent" error message unless I added Output Buffering.
Late last night I moved most of my PHP before my HTML to eliminate this issue, but now my re-direct is broken?!
In my article.php I am setting the return page here...
PHP Code:
// Set Article Title.
$articleTitle = $_GET['title'];
$_SESSION['articleTitle'] = $_GET['title'];
// Set current Script Name + Query String.
$_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME'] . '/' . $articleTitle;
log_in2.php
PHP Code:
// ****************************
// Check for Member Record. *
// ****************************
if (mysqli_stmt_num_rows($stmt)==1){
// Member was Found.
// Bind result variables.
mysqli_stmt_bind_result($stmt, $memberEmail, $memberFirstName);
// Fetch record.
mysqli_stmt_fetch($stmt);
$_SESSION['loggedIn'] = TRUE;
$_SESSION['memberEmail'] = $memberEmail;
$_SESSION['memberFirstName'] = $memberFirstName;
// Redirect User.
if (isset($_SESSION['returnToPage'])){
header("Location: " . $_SESSION['returnToPage']);
}else{
// Take user to Home Page.
header("Location: " . WEB_ROOT . "index.php");
}
// End script.
exit();
}else{
// Member not Found.
$_SESSION['loggedIn'] = FALSE;
$errors['pass'] = 'The E-mail and Password do not match those on file.';
}// End of CHECK FOR MEMBER RECORD.
I am also using the following mod_rewrite...
Code:
RewriteEngine on #PRETTY: articles/postage-meters-can-save-you-money #UGLY: article.php?title=postage-meters-can-save-you-money RewriteRule articles/([a-zA-Z0-9_-]+)$ article.php?title=$1 # Build Date: 2011-08-22 7:08pm
As far as I can tell, when flow is re-directed back to "article.php", the GET variable is not getting set and this code is failing...
article.php
PHP Code:
// Check for Title in URL.
if (isset($_GET['title'])){
// Title found in URL.
// Set Article Title.
$articleTitle = $_GET['title'];
$_SESSION['articleTitle'] = $_GET['title'];
// Set current Script Name + Query String.
$_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME'] . '/' . $articleTitle;
// Build query.
$q = 'SELECT html_title, meta_description, meta_keywords, page_title, page_subtitle,
written_on, author, body, reference_listing, endnote_listing
FROM article
WHERE article_title=?';
// Prepare statement.
$stmt = mysqli_prepare($dbc, $q);
// Bind variable.
mysqli_stmt_bind_param($stmt, 's', $articleTitle);
// Execute query.
mysqli_stmt_execute($stmt);
// Transfer result set from prepared statement.
// (Required for all queries that return results.)
mysqli_stmt_store_result($stmt);
// Check for Article Record.
if (mysqli_stmt_num_rows($stmt)==1){
// Article in Database.
$articleExists = TRUE;
// Bind result variables.
mysqli_stmt_bind_result($stmt, $htmlTitle, $metaDescription, $metaKeywords, $pageTitle, $pageSubtitle,
$writtenOn, $author, $body, $referenceListing, $endnoteListing);
// Fetch record.
mysqli_stmt_fetch($stmt);
}else{
// Article not in Database.
// Take user to Home Page.
header("Location: " . WEB_ROOT . "index.php");
}
}else{
// Title not found in URL.
// Take user to Home Page.
header("Location: " . WEB_ROOT . "index.php");
}// End of CHECK FOR ARTICLE IN URL.
Code:
}else{ // Title not found in URL. // Take user to Home Page. header("Location: " . WEB_ROOT . "index.php"); }// End of CHECK FOR ARTICLE IN URL.
Any ideas what my code re-write did to break things?!

Thanks,
Debbie
Comment