Prev | Current Page 343 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

The purpose of the redirect isn??™t for search engine optimization but to
give users a way to bookmark search results pages and offer other web sites the means to link to these pages:
if (isset ($_GET['Search']))
{
$this->mSearchString = trim($_POST['search_string']);
$this->mAllWords = isset ($_POST['all_words']) ?
$_POST['all_words'] : 'off';
// Clean output buffer
ob_clean();
// Redirect 302
header('HTTP/1.1 302 Found');
header('Location: ' .
Link::ToSearchResults($this->mSearchString, $this->mAllWords));
// Clear the output buffer and stop execution
flush();
ob_flush();
ob_end_clean();
exit();
}
Of course, when implementing the search results page in the next exercise, we??™ll need to learn how to interpret the
search results links. Currently, the any-words search for ???beautiful flower??? link is: http://localhost/tshirtshop/
search-results/find-beautiful-flower/all-words-off/. If this were an all-words search, the last bit
of the URL would be all-words-on instead of all-words-off. The second page of the results would contain
/page-2/ at the end of the URL.
If we??™re on the search results page, we retrieve the search string and the AllWords value from the query string.
These will be read and displayed by the search_box.tpl template:
elseif (isset ($_GET['SearchResults']))
{
$this->mSearchString = trim(str_replace('-', ' ', $_GET['SearchString']));
$this->mAllWords = isset ($_GET['AllWords']) ? $_GET['AllWords'] : 'off';
}
CHAPTER 8 ?–  SEARCHING THE CATALOG 241
In the end, SearchBox verifies the current page is a product details page that was reached from a search results
page.


Pages:
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355