PHP - How Can I Cache More Than Just Simple Variables In The Environment?
What's the best way to cache things on the server? I've found some SetEnv things but this all seems to be a single key/value.
I'd like to cache an array of things that I can access later. Right now it's cached in $_SESSION which is fine, but still there's overhead on every first-time visitor to a site. Is there a way to add something to $_SERVER or elsewhere that ALL visitors to a website will ultimately be able to access?
I guess I want something like web.config in C#, where the first time a page is visited, the "app starts", as it were, and those things are now in cache on the server.
What's the best way to do this?
Similar TutorialsWhat I have done in the past is created a conn.php file, used as an include, when I wish to connect to my DB. As a security measure, rather than have my connection info in a file that could potentially get accessed by unauthorised users, I read that I could use environment variables and store the database connection string values i.e username, password etc for retrieval. Can anyone offer some guidance on going about this? Thanks I am by no means a security expert, but I would like to know if storing MySQL database information in an environment variable would be a good or bad idea. What are your thoughts? Not asking you to troubleshoot for me but to pop in any thoughts you might have on how YOU would troubleshoot this problem.. Thanks
This is a wp site.. and generated the following error.. Notice: Undefined index: USER_AGENT in /home/luxuryrealtygrp/public_html/wp-content/plugins/LRG/Masked/Filters.php on line 31 This is what line 31 that is being called out: Line 31: function lrg_masked_field($false, $field_name){ if(is_user_logged_in() || stripos($_SERVER['USER_AGENT'], 'google') !== false || stripos($_SERVER['USER_AGENT'], 'yahoo') !== false || stripos($_SERVER['USER_AGENT'], 'bing') !== false){ return false; }
Just looking for ideas that might help to chase this down..
Edited December 17, 2020 by tommytx I've googled a lot but still can't find much of a clue for how to do this (printing all environment variables in PHP that is). I know it has something to do with $_ENV and $_SERVER but... I would be thrilled for some guidance! Best regards, Rasekamon Hi guys, I'm currently in the process of making a simple social networking type site for a uni project and have basically everything i want except the ability to use AJAX to link to my profiles in the search bar. I have this code to generate my XML: Code: [Select] <?php // create simplexml object $xml = new SimpleXMLElement('<rss version="2.0"></rss>'); // add channel information $xml->addChild('channel'); $xml->channel->addChild('title', 'The Social Network'); $xml->channel->addChild('link', 'http://reecesayer.com/projects/template/XML/news.rss'); $xml->channel->addChild('description', 'example'); // query database for article data include("phpfunctions.php"); db_connect(); $link = "www.reecesayer.com/projects/template/testprofile.php?id="; $select='SELECT email, id FROM users'; $result = mysql_query($select) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { // add item element for each article $item = $xml->channel->addChild('item'); $item->addChild('email', $row['email']); $item->addChild('link', $row['id']); //I wanted to add a link before the $row['id'] } // save the xml to a file $xml->asXML('profiles.xml'); header ('Location: http://reecesayer.com/projects/template/XML/profiles.xml'); ?> I need to add a partial URL (http://reecesayer.com/projects/template/testprofile.php?id=) before the row is called so that when the email is searched it provides a link to the profile depending upon the id (http://reecesayer.com/projects/template/testprofile.php?id=8) Is there an easier way to do this or am i going the long way around? I'm only storing the data in XML as i saw a tutorial for a livesearch script on another site. Cheers, Reece Sorry for my noob question, I've learned about sessions a bit and tried to make a simple "game", basically a user has to enter one of the colors of the rainbow and after they name all 7, they win. Sounds simple enough, but I'm clearly making an obvious mistake and I've googled and read and experimented, but obviously something is alluding me. Here is the pastebin: http://pastebin.com/XmN4YLp8 I suppose what I want to know is...how do I store the values from the form (that is, $_POST['color']) and save that information to something like an array, because whatever I'm doing now is resetting the counter ($_SESSION['left']) and if a user guesses "red" for instance, it temporarily goes from 7 to 6, but then bumps up to 7? Hi,
I hope this belongs to the right sub-forum.
I'm gonna be on the move for quite some time, and I was wondering if there was an [almost] ideal portable PHP development environment, which I can treat just like the non-portable counterpart, which will include using Composer, Laravel, etc.
With a little research I found http://zwamp.sourceforge.net/ and http://www.codelobster.com, but I'm not sure how efficient they are.
Any of you guys use this approach?
Thanks.
I am trying a very simple thing , just to run an exe on local WAMP environment.The code below launches does launch notepad(can see in task manager) but doesn't show up.I want test.txt to be opened in a window. <?php $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run("notepad.exe C:\wamp\www\test.txt", 3, true); ?> I have tried exec as well .Same problem.What modifications are needed? My local IT department is migrating to a "hardened" LAMP/PHP environment. The PHP application at http://library.uww.edu/php/showrp.php is being moved to this new "hardened" environment and the "Title/Subject/Issue:" search option does not work in this environment. The "Title/Subject/Issue:" search option does however work within the "non-hardened" environment at http://library.uww.edu/php/showrp.php. Attached is the source code for the showrp.php. What is likely causing the failure of the "Title/Subject/Issue:" search option. 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 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? 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"); } ?> 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 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? 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! 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 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 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>"); } I want to set the correct header / cache values for a site. I am working on a social network / forum style site. I want to ensure that every page a user requests results in a fresh one being requested from the server as most content changes by the minute. (1) How would I set this? (2) Also, can I prevent nav bars being reloaded as these never, ever change. |