PHP - Domain Forwarding And Caching Them
I have a client, that wants an affiliate driven service, which is fine. However they want to offer the affiliates the ability to forward there own domains to the service and have that work as the initial affiliate id token. Now my question is. I know I can find what the domain is that the scripts I am writing run off of using $_SERVER['HTTP_HOST'] however I'm not to sure how that would work for a domain that is forwarded with a 301 or 302 redirect status and masked for use on the service I am building up. I want to say I could use $_SERVER['HTTP_REFERER']. But as I said I'm not to sure how thats going to work for a forwarded domain thats masked as its not part of the actual host conf files its landing on in the end.
Hopefully I am making sense with the above. So what would be my best choice of options to work with when handling a domain that will be masked and landing on another domain as it will be forwarded. I am only taking the inital landing with a domain and setting the tokens I need set for it to run as that affiliate and setting them in sessions and cookie and various other variables. But I guess I am just wondering which would be better for me to catch that inital landing with the domain thats forwarded. Similar TutorialsI have two domains both running SSL. Let's call them old-domain and new-domain. old-domain is permanently redirecting traffic to new-domain. There are still a lot of links out there to old-domain with https://. If I were to remove SSL from old-domain but keep SSL on new-domain, I am betting that users will be getting some sort of certificate error. Right? Any way around that if I want to remove SSL from old-domain?
Hi Is there another function then header() in php for forwarding? This topic has been moved to the corner of 3rd Avenue and mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359430.0 How is it that a site can forward to my site without a trace? www.2mysite.com is forwarding traffic to www.mysite.com but $page_name = $_SERVER['HTTP_REFERER']; echo $page_name; does not show www.2mysite.com as the referring site...how does one hide this? Help? Hi all. I am in need of some help with a simple page search function. In short what i need is a way the user can search for a specific page name from the home index page. My site (local for now) will be constructed as follows: localhost/mysite/index.html 0001.html 0002.html ... 0132.html etc... The subpages will be added/modified externaly and may run into the hundreds of pages. For this reason mySQL will be hard to implement and somewhat overkill especialy for this simple search function. So, is there a way i can type the page to look for "0132" into the field and be forwarded onto the searched page "0132.html" I realise i could just type mysite/0132.html but the page may or may not exist and searching would be tiny bit more elegant. Simple for you guys i expect but im at a loss as all search functions use mySQL in addition. Many thanks for your help in advance! Regards, Matt.
Some background we are creating a system that collects rain data from multiple sensors and then every 15 mins sends a packet to the main server. I have been ingesting this data fine and storing the info into my database and storing a local .txt file of the packet. To forward this packet to our back up server I have been using: shell_exec("nc backup_server_address < ".$my_p); Where $my_p is the location of the .txt file. However, I have been requested to not use nc as it creates its own process every time it is called and for scalability issues we would like to forward the packet using PHP and not require a new process every time we receive a packet. I tried do some redirect stuff using headers("Location: backup_server_address"). If anyone can help that would be greatly appreciated. I'm trying to create a simple session on a form page that determines if you've signed in. If you haven't, it kicks you to the login page. But for some reason, what I have isn't doing that. When I open the page, it loads, but only prints the url on a blank page, instead of actually going to the url. Code: [Select] <html> <title>form</title> <link rel="stylesheet" type="text/css" href="style.css"> <body> <?php session_start(); if(isset($_SESSION['id']) && is_numeric($_SESSION['id'])) { if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['scientific_name'])) { $errors[] = 'you forgot to enter the scientific name'; } else { $sn = trim($_POST['scientific_name']); } if (empty($_POST['common_name_english'])) { $errors[] = 'you forgot to enter the common name'; } else { $cne = trim($_POST['common_name_english']); } $description4 = trim($_POST['common_names_spanish']); $description5 = trim($_POST['common_names_french']); $description6 = etc. etc. if (empty($errors)) { require_once ('3_z_mysq1_c0nn3ct.php'); $query = "INSERT INTO plantae (scientific_name, common_name_english, etc.) VALUES ('$sn', '$cne', '$description4', '$description5', '$description6', '$description7', etc.)"; $result = @mysql_query ($query); if ($result) { if(isset($_POST['scientific_name'])) { $plant_id=mysql_insert_id(); } exit(); } else { echo 'system error. No plant added'; echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>'; exit(); } mysql_close(); } else { echo 'error. the following error occured <br>'; foreach ($errors as $msg) { echo " - $msg<br>\n"; } } // end of if } // end of main submit conditional echo '<form action="insertaplant1.php" method="post"><fieldset><legend><b>Enter your new plant here</b></legend> form fields here. </form>'; } else { $url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); if((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr($url, 0, -1); } $url .= '/login.php'; echo $url; exit(); } ?> Code: [Select] <form action="meetme.aspx" method="post" id="form1" name="form1"> <input type="hidden" name="add_id" value ="28667977"> <input type="hidden" name="next26" value ="26883214,28590733,28654666,28681535,27273243,28576166,28613584,28591951,28515273,28541847,18296015,28594117,27206532,21878719,28590233,28663167,5039360,28636411,28569000,28645007,28587048,28569415,7815397,26626891,28671149,28570991"> <input type="hidden" name="p_Id" value ="28667977"> <INPUT TYPE="image" SRC="image/yes.png" NAME="votea" VALUE="1 <INPUT TYPE="image" SRC="image/maybe.png" NAME="voteb" VALUE="2'> <INPUT TYPE="image" SRC="image/no.png" NAME="votec" VALUE="3"> </form> I got this from datesite, But it suits my needs for something else. Exclude the 3 link options, I just want to use one. as a Next page button. and another as a back pagebutton. I made pagination already but I dont want that, I noticed pagination always keeps the same page, and just adds page numbers. But the same original page. The code above im assuming will allow to move to next new entire page with the new metas, and title and be botted by the search engines as a separate pages. And also keeping track of the next pages in que out of the entire specified db. So the question above is.. is there a page/website/tutorial.. terminology for this? pagination is pagination, is this like "form forwarding?? or something" ...So I can use.. Code: [Select] $sql = "SELECT COUNT(*) as Num FROM `mydb` Where models = ' 2012' and have it list all the values of say 'models' but keep them in memory passing to the next page and the next until they have all been viewed. Sorry if what im typing is overkill and you already knew what I asking in the first view of the code above lol. lemme know thanks! Hello, I just had a quick question about caching when the compiler compiles php into assembly (or however this works with php). Anyways, is there any efficiency in doing this: $holder = strlen($anArray); for (i=0 to 100) echo $holder; Rather than this: for (i=0 to 100) echo strlen($anArray); ? If PHP is smart, then strlen($anArray) would be called once, and any subsequent calls to strlen($anArray) would just call a value stored in a cache. Is this how PHP works? Hi! I was little confused and i am not able to figure out how can i use caching server side and client side. How to use the caching using php. What I have, is a php page that runs over 60 query's a visit, and has over 2000 visits a day. That thousands of query's, and I'm sure this can be simplified easily to lessen the load. I only need to update the data on the page every 12 hours. So, what I'm thinking, is that it would be best to run the query based on time()(every 12 hours), and store that data in a .txt file. Then, the php file, instead of requesting the query over and over, it just extracts the data from the text file. Does this help me at all, or is it useless? is there a better method? Thanks! How can you prevent your browser from caching a page? I think that my news feed is being cached and is causing new posts to not be displayed even after a refresh. Eventually, the posts will show up after about 20 refreshes. I know my query is right so I didn't know if there was a way to stop page caching. I don't really know if it is a caching issue though. I'm starting to think I just have some weird bug in my code because sometimes on refresh news feed items get removed then i'll refresh again and some will get added back in then i'll refresh again and they'll all be there. Ever heard of this happening? Hi, just started experimenting with file caching after reading this article: http://www.rooftopsolutions.nl/blog/107 Aside from when dealing with data which changes frequently, I was wondering if it's ever inappropriate to cache your queries. For example, I have a page with a ridiculous number of queries, some of them have a resulting set which is not nearly as large as others. Page performance increased, just not to the level I had been expecting and I wondering if having Apache read each of these files for data is in fact faster than running a number of queries with only some data being cached. Hi I have a php script which allows me to upload images to my product page, when I select a image to copy it simply does a Code: [Select] copy(); function, followed by a Code: [Select] header("Location: products.php"); redirect This all works ok, but when the page reload, the image has not changed, if I refresh the page, it seems to load ok. So I think this is a image caching problem. Any ideas on how to solve this? Thanks let's say I have 100,000 users on my forum i want to cache there PROFILE INFO (About me) in .php files which is easy/etc but would that be more space than 100k rows in a db table, or 100k .php files? just wondering, prob a stupid question but atm I cache some lottery info and some other stuff, but that's only 1 .php it would be dumb to cache info and have 100k .php's for each user ID right? or maybe story it all in 1 .php? would be a HUGE Filesize? rather just keep the data in MYSQL right? I am using a cache script, well it writes a array to a file like this: Code: [Select] fwrite($fh, '<?php'."\n\n".'define(\'PUN_LOTTERY_LOADED\', 1);'."\n\n".'$lottery = '.var_export($output2, true).';'."\n\n".'?>'); output2 is Code: [Select] $result2 = $db->query('MY QUERY '); $output2 = array(); while ($cur_donors = $db->fetch_assoc($result2)) $output2[] = $cur_donors; Now, I want to ditch the mysql and I want to use this script with 7 variables that I already have loaded, so I dont need to use the mysql, how do I add my 7 variables to my var_export function instead of using mysql to loop them? <?php $myData = file_get_contents(""); $myObject = json_decode($myData); $myObjectMap = $myObject->result; ?> can i somehow build in that it only request every 5 minutes because if there are many users on the site it request too much? Hello, I am needing to cache a json response from an API so I am not making requests on each load. I have come across some code that is suppose to accomplish this but, it seems to not be working and can't figure out as to why. I created the cache file with 777 but it doesn't write or read from that file when I echo out the results.
The code below is just what is suppose to get the contents and cache it. At the end I tried to print it so I can test it to see it prints the response from the cache file but, nothing and the cache file does exists.
This is the first time I have tried something like this so please be gentle.
// cachePath is name of the path and file used to store cached current conditions gathered from the API request $cachePath = "./cache/nowcast-cache.txt"; // URL to the API request $url = "http://api.wunderground.com/api/XXXXXXXXXXXX/geolookup/conditions/q/TX/mesquite.json"; date_default_timezone_set('America/Chicago'); /** * Request jobs from API * * Split the request into smaller request chunks * and then consolidate them into a single array to limit the API * requests. */ function api_request() { file_put_contents($cachePath, file_get_contents($url)); } /** * API Request Caching * * Use server-side caching to store API request's as JSON at a set * interval, rather than each pageload. * * @arg Argument description and usage info */ function json_cached_api_results( $cache_file = NULL, $expires = NULL ) { global $request_type, $purge_cache, $limit_reached, $request_limit; if( !$cache_file ) $cache_file = dirname(__FILE__) . $cachePath; if( !$expires) $expires = time() - 2*60*60; if( !file_exists($cache_file) ) die("Cache file is missing: $cache_file"); // Check that the file is older than the expire time and that it's not empty if ( filectime($cache_file) < $expires || file_get_contents($cache_file) == '' || $purge_cache && intval($_SESSION['views']) <= $request_limit ) { // File is too old, refresh cache $api_results = api_request(); $json_results = json_encode($api_results); // Remove cache file on error to avoid writing wrong xml if ( $api_results && $json_results ) file_put_contents($cache_file, $json_results); else unlink($cache_file); } else { // Check for the number of purge cache requests to avoid abuse if( intval($_SESSION['views']) >= $request_limit ) $limit_reached = " <span class='error'>Request limit reached ($request_limit). Please try purging the cache later.</span>"; // Fetch cache $json_results = file_get_contents($cache_file); $request_type = 'JSON'; } return json_decode($json_results); } print_r($json_results); Edited by Texan78, 20 December 2014 - 03:51 PM. This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=345836.0 I can trying to create a script for caching an XML files. The problem is that this XML file was poorly constructed and I can't do anything about it. XML file: http://www.boj.org.jm/uploads/tbills.xml I would like to have the cached xml file to be restructured like this: Code: [Select] <tbills> <tbill> <title>Announcement</title> <doc>www.boj.org.jm/pdf/tbill_press_release_2010-07-13.doc</doc> <date>Jul 14 2010 12:00am</date> </tbill> <tbill> <title>Results</title> <doc>www.boj.org.jm/pdf/tbill_results_2010-june-23.doc</doc> <date>Jun 23 2010 12:00am</date> </tbill> </tbill> I can find tutorials that works if the source XML data is properly structured, but I can never seem to find one that addresses situations like this. I found this code in a tutorial and tried to edit it to what I would need, but I'm stuck with 2 things. How do I get this to change the structure of the XML when caching How do I use the call script and where do I put it? Caching script (caching.php) Code: [Select] <?php /* * Caching A small PHP class to */ class Caching { var $filePath = ""; var $apiURI = ""; function __construct($filePath, $apiURI) { //check if the file path and api URI are specified, if not: break out of construct. if (strlen($filePath) > 0 && strlen($apiURI) > 0) { //set the local file path and api path $this->filePath = $filePath; $this->apiURI = $apiURI; //does the file need to be updated? if ($this->checkForRenewal()) { //get the data you need $xml = $this->getExternalInfo(); //save the data to your file $this->stripAndSaveFile($xml); } else { //no need to update the file return true; } } else { echo "No file path and / or api URI specified."; return false; } } function checkForRenewal() { //set the caching time (in seconds) $cachetime = (60 * 60 * 24); //one day worth of seconds //get the file time $filetimemod = filemtime($this->filePath) + $cachetime; //if the renewal date is smaller than now, return true; else false (no need for update) if ($filetimemod < time()) { return true; } else { return false; } } function getExternalInfo() { if ($xml = @simplexml_load_file($this->apiURI)) { return $xml; } else { return false; } } function stripAndSaveFile($xml) { //put the artists in an array $tbill = $xml->TBILLS->ANNOUCE; //building the xml object for SimpleXML $output = new SimpleXMLElement("<tbill><title></title></tbill>"); //get only the top 10 for ($i = 0; $i < 10; $i++) { //create a new artist $insert = $output->addChild("artist"); //insert name and playcount childs to the artist $insert->addChild("name", $artists[$i]->name); $insert->addChild("playcount", $artists[$i]->playcount); } //save the xml in the cache file_put_contents($this->filePath, $output->asXML()); } } ?> Calling script (calling.php) Code: [Select] <?php ini_set('display_errors', 1); error_reporting(E_ALL); include('caching.php'); $caching = new Caching($_SERVER['DOCUMENT_ROOT']."/tbills.xml", "http://www.boj.org.jm/uploads/tbills.xml"); ?> Thanks in advance. Best Regards, _________ Winchester |