PHP - Redirect After Deletion Of Comment And Timestamp Update = No Cache Revalidation
I'm having a problem with a bit of code, which works for everything else, but just doesn't work when used for deletion of comments.
The relevant code: Code: [Select] mysql_query("UPDATE $table SET LastEdited = '$time' WHERE PID = '$ID'", $Connection) or die(mysql_error()); header('Location: /'. $URL;This works, the resource is getting updated. What doesn't work is the revalidation after the redirect. The code I'm using for caching is: Code: [Select] header("Cache-Control: must-revalidate"); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $Header['LTIME'])." GMT"); header("Etag: $etag"); header('Content-type: text/html; charset=UTF-8'); if ((@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $Header['LTIME']) && ( trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { header("HTTP/1.1 304 Not Modified"); exit; } Its the exact same code used when posting comments on the site, aside from the query of cause. What i don't get, is why i have to hit update in my browser, to get it to re-validate. The $etag will only be updated if the sites source have been changed. Similar TutorialsI can't get my Updated On timestamp to work in the following query... Code: [Select] // ****************************** // Create Temporary Password. * // ****************************** $tempPass = substr(md5(uniqid(rand(), true)), 3, 10); // Build query. $r = "UPDATE member SET pass=?, updated_on=? WHERE email=? LIMIT 1"; // Prepare statement. $stmt2 = mysqli_prepare($dbc, $r); // Bind variables to query. mysqli_stmt_bind_param($stmt2, 'sss', $tempPass, NOW(), $email); // Execute query. mysqli_stmt_execute($stmt2); I used similar code for an INSERT and it worked fine?! Now sure what is going on here... Debbie CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please Are PHP sessions automatically destroyed after you close the browser, or they stay on server for ever, and are later accessible by id? (in case you do not destroy them before the browser exit). Thank you Hi, i have delete link for records and it goes to other page to delete all related records in tables. is there away to get confirmation before the delete process starts? <?Php include('session.php'); include('dbcon.php'); if(isset($_GET['Del'])) { $userid = $_GET['Del']; $query = "delete from staff where OracleID='".$userid."'"; $result = mysqli_query($con,$query); if($result) { echo "staff deleted"; } else { echo 'check the errors!'; } $query2 = "delete from attendance_records where OracleID='".$userid."'"; $result2 = mysqli_query($con,$query2); if($result2) { echo "records deleted"; } else { echo 'check the errors!'; } header("location:viewstaff.php"); } else { header("location:viewstaff.php"); } ?> how to add confirm message with php before deletion is processed? Hey, I've got an upload site where you can upload files and you get a direct link. I was wondering if it would be possible to offer a delete link too, where if you went to the link it would delete your file? Thanks. hi..i am creating an app for a school...registration is happening but deletion and updation is not This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322815.0 I'm building a site similiar to a web forum.
The code is all done, this is how it works:
CREATING POST:
------------------------
In PHP: Create Post -> Upload Images -> Remake Images (For security) -> Create Thumbnails (saved in uploads folder with unique name) With DATABASE: I have a table called "images" which tracks user uploaded images: uploaded_by_username (stores who posted it) image_status (tracking whether user aborted upload) thumbnail_confirm (tracking whether thumbnail generated successfully) post_association (tracking the post that the images go to) image_name (the image filename in uploads filefolder) time (unix time-stamp of upload tracking for admin purposes) DELETING POST: ------------------------ In PHP: Move all images into a "deleted_images" folder ( I'm afraid to use "unlink") With DATABASE: Delete all associated images from images table ( Is this risky? Should I use a second table and transfer the images? ) Anyhow, feedback appreciated in regards to how I designed this. Is this acceptable for the industry? Code: [Select] <form name="commentbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <textarea name="comment" cols="20" rows="2" onclick="document.commentbox.comment.value='';" onfocus="this.style.borderColor='yellow';" onblur="this.style.borderColor='blue';" />Comment...</textarea> </td></tr> $commentcheck = $_POST['comment']; if ($commentcheck == "Comment...") { die(' <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\"> '); }else why does this not refresh if i comment "Comment..." it just dies and doesnt echo anything Hi, I am looking for reliable, effective code to cache one or two of my website webpages. I know there are packages like the pear cache lite but is far beyond my needs and complex in terms of never used pear before etc. I am looking for a good cache class perhaps or a link to a good cache script. Does anyone have any code they would like to share or know of any good cache classes etc? I want to keep it relatively simple if possible. Thanks for any suggestions, help. PHPLOVER I have a question about caching files, the way i have seen people do it on tutorials is they save the file to a cache/ folder if non exists, then check if it exists when the page loads so if it doesn't then load the file normally or if it does then include the cache/file but what is the difference? if the browser has to load the file every time someone goes to it so you cache it for better performance isn't including the cache/file just the exact same thing? the server still has to download the included cached file. I run an image hosting site and it's using a lot of resources. I temporaly disabled the images by using this code: <?php $myImage = imagecreatefromjpeg('ua.jpg'); header("Content-type: image/jpeg"); imagejpeg($myImage); imagedestroy($myImage); ?> I redirected all images to one, but he server still getting high loads. Is there a way to cache this image so it doesn't use many resources? Hi Guys
I have recently been looking into implementing browser caching after reading this: https://developers.g...ctices/caching
There are a few things in that google article that don't make much sense to me so I'm hoping someone can clarify.
Firstly Question
The document says:
" we recommend that you configure your web server to explicitly set caching headers and apply them to all cacheable static resources"
This implies you can set caching headers for just some resources. How would you do this? Lets assume I only wanted to set caching headers for a file styles.css - would I need to output headers within the CSS file and then change the extension to .php? e.g.
<link rel="stylesheet" href="styles.php"/>Second question Etags have me very confused. How would you set etag headers for specific files and then generally? And if you set the etag in the header of the main php page does that mean everything gets cached? Any help someone can provide would be very, very welcome! Drongo Ive been using no cache at the very top of my page and then using a header with a number in the link Code: [Select] <?php header("Location: settings.php?change=3"); ?> so the form updates after submit Then I have a if statment to echo that form was submited Any better ideas on how I can do this? Shouldnt I beable to just use no cache and use a standard echo in the form with no header in the form the problem with the way im doing it now if user keeps refreshing the screen it keeps saying the echo. which makes sense maybe its cause im not using the action in my form correctly with putting a link there? small example below Code: [Select] <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); if(isset($_GET['change'])) { echo "form submited";} if(isset($_POST['build_naq'])) { if(!empty($_POST['stargate_naq'])) { mysql_query("UPDATE settings SET naq= '".mysql_real_escape_string($_POST['naq'])."'"); } header("Location: settings.php?change=3"); } ?> I need to know when a file was last modified to see if the browser has an updated cached version, if the browser does use its cache otherwise get the most current version. How can I do this? Hi, I have a question. is that code below made a problem in google search, mean if I put this codes in header did google find my homepage? header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); Thnx. T I've tried to disable caching of HTML for certain pages but they seem to prevent the storing of the php sid cookies. Is there any way to prevent caching and keep cookie? I did some research on the topic and came across no-cache='set cookie' but the description of that directive seems opposite my need. Help is a greatly appreciated! I have some JavaScript that sends an AJAX request to the following PHP script every 4 seconds. The idea behind this is that every 4 seconds a new, randomly generate piece of content is loaded. This works fine in Firefox and Chrome, however when I test it in IE it seems to just load the same piece of content over and over again. I'm pretty sure there is nothing wrong with the script so could this be something to do with IE caching the first piece of content returned? Thanks for any help. $random_number = 0; $random_number = rand(1,6); if ($random_number == 1 ) { echo("<a href=\"\"><h4>Aliquam erat volutpat. Vivamus feugiat tempor quam, faucibus elementum.</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae ante at erat tempor facilisis. Quisque blandit faucibus suscipit. Proin suscipit est sed. </p></a>"); } if ($random_number == 2) { echo("<a href=\"\"><h4>Quisque ac lacus nibh, ac semper ante. Sed imperdiet.</h4><p>Vestibulum aliquam pellentesque lacus quis mollis. Proin quis lobortis libero. Ut nec tempor lectus. Pellentesque habitant morbi tristique senectus et netus id. </p></a>"); } if ($random_number == 3) { echo("<a href=\"\"><h4>Suspendisse vestibulum dui augue, nec viverra erat. Proin id.</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu sollicitudin elit. Cras mauris mi, luctus non luctus quis, tristique vitae turpis turpis duis. </p></a>"); } if ($random_number == "4") { echo("<a href=\"\"><h4>Vestibulum gravida elit posuere arcu.</h4><p>Phasellus sit amet rutrum purus. Cras vulputate pretium quam eleifend viverra. Morbi convallis eros ac tellus suscipit nec euismod nibh semper. In quam posuere. </p></a>"); } if ($random_number == "5") { echo("<a href=\"\"><h4>Vestibulum ante ipsum primis in.</h4><p>Aliquam consectetur aliquet libero. Mauris malesuada tortor eu ipsum mollis sit amet blandit erat sollicitudin. Cras consequat dui ac elit semper pharetra amet. </p></a>"); } if ($random_number == "6") { echo("<a href=\"\"><h4>Nam ornare, nisl non interdum aliquam, erat urna consequat elit, vel.</h4><p>Nulla ut libero est, eu convallis urna. Nullam fringilla mollis ligula, id fringilla enim sagittis non. Nunc lectus nunc, condimentum eget imperdiet massa nunc.</p></a>"); } Does anyone know how to cache Tweets as to not reach the API rate limit? I am using the Twitter-provided widget to display multiple profiles on a website, but the API hits the limit of 150 per hour. Is there any way to cache the Tweets and still use this widget? Or does anyone know of a good widget that caches, or simple code? If anyone knows, please explain in newbie terms. Thanks a lot! |