Jump to content

Back-button Error


doubledee

Recommended Posts

I am getting strange behavior after a user submits a comment.

 

After they comment on an article, I display a success message with two buttons: "Return to Article" and "Go to Home Page"

 

Each button seems to work, and I was even able to "Return to Article" and then hit my browser's Back button to return the original "You Comment was Added" message, but if I hit the Back button after hitting "Go to Home Page" I got this error...

 

Notice: Undefined index: pageTitle in /Users/user1/Documents/DEV/++htdocs/01_MyProject/add_comment.php on line 39

Call Stack

 

On Line 39 I have this code...

 

// Set Page Title.
$pageTitle = $_SESSION['pageTitle'];

 

 

It seems to me that if a user hits the Back button in general it will often cause problems, so is there a way to handle this??

 

I'm not exactly certain is causing the error above in the first place since my SESSION should be intact....  :confused:

 

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/246152-back-button-error/
Share on other sites

are you checking to see if the session is not empty or set :confused:

 

// Set Page Title
$pageTitle = isset($_SESSION['pageTitle']) ? $_SESSION['pageTitle'] : 'The Session has not been set';

 

No, I am not checking if it is set, but regardless, why is it becoming "un-set" after the user hits the back button?

 

And even if your code above fixed one problem, it would create another one...

 

Here is my code...

 

// Verify Insert.
if (mysqli_stmt_affected_rows($stmt)==1){
// Insert Succeeded.
echo '<div id="box_Content_700b">';
echo	'<h1>Comment Submitted</h1>';
echo	'<p>Thanks for sharing your thoughts!</p>
<p>Once approved, your comment will appear below the article:<br />
<span id="articleTitle">' . '"' . htmlspecialchars($pageTitle, ENT_QUOTES) .	'"</p>';
echo '<ul>
		<li>
			<a href="' . WEB_ROOT . $returnToPage . '">
			<img src="' . WEB_ROOT . 'buttons/ReturnToArticle.png" alt="Return to Article" />
			</a>
		</li>
		<li>or</li>
		<li>
			<a href="' . WEB_ROOT . 'index.php">
			<img src="' . WEB_ROOT . 'buttons/GoToHomePage.png" alt="Go to Home Page" />
			</a>
		</li>
	</ul>';

echo '</div>';
}else{
// Insert Failed.
echo '<div id="box_Content_700b">';
echo	'<h1>Comment Creation Failed</h1>';
echo	'<p>Your comment could not be added due to a system error.</p>';
echo '</div>';
}// End of VERIFY INSERT.

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/246152-back-button-error/#findComment-1264150
Share on other sites

unless you plan on using globals you need to call session_start  on each page or your session won't carry over from a previous page.

 

Global session function:

function global_session($var){
        if(!array_key_exists($var,$_SESSION))
            $_SESSION[$var]='';
        $GLOBALS[$var]=&$_SESSION[$var];
    }

Link to comment
https://forums.phpfreaks.com/topic/246152-back-button-error/#findComment-1264153
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.