Looktrne Posted March 12, 2009 Share Posted March 12, 2009 Oh I run a member search on my site. the first page is always good results. the second page and so on is good results until I repeat the search. after the search is run twice all pages past the first no longer pull the proper search_query. they just pull all members it seems the session search_query is not storing properly the funny thing is it works fine on the initial search but after that goes crazy. please any ideas on this would be greatly appreciated. here is the code: the form first: <form action="index.php?page=search&search_type=quick_search&action=process_search" method=post> <tr> <td colspan="2" style="padding-top:10px;"><div class="headline_w">Quick Search</div></td> </tr> <tr> <td width="100" class="w">I am a</td> <td width="130">{QUICK_SEARCH_GENDER}</td> </tr> <tr> <td class="w">seeking a</td> <td>{QUICK_SEARCH_LOOKING_FOR}</td> </tr> <tr> <td class="w">between ages</td> <td>{QUICK_SEARCH_AGE_FROM}</td> </tr> <tr> <td class="w">and</td> <td>{QUICK_SEARCH_AGE_TO}</td> </tr> <tr> <td class="w">Photos only</td> <td><input type="Checkbox" name="search_piconly" checked></td> </tr> <tr> <td> </td> <td><input name="imageField" type="image" src="images/en/button_search.gif" width="55" height="20" alt="Search" border="0"></td> </tr> </form> now the page that is called by the form it is quite long but I know only some of it is relevant to my problem so if you could please take a glance.. thanks <? $sql_sort_by = " ORDER BY m.login ".($search_sort_by_ad == "Ascending" ? "ASC" : "DESC"); if($action == process_search) { // Collecting search tokens & search tables $sql_from = "dt_profile AS p, dt_members AS m"; $sql_where = ""; $sql_vars = "*, p.name, p.gender, p.country, m.age"; if ($_SERVER['REQUEST_METHOD'] == "POST" || $_SERVER['REQUEST_METHOD'] == "post") { foreach($_SESSION as $k => $v) { if(substr($k, 0, 7) != "search_") continue; $_SESSION[$k] = ""; } } switch($search_type) { case easy: case quick_search: foreach($_POST as $k => $v) { if(substr($k, 0, 7) != "search_") continue; $_SESSION[$k] = $v; } $nWas = 0; if($search_gender != "") { if ($search_looking_for != "") { $sql_where = "p.looking_for='$search_gender' AND p.gender='$search_looking_for' "; } else { $sql_where = "p.looking_for='$search_gender' "; } $nWas = 1; } if($search_age_from != "") { $sql_where .= ($nWas ? "AND " : "")."m.age>='$search_age_from' "; $nWas = 1; } if($search_age_to != "") { $sql_where .= ($nWas ? "AND " : "")."m.age<='$search_age_to' "; $nWas = 1; } if($search_city != "") { $sql_where .= ($nWas ? "AND " : "")."p.city LIKE '%$search_city%' "; $nWas = 1; } if($search_state != "") { $sql_where .= ($nWas ? "AND " : "")."p.state LIKE '%$search_state%' "; $nWas = 1; } if($search_country != "") { $sql_where .= ($nWas ? "AND " : "")."p.country LIKE '%$search_country%' "; } if($search_radius != "" && $search_zipcode != "") { $search_zipcode = substr(trim($search_zipcode), 0, 5); $zip_lookup_query = "SELECT longw, latn FROM dt_zips WHERE zipcode = '$search_zipcode' "; $longlatn = q($zip_lookup_query); $longlatn = f($longlatn); if ($longlatn["longw"] != "") { $longitude = $longlatn['longw']; $latitude = $longlatn['latn']; } else { $longitude = 0; $latitude = 180; } $sql_where .= ($nWas ? "and " : "") . " SQRT(POWER(p.longitude - $longitude, 2) + POWER(p.latitude - $latitude, 2))*69 < $search_radius "; $nWas = 1; } if ($search_piconly != "") { $sql_where .= ($nWas ? "AND " : "")." f.member_id = p.member_id AND f.filename_1 <> '' AND p.member_id = m.id "; $nWas = 1; $sql_from = "dt_profile AS p, dt_photos AS f, dt_members AS m "; } else { $sql_where .= ($nWas ? "AND " : "")." p.member_id = m.id "; $nWas = 1; $sql_from = "dt_profile AS p, dt_members AS m "; } $query = "SELECT count(p.id) AS count1 FROM $sql_from WHERE (p.status='1' ".($sql_where == "" ? ")" : " AND $sql_where)"); $rec_count = f(q($query)); $rec_count = $rec_count["count1"]; $page_count = 0; if($records_per_page >= $rec_count) { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") $search_query = $_SESSION['search_query_save']; else $search_query = "SELECT $sql_vars, p.id, p.country FROM $sql_from WHERE p.status='1' ".($sql_where == "" ? "" : " AND $sql_where")." $sql_sort_by"; $_SESSION['search_query_save'] = $search_query; } else { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") { $page_count = $_SESSION['search_query_result_count']; settype($page_num, "integer"); if(!$page_num){$page_num++;} if($page_num > $page_count) { $page_num = $page_count; } $search_query = $_SESSION['search_query_save']; } else { $page_count = $rec_count / $records_per_page; $page_count = ceil($page_count); $_SESSION['search_query_result_count'] = $page_count; settype($page_num, "integer"); if(!$page_num){$page_num++;} if($page_num > $page_count) { $page_num = $page_count; } $search_query = "SELECT $sql_vars, p.id FROM $sql_from WHERE p.status='1' ".($sql_where == "" ? "" : " AND $sql_where")." $sql_sort_by"; } $from = ($page_num - 1) * $records_per_page; $_SESSION['search_query_save'] = $search_query; $search_query .= " LIMIT $from, $records_per_page"; } // Creating search query: $query = "SELECT count(p.id) AS count1 FROM $sql_from WHERE p.status='1' ".($sql_where == "" ? "" : " AND $sql_where"); $rec_count = f(q($query)); $rec_count = $rec_count["count1"]; $page_count = 0; } $profiles = q($search_query); $search_query_count = "SELECT count(p.id) AS count1 FROM $sql_from WHERE p.status='1' ".($sql_where == "" ? "" : " AND $sql_where"); $search_query_full = "SELECT $sql_vars, p.id FROM $sql_from WHERE p.status='1' ".($sql_where == "" ? "" : " AND $sql_where")." $sql_sort_by"; session_start(); $_SESSION[search_query_count] = $search_query_count; $_SESSION[search_query_full] = $search_query_full; $include_file = "templates/search_results.html"; } else if($action == save_search) { $f = f(q("SELECT id FROM dt_saved_searches WHERE search_name='$search_name' AND member_id='$fMember[id]'")); if($f[id] != "") { $message = "This search name already exists. Please enter a new search name.<br>\n"; } else { $t = time(); $search_query_full = ereg_replace("'", "\\'", $_SESSION[search_query_full]); $search_query_count = ereg_replace("'", "\\'", $_SESSION[search_query_count]); q("INSERT INTO dt_saved_searches (member_id, search_name, search_query_full, search_query_count, timestamp) VALUES('$fMember[id]', '$search_name', '$search_query_full', '$search_query_count', '$t')"); $message = "Search saved successfully.<br>\n"; } $search_query_count = stripslashes($_SESSION[search_query_count]); $search_query_full = stripslashes($_SESSION[search_query_full]); $rec_count = f(q($search_query_count)); $rec_count = $rec_count[count1]; $page_count = 0; if($records_per_page >= $rec_count) { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") $search_query = $_SESSION['search_query_save']; else $search_query = $search_query_full; $_SESSION['search_query_save'] = $search_query; } else { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") { $page_count = $_SESSION['search_query_result_count']; settype($page_num, "integer"); if(!$page_num){$page_num++;} if($page_num > $page_count) { $page_num = $page_count; } $search_query = $_SESSION['search_query_save']; } else { $page_count = $rec_count / $records_per_page; $page_count = ceil($page_count); $_SESSION['search_query_result_count'] = $page_count; settype($page_num, "integer"); if(!$page_num)$page_num++; if($page_num > $page_count) { $page_num = $page_count; } } $_SESSION['search_query_save'] = $search_query_full; $from = ($page_num - 1) * $records_per_page; $search_query .= " LIMIT $from, $records_per_page"; } $profiles = q($search_query); $include_file = "templates/search_results.html"; } else if($mode == gallery || $mode == detail) { $search_query_count = $_SESSION[search_query_count]; $search_query_full = $_SESSION[search_query_full]; $rec_count = f(q($search_query_count)); $rec_count = $rec_count[count1]; $page_count = 0; if($records_per_page >= $rec_count) { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") $search_query = $_SESSION['search_query_save']; else $search_query = $search_query_full; $_SESSION['search_query_save'] = $search_query; } else { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") { $page_count = $_SESSION['search_query_result_count']; settype($page_num, "integer"); if(!$page_num){$page_num++;} if($page_num > $page_count) { $page_num = $page_count; } $search_query = $_SESSION['search_query_save']; } else { $page_count = $rec_count / $records_per_page; $page_count = ceil($page_count); $_SESSION['search_query_result_count'] = $page_count; settype($page_num, "integer"); if(!$page_num)$page_num++; if($page_num > $page_count) { $page_num = $page_count; } } $_SESSION['search_query_save'] = $search_query; $from = ($page_num - 1) * $records_per_page; $search_query .=" LIMIT $from, $records_per_page"; } $profiles = q($search_query); $include_file = "templates/search_results.html"; } else if($mode == saved_search) { $f = f(q("SELECT * FROM dt_saved_searches WHERE id='$id' AND member_id='$fMember[id]'")); $serach_query_count = stripslashes($f[search_query_count]); $search_query_full = stripslashes($f[search_query_full]); $message = $f[search_name]; $rec_count = f(q($serach_query_count)); $rec_count = $rec_count["count1"]; $page_count = 0; if($records_per_page >= $rec_count) { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") $search_query = $_SESSION['search_query_save']; else $search_query = $search_query_full; $_SESSION['search_query_save'] = $search_query; } else { if(isset($_SESSION['search_query_save'])&&$_SESSION['search_query_save']!="") { $page_count = $_SESSION['search_query_result_count']; settype($page_num, "integer"); if(!$page_num){$page_num++;} if($page_num > $page_count) { $page_num = $page_count; } $search_query = $_SESSION['search_query_save']; } else { $page_count = $rec_count / $records_per_page; $page_count = ceil($page_count); $_SESSION['search_query_result_count'] = $page_count; settype($page_num, "integer"); if(!$page_num)$page_num++; if($page_num > $page_count) { $page_num = $page_count; } } $_SESSION['search_query_save'] = $search_query; $from = ($page_num - 1) * $records_per_page; $search_query .= " LIMIT $from, $records_per_page"; } $profiles = q($search_query); $_SESSION[search_query_count] = $search_query_count; $_SESSION[search_query_full] = $search_query_full; $include_file = "templates/search_results.html"; } else { foreach($_SESSION as $k => $v) { if(substr($k, 0, 7) != "search_") continue; session_unregister($_SESSION[$k]); } $include_file = "engine/pages/easy_search.php"; } if(! e($profiles)) { if($mode != "gallery") { $new_mode = "gallery"; $search_results_header_image = "images/en/gallery_mode.gif" . '" width="136" height="20" border="0'; } else { $new_mode = "detail"; $search_results_header_image = "images/en/detailed_mode.gif" . '" width="143" height="20" border="0'; } if ($fMember[id]) { $save_search_content = ''; if($mode != saved_search && $id == "") { $save_search_content = parseVariables("templates/search_results_save_search_form_content.html",0); } } $change_mode_link = '<a href="index.php?page=search&mode='.$new_mode.'"><img src="'.$search_results_header_image.'"></a>'; $save_search_form = parseVariables("templates/search_results_save_search_form.html",0); } $npages = $page_count; $p = $page_num; if ($npages > 1) { $params = ""; $pages = ""; foreach($_GET as $k => $v) { if($k == "page_num") continue; $params .= "$k=$v&"; } $pages .= "Result Page:"; if ($p != 1) $pages .= '<a href="index.php?'.$params.'page_num='.($p-1).'"><b>'."Previous".'</b></a> '; $lend = floor($p/10)*10; if ($lend < 1) $lend = 1; if ($npages > 19) { $hend = $lend + 19; if ($hend > $npages) $hend = $npages; } else $hend = $npages; for ($i = $lend; $i <= $hend; $i++) { if ($i == $p) $pages .= $i." "; else $pages .= '<a href="index.php?'.$params.'page_num='.$i.'">'.$i.'</a> '; } if ($p != $npages) $pages .= ' <a href="index.php?'.$params.'page_num='.($p+1).'"><b>'."Next".'</b></a> '; } $search_results_pages = ""; if($pages) { $search_results_pages = parseVariables("templates/search_results_pages.html",0); } $search_results_content = ""; if(e($profiles)) { $search_results_content = parseVariables("templates/search_results_no_profiles.html",0); } else { //Set if the viewing user can send/receive IMs if($fMember["unlimited"]==1 && $fMember["unlimited_end"] > time()) $i_can_im = 1; else $i_can_im = 0; while($profile = f($profiles)) { $age = $profile["age"]; $member_code = sysGetProfileCode($profile[ id ]); $profile[ marital_status ] = f(q("SELECT name FROM dt_marital_status WHERE id='$profile[marital_status]'")); $profile[ marital_status ] = $profile[ marital_status ][ name ]; $profile[ country ] = f(q("SELECT name FROM dt_countries WHERE id='$profile[country]'")); $profile[ country ] = $profile[ country ][ name ]; $profile[ general_info ] = substr($profile[ general_info ], 0, 250).(strlen($profile[ general_info ]) > 250 ? "..." : ""); if($censor_on) { $qWords = q("SELECT name FROM dt_badwords"); while($fWords = f($qWords)) { $replace = ""; for($i = 0; $i < strlen($fWords[name]); $i++) $replace .= "*"; $profile[general_info] = eregi_replace($fWords[name], $replace, $profile[general_info]); } } $f = f(q("SELECT login, reg_date FROM dt_members WHERE id='$profile[member_id]'")); $member_name = $f[login]; $reg_date = $f[reg_date]; if($reg_date > time() - ($new_timelimit*24*60*60)) $new_icon = '<img src="'."images/en/new.gif".'">'; else $new_icon = ""; $fUsersOn = f(q("SELECT id FROM dt_usersonline WHERE userid = '$profile[member_id]'")); if ($fUsersOn["id"] != "") { $online_status = "<b><font color=red>"."Online Now!"."</font></b>";} else if (time() - $profile["lastlogin"] > 0) { if (time() - $profile["lastlogin"] < 3600) { $online_status = "Within 1 Hour";} else if (time() - $profile["lastlogin"] < 7200) { $online_status = "Within 2 Hours";} else if (time() - $profile["lastlogin"] < 10800) { $online_status = "Within 3 Hours";} else if (time() - $profile["lastlogin"] < 86400) { $online_status = "Within 24 Hours";} else if (time() - $profile["lastlogin"] < 172800) { $online_status = "Within 2 Days";} else if (time() - $profile["lastlogin"] < 259200) { $online_status = "Within 3 Days";} else if (time() - $profile["lastlogin"] < 345600) { $online_status = "Within 4 Days";} else if (time() - $profile["lastlogin"] < 432000) { $online_status = "Within 5 Days";} else if (time() - $profile["lastlogin"] < 518400) { $online_status = "Within 6 Days";} else if (time() - $profile["lastlogin"] < 604800) { $online_status = "Within 1 Week";} else { $online_status = "";} } else { $online_status = "More Than 1 Week";} $pr = f(q("SELECT * FROM dt_privacy WHERE member_id='$profile[member_id]'")); $fOnline = f(q("SELECT id, userid FROM dt_usersonline WHERE userid=$profile[member_id]")); //Set if this user returned in the result can send/receive IMs $thisMember = $profile["member_id"]; $fMemberInfo = f(q("SELECT unlimited, unlimited_end FROM dt_members WHERE id='$thisMember'")); if( $fMemberInfo["unlimited"]==1 && ($fMemberInfo["unlimited_end"]>time()) ) $can_be_imed = 1; else $can_be_imed = 0; if($mode != gallery) { $profile_id = $profile[ id ]; $profile_name = $profile[ name ]; $profile_gender = convertGender($profile[gender]); $profile_marital_status = $profile[marital_status]; $profile_city = $profile[city]; $profile_state = $profile[state]; $profile_country = $profile[country]; $general_info = wordwrap($profile[ general_info ],65, "<br>\n", 1); if ($piconly == "") { $fPhoto = f(q("SELECT filename_1 FROM dt_photos WHERE member_id='$profile[member_id]'")); $fPhoto = $fPhoto[filename_1]; } else $fPhoto = $profile[filename_1]; if($fPhoto != ""){ $profile_image = sysGetThumbnail("photos/$fPhoto"); } else { $profile_image = '<img src="images/default_photo.gif" border="0" width="100" height="100">'; } //Check to see if IM is allowed, The person viewing the search results and this particular search result must both be able to IM or IM for nonpaying //members must be turned on for this to be true. Also checks this search result's privacy settings, IMs must not be blocked for IMs to be allowed if (($fOnline[id] != "" && $pr[iM_yn] != 'Y' && $sAuth != $fOnline[userid] && (($can_be_imed==1 && $i_can_im==1)|| $free_im == "on"))) { $profile_im = '<a href="javascript:var newim = window.open(\'im.php?action=message&rid='.$fOnline[userid].'\', \''.$fOnline[userid].'\', \'scrollbars=yes,menubar=no,resizable=0,location=no,screenX=50,screenY=100,width=423,height=550\')" class="e">'; $profile_im .= '<img src="images/im_small.gif" alt="Instant Message" border="0">'."instant message".'</a>'; } else { $profile_im = '<img src="images/im_small_gray.gif" alt="Instant Message Unavailable" border="0">'."instant message"; } $search_results_content .= parseVariables("templates/search_results_detail_mode.html",0); } else { $profile_id = $profile[ id ]; $profile_name = substr($profile[name], 0, 20); $profile_name .= ((strlen($profile[name]) > 20) ? "..." : ""); if($no_of_column == 0) { $search_results_content .= "<table>\n<tr>\n"; } if ($piconly == "") { $fPhoto = f(q("SELECT filename_1 FROM dt_photos WHERE member_id='$profile[member_id]'")); $fPhoto = $fPhoto[filename_1]; } else { $fPhoto = $profile[filename_1]; } if($fPhoto != "") { $profile_image = '<a href="index.php?page=view_profile&id='.$profile[ id ].'">'.sysGetThumbnail("photos/".$fPhoto).'</a>'; } else { $profile_image = '<a href="index.php?page=view_profile&id='.$profile[ id ].'"><img src="images/default_photo.gif" border="0" width="100" height="100"></a>'; } $search_results_content .= parseVariables("templates/search_results_gallery_mode.html",0); $no_of_column++; if($no_of_column == 3) { $no_of_column = 0; $search_results_content .= "</tr>\n</table>\n"; } } } if($no_of_column > 0) { $search_results_content .= "</tr>\n</table>\n"; } } if($pages) { $search_results_footer = parseVariables("templates/search_results_pages.html",0); } if($include_file == "engine/pages/easy_search.php") { include($include_file); parseVariables("templates/easy_search.html"); } else { parseVariables($include_file); } ?> if you have a solution for this please let me know.... I would be willing to reward you for your time. Paul Quote Link to comment https://forums.phpfreaks.com/topic/149109-sessions-only-working-on-first-try-any-help-would-be-great/ Share on other sites More sharing options...
premiso Posted March 12, 2009 Share Posted March 12, 2009 Your not using session_start at the top of your code where you wish to use sessions. This is a requirement on any page sessions are to be used. It must be placed at the top before any output is sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/149109-sessions-only-working-on-first-try-any-help-would-be-great/#findComment-782950 Share on other sites More sharing options...
medaswho Posted March 12, 2009 Share Posted March 12, 2009 I agree with PERMISO, i suggest starting session at the beginning of the script. Quote Link to comment https://forums.phpfreaks.com/topic/149109-sessions-only-working-on-first-try-any-help-would-be-great/#findComment-782953 Share on other sites More sharing options...
Looktrne Posted March 12, 2009 Author Share Posted March 12, 2009 the session is started it is started in a index.php page this page is simply included after the session has been started. Paul Quote Link to comment https://forums.phpfreaks.com/topic/149109-sessions-only-working-on-first-try-any-help-would-be-great/#findComment-782975 Share on other sites More sharing options...
Looktrne Posted March 12, 2009 Author Share Posted March 12, 2009 please test my problem here go to http://discreet-cheaters-dating-site.com/index.php?page=search sign in as: paul pw: test run a search male seeking female click search 5 pages are normal repeat the search first page is normal clicking on second page ruins the results.. if I clear my cookies the search will then work normal again if anyone can help me fix this I will give you 50 thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/149109-sessions-only-working-on-first-try-any-help-would-be-great/#findComment-783001 Share on other sites More sharing options...
Looktrne Posted March 12, 2009 Author Share Posted March 12, 2009 I believe something is up with the initial php settings because the same script runs fine on different servers... please advise http://discreet-cheaters-dating-site.com/phpinfo.php Quote Link to comment https://forums.phpfreaks.com/topic/149109-sessions-only-working-on-first-try-any-help-would-be-great/#findComment-783013 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.