MainStWebGuy Posted July 14, 2009 Share Posted July 14, 2009 Hello all, I'm working on a website that i'd like to have dynamically served meta tags based on the search query they've entered on a search page of my site, but i'm hitting a wall. My search page is pretty simple and when searched will display a search results page with a URL like this: http://www.MySite.net/search.php?q=auto%20repair%20<myCity> each of the pages of the search result (and the site for that matter) have an include pointing to the following file: brains2.php <?php $referer = $_SERVER[HTTP_REFERER]; if($referer) { //if referer exists preg_match("/[\&\?]q=([^&]*)/", $referer, $matches); //search for special chars in the referer and //create an array of all the matches ($matches) if($matches[1]) { //if matches exist $search_query = rawurldecode($matches[1]); //replace things like "%20" and "%40 with " " and "@" //and assign the new value to $search_querry $search_query = str_replace("+", " ", $search_query); // replace plus sighns with spaces //and assign the new value to $search_querry } $dbcnx = @mysql_connect('myHost', 'myUser', 'myPassword'); //connect to database server if (!$dbcnx) { echo '<p>'.'Unable to connect to database server'.'</p>'; exit(); } if (!@mysql_select_db('seo')) { //select the database exit ('<p>'.'unable to connect to the database'.'</p>'); } $result = @mysql_query('SELECT city FROM citynames where city in '.$search_query); //query the database to get the city names if ($result) { $city = $result; setcookie('cityname', '$result'); } } else { $city="City1, City2, and City3"; setcookie('cityname', '$city'); } ?> The basic idea is that the user will click on a search result that will dynamically change the city refered to in the meta tags and content by calling the variable $city that's stored in the cookie (created by 'brains2.php'). Obviously, this isn't working... i can't seem to get the variable '$search_query' to hold a value... what am i missing here? Is there any flaws in my logic? Thanks guys and gals! Your help is always appreciated! J Quote Link to comment https://forums.phpfreaks.com/topic/165922-http_referer-and-query-strings/ Share on other sites More sharing options...
premiso Posted July 14, 2009 Share Posted July 14, 2009 Try using all the parameters for setcookie or use session instead. If you choose to use session remember to call session_start. Also using @ on the mysql statements supresses the errors. So if there is an error causing the problem you will never know. One other item, I would change this: $referer = $_SERVER[HTTP_REFERER]; to $referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:false; Quote Link to comment https://forums.phpfreaks.com/topic/165922-http_referer-and-query-strings/#findComment-875157 Share on other sites More sharing options...
MainStWebGuy Posted July 14, 2009 Author Share Posted July 14, 2009 Thanks a bunch! I'll take your suggestions and go from there. Much appreciated! J Quote Link to comment https://forums.phpfreaks.com/topic/165922-http_referer-and-query-strings/#findComment-875270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.