Jump to content
Larry Ullman's Book Forums

Adapting Ch17 Message Board - No Sessions


Recommended Posts

Hi Larry and forum members,

 

I'm hoping someone could please help me out. I'd like to modify script 17.1 (from ch17, example message board) so that it works without the need for sessions. My non-forum website doesn't require any login/logout functionality, and anyone should be able to change the language (I plan on having a selection of 4 or 5 different languages).

 

What I've done so far is replace all instances of $_SESSION['lid'] with $_GET['lid'] and modified <form action="forum.php" method="get"> to <form action="" method="get">. Something isn't working because I now receive an error: Undefined index: lid when I load the page.

 

I've posted the modified code below.

// Check for a new language ID...

if ( isset($_GET['lid']) && 
	filter_var($_GET['lid'], FILTER_VALIDATE_INT, array('min_range' => 1)) 
	) {
	 $_GET['lid'] = 1; // Default.
	 }
	

// Get the words for this language:
$q = "SELECT * FROM words WHERE lang_id = {$_GET['lid']}";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 0) { // Invalid language ID!
	
	// Use the default language:
	$_GET['lid'] = 1; // Default.
	$q = "SELECT * FROM words WHERE lang_id = {$_GET['lid']}";
	$r = mysqli_query($dbc, $q);
	
}

// Fetch the results into a variable:
$words = mysqli_fetch_array($r, MYSQLI_ASSOC);

// Free the results:
mysqli_free_result($r);
?>

<?php 
echo '<p>' . $words['home'] . '</p>
<p>' . $words['about'] . '</p>';



// For choosing a forum/language:
echo '</b><p><form action="" method="get">
<select name="lid">
<option value="0">' . $words['language'] . '</option>
';

// Retrieve all the languages...
$q = "SELECT lang_id, lang FROM languages ORDER BY lang_eng ASC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
	while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) {
		echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n";
	}
}
mysqli_free_result($r);

echo '</select><br />
<input name="submit" type="submit" value="' . $words['submit'] . '" />
</form></p>
    </td>
     
    <td valign="top" class="content">';
?>
 

Thank you in advance!!!

Link to comment
Share on other sites

 Share

×
×
  • Create New...