php - Setting and using newly set Cookie value -


Working on a site that displays different content based on cookie content. For example:

versus

This value can be set on any page because I have a job on each page. If the cookie is set or already saved, information has been loaded for that cu. If a cookie value is not set or the value is passed which is not present in DB, then the site displays the default information.

Here's the problem if you do not load the existing data until you refresh the current page if you do not set a cookie value to request a site with "? Cu = 10010" attached to any page Does.

I have read, I have to refresh the page using the header ("Location .... .... but I'm not sure if I want to do everything based on that cookie value

$ _ GET [ "cu"]) and amp; is_numeric ($ _ GET [ "cu"]] {$ Pass_cu = $ _GET [ "cu"]; see // if value passed is an active CU record mysql_select_d $ ($ Database_peewee, $ peewee); $ query_rs_valid_cu = "SELECT * fROM tbl_cus WHERE cu_id = $ pass_cu"; $ Rs_valid_cu = mysql_query ($ query_rs_valid_cu, $ peewee) or die (mysql_error ()); $ row_rs_valid_cu = mysql_fetch_assoc ($ rs_valid_cu ), totaling $ Rows_rs_valid_cu = mysql_num_rows ($ rs_valid_cu); if ($ totalRows_rs_valid_cu! = 0) {// set cookies $ peewee_cu_querystring = $ _GET [ "cu"]; $ expire_month = time () + 60 * 60 * 24 * 30 ; // 30 day / kill current cookie setcookie ("peveby_q", "", time () - 10); // Set new cookie set cookie ("payweb_qq", $ peveby_quarterstring, $ xpermoth, "/"); } Mysql_free_result ($ rs_valid_cu); } // Check out cookie is present (if (($ $ COOKIE [peewee_cu '])) & amp; amp; amp; $ _COOKIE [' peewee_cu '] = "") {$ cu_cookie_value = $ _COOKIE [' peewee_cu '] ; // Set the value to get the CU Records colname_rs_cu_data = $ cu_cookie_value; $ Load_custom_cu = 'true'; } Else {// set defualt CU value $ colname_rs_cu_data = 10000; $ Load_custom_cu = 'false'; } // Get CU Information (CU Specific or Default) and set mysql_select_db ($ database_peewee, $ peewee); $ Query_rs_cu_data = "SELECT * FROM tbl_cus WHERE cu_id = $ colname_rs_cu_data"; $ Rs_cu_data = mysql_query ($ query_rs_cu_data, $ peewee) or die (mysql_error ()); $ Row_rs_cu_data = mysql_fetch_assoc ($ rs_cu_data); $ Total Rows_rs_cu_data = mysql_num_rows ($ rs_cu_data); $ Cu_sidebar_image = $ row_rs_cu_data ['cu_logo']; $ Cu_sidebar_name = $ row_rs_cu_data ['cu_name']; $ Cu_sidebar_link = $ row_rs_cu_data ['cu_link']; $ Cu_sidebar_address = $ row_rs_cu_data ['cu_address']; $ Cu_sidebar_city = $ row_rs_cu_data ['cu_city']; $ Cu_sidebar_state = $ row_rs_cu_data ['cu_state']; $ Cu_sidebar_postal = $ row_rs_cu_data ['cu_postal']; $ Cu_sidebar_phone = $ row_rs_cu_data ['cu_phone']; $ Cu_sidebar_toll = $ row_rs_cu_data ['cu_phone_toll_free']; $ Cu_meta_title = $ row_rs_cu_data ['cu_name']; $ Cu_tab_title = $ row_rs_cu_data ['cu_name']; Mysql_free_result ($ rs_cu_data); // Set default error page for all pages except home page $ default_error_page = 10007; $ Default_error_page_home = 10005;

Thank you

Brett

again Loading page is for reading only in a cookie, whose value you know (because you set it right now) looks a little unnecessary

Instead, whatever you have to do, by the browser as sent to the current cookie value or is set to a variable ( $ _COOKIE [ 'peewee_cu'] ) or value Which lets you access that cookie on the current page Particular are ( $ peewee_cu_querystring ).

In a really simple way (but note: I do not particularly recommend writing superglosses, it is better to properly manage your own variables and scopes)

Incidentally, you do not need to kill the old cookie before setting a new cookie, because a new cookie with the same name, domain, and path will be automatically overwritten.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -