php - Script works in browser only when I hit F5 -


my script works in browser when hit f5. previous result seem cached or something.

this how looks like:

http://mywebsite.com/unsubscribe.php 

this causes serious problem. have unsubscribe link in email want send out users when click it, nothing happens, because click considered same when hit enter in browser. though have parameter in link as

http://mywebsite.com/unsubscribe.php?email=tom@gmail.com 

the value not captured.

$email = $_get['email']; $newsletter = 'no';       try {         $stmt = $conn->prepare("update users set newsletter = ? email = ?");         $stmt->execute(array($newsletter, $email));         $response["success"] = 1;         } catch(pdoexception $e) {         echo 'error: ' . $e->getmessage();         $response["success"] = 0;     }     echo 'email: '.$email.'<br>';     print(json_encode($response)); 

result:

email: tom@gmail.com {"success":1} 

but because tom@gmail.com cached (or else) value not updated in database. when hit f5, value updated in database. what's wrong?

if problem cache, should add headers remove cache. then, should send whole valid json! (you added unvalid part text).

headers:

header('cache-control: no-cache, must-revalidate'); header('expires: mon, 26 jul 1997 05:00:00 gmt'); header('content-type: application/json');//*/ 

simple json php -if use method, automatically sends headers-

include('includes/json.php');  $json = new json();  $email = $_get['email']; $newsletter = 'no'; try {     $stmt = $conn->prepare("update users set newsletter = ? email = ?");     $stmt->execute(array($newsletter, $email));     $response["success"] = 1;     } catch(pdoexception $e) {     echo 'error: ' . $e->getmessage();     $response["success"] = 0; }  $json->add('status', '200'); $json->add('message', '$success'); $json->add('email', '$email'); $json->add('response', '$response');  $json->send();   

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -