kcelsi Posted October 12, 2013 Share Posted October 12, 2013 Hello, I am trying to change the source page of an iframe every 24 hours automatically in Eastern Standard time in any browser on any computer. I thought I could do this with javascript, but was told that php is the better way. I am a newbie to php. I am a web designer and I'm trying to learn more about programming. I have some knowledge of php, but only basic. Can anyone tell me how to do this? Thank you! Quote Link to comment Share on other sites More sharing options...
PravinS Posted October 12, 2013 Share Posted October 12, 2013 if you are not going to reload the page then you can use meta refresh tag in iframe source page Quote Link to comment Share on other sites More sharing options...
kcelsi Posted October 12, 2013 Author Share Posted October 12, 2013 (edited) The source pages need to be there whether the page is refreshed or not. It's for a mortgage company. One day, the page has to be for one broker, the next day the page has to be for the other broker and so on every day. All viewers must be able to see the right broker for that day when viewing the page from any computer. Edited October 12, 2013 by kcelsi Quote Link to comment Share on other sites More sharing options...
vinny42 Posted October 12, 2013 Share Posted October 12, 2013 I thought I could do this with javascript Then try that first. It doesn't matter to the visitor and you'll probably have a working solution much sooner than with PHP. Just make it intelligent; don't add all the brokers into the HTML and hide all but the current one; use ajax to only load the current one. That way the webserver will also register a hit for every broker loaded and you can prove to your brokers that the all had a equal share of hits, etc... Quote Link to comment Share on other sites More sharing options...
.josh Posted October 12, 2013 Share Posted October 12, 2013 There are a number of ways you can store the list of brokers and flag the current, one, but here is an example to demonstrate the principle. Create a text file with the list of brokers. The first broker in the list will be the one for the current day. brokers.txt broker1 broker2 broker3 etc.. Code for getting the first broker in the list. This will be what you use on your page to get the current broker for the day. <?php $handle = fopen('brokers.txt', 'r'); $broker = fgets($handle); fclose($handle); // example: echo "current broker is: " . $broker . "<br/>"; ?> Now for script that rotates the list. You don't actually include this on the web page, nor does the visitor go to it. Instead, you will create a cronjob to run the script every 24 hours. rotateBrokers.php <?php $file = 'brokers.txt'; // name of file $brokers = file($file); // get the list from the file $oldBroker = trim(array_shift($brokers)).PHP_EOL; // remove the first broker from the list array_push($brokers,$oldBroker); // put it onto the end of the list file_put_contents($file,$brokers); // write reordered list back to file ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted October 12, 2013 Share Posted October 12, 2013 No need for cron job $brokers = array ( 'www.broker1.co.uk', 'www.broker2.com', 'www.broker3.com', 'www.broker4.co.uk' ); // or use file() as reply^^ $numbrokers = count($brokers); $dayofyear = date('z'); $todaysURL = 'http://'.$brokers[$dayofyear%$numbrokers]; Quote Link to comment Share on other sites More sharing options...
kcelsi Posted October 12, 2013 Author Share Posted October 12, 2013 The last post by Barand seems to be the easiest way to go. Couple of questions though. There will only be two rotating web pages so how would I write this specifically to what I need to do. Which parts of this code need to be customized to my specific page. Is it everything in green? If so, can you give an example of what I put in for 'z' and which url (broker 1 or broker2) do I put into the last line. Also, is there anything that I need to change in the html for the iframe? This is what I have now to show only one source page: <div id="iframe"><iframe id="iframeHome" src="https://www.broker1.com" frameborder="0">Browser Not Compatible</iframe></div> Thanks! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 12, 2013 Share Posted October 12, 2013 (edited) Is it everything in green?Not every thing no. That is the forums syntax highlighting Which parts of this code need to be customized to my specific page.The urls in the $brokers array. Enter each of your brokers websites into that array. As Barand has demonstrated If so, can you give an example of what I put in for 'z'You don't change that, date is a PHP function, z is used to get the curent day of the year http://php.net/date Also, is there anything that I need to change in the html for the iframe? This is what I have now to show only one source page: <div id="iframe"><iframe id="iframeHome" src="https://www.broker1.com" frameborder="0">Browser Not Compatible</iframe></div> Yes change the iframe code to <div id="iframe"><iframe id="iframeHome" src="<?php echo $todaysURL; ?>" frameborder="0">Browser Not Compatible</iframe></div> Edited October 12, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Barand Posted October 12, 2013 Share Posted October 12, 2013 If there are only then there will be just two urls in the array <?php $brokers = array ( 'www.broker1.co.uk', 'www.broker2.com' ); $numbrokers = count($brokers); $dayofyear = date('z'); $todaysURL = 'http://'.$brokers[$dayofyear%$numbrokers]; ?> <div id="iframe"><iframe id="iframeHome" src="<?php echo $todaysURL ?>" frameborder="0">Browser Not Compatible</iframe></div> If a third broker comes along, just add it to the array Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 13, 2013 Share Posted October 13, 2013 Pretty tricky Barand I never thought about using an array like that. My first reflection was like .josh's reply with a cron job. Quote Link to comment Share on other sites More sharing options...
kcelsi Posted October 13, 2013 Author Share Posted October 13, 2013 Thanks so much. So far it's working, but I won't know for sure until tomorrow to see if it changes. It seems to be showing the second url first. Is that normal? Also, will this change at exactly midnight every night? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 13, 2013 Share Posted October 13, 2013 (edited) It should serve a different url for each day. To simulate the day changing and what url be served on that day you can this code <?php $time = time(); if(isset($_GET['time'])) $time = $_GET['time']; if(isset($_GET['next'])) $time = strtotime('+1 day', $time); if(isset($_GET['prev'])) $time = strtotime('-1 day', $time); $brokers = array ( 'www.broker1.co.uk', 'www.broker2.com', 'www.google.co.uk', 'www.phpfreaks.co.uk' ); $numbrokers = count($brokers); $dayofyear = date('z', $time); $todaysURL = 'http://'.$brokers[$dayofyear%$numbrokers]; $dateFormat = date('jS M y', $time); echo ' On <b>'.$dateFormat.'<b> url will be: <b>'.$todaysURL.'</b> <p> <a href="?prev&time='.$time.'">Previous Day</a> | <a href="?next&time='.$time.'">Next Day</a> </p>';?> As you click the links you see the url changing. Edited October 13, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
.josh Posted October 13, 2013 Share Posted October 13, 2013 One other thing.. you mentioned wanting it to be EST based. If the server isn't located in EST timezone, add this to the top of it: date_default_timezone_set('America/New_York'); Quote Link to comment Share on other sites More sharing options...
kcelsi Posted October 13, 2013 Author Share Posted October 13, 2013 I added the code to update the time zone. Thank you all for the help! Quote Link to comment Share on other sites More sharing options...
kcelsi Posted November 3, 2013 Author Share Posted November 3, 2013 Hello, I'm having problems with this again. Here some issues I'm having: 1. I have 7 pages with iframes that are supposed to rotate daily between two web pages from GuaranteedRate.com. They are: http://www.newjerseyrates.com/ http://www.newjerseyrates.com/Buying-a-Home.php http://www.newjerseyrates.com/Refinance.php http://www.newjerseyrates.com/Loan-Options.php http://www.newjerseyrates.com/Mortgage-Rates.php http://www.newjerseyrates.com/Calculators-GuaranteedRate.php http://www.newjerseyrates.com/About-GuaranteedRate.php For some reason, the pages are not changing any more. I know it was working when I first uploaded the site, but now, only one link shows up and it stays on that one all the time. 2. When you type the url directly to go to the home page, a different page comes up than if you click on any link within the site to get to the home page. Entering the site externally will produce a different home page than getting to the home page internally. I only have one index.php file so this is a mystery to me. 3. When I "view source" in the browser, the code that shows up is completely wrong on all the pages. I checked the file manager from my hosting provider and there, the code for each page is correct. The browser view source is showing the old javascript that I replaced with the php. I thought this could be why it's not working, but I have uploaded the pages several times and the browser is still showing the incorrect code. I have tried clearing the browser cache. 4. I did a test and about 30% of the people I tested that go to the home page, have the main site www.guaranteedrate.com show up in the iframe instead of the link I have in the php code. I'm not sure if this is a problem with my code, an issue with the hosting provider or something related to the Guaranteed Rate site on their end. I am in a rush to get all this ironed out because my client is pausing their pay per click campaign until it's resolved. Anyone who could shed light on any of these issues, please let me know. Code samples are below. Thank you. For example, the index.php page should be (this is what shows up in my hosting file manager): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Main.dwt" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>New Jersey (NJ) Mortgage Lender, Mortgage Rates, Fha, Refinance & Home Loans</title> <meta name="description" content="Get real time, accurate New Jersey (NJ) mortgage rates, refinancing and home loans." /> <meta name="keywords" content="new jersey, nj, new jersey refinance, new jersey refinancing, FHA mortgage, jumbo mortgage, mortgage interest rate, mortgage, mortgage rates, mortgage broker, refinance, home loan, mortgage company, mortgage lender, mortgage refinancing, new jersey refinancing, home mortgage, mortgage interest rate" /> <meta name="nibbler-site-verification" content="3a321e0559840ef51087c274ba6f8be369e42dbf" /> <link rel="shortcut icon" href="favicon.ico" /> <?php date_default_timezone_set('America/New_York'); $brokers = array ( 'www.guaranteedrate.com/loanoptions/vpname/leezacharczyk', 'www.guaranteedrate.com/loanoptions/vpname/markzacharczyk' ); $numbrokers = count($brokers); $dayofyear = date('z'); $todaysURL = 'http://'.$brokers[$dayofyear%$numbrokers]; ?> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable --> <link href="css/GRateStyles.css" rel="stylesheet" type="text/css" /> <style> @media print { body { color: #000; background: #fff; } h1, h3 { color: #000; background: none; } #header, #footer, #leftNav, #right { display: none; } @page { margin: 2cm; } img { max-width: 100% !important; } ul, img { page-break-inside: avoid; } a { font-weight: bolder; text-decoration: none; } a[href^=http]:after { content:" <" attr(href) "> "; } } </style> <style type="text/css"> body { background-image: url(images/BkrdTexture.jpg); background-repeat: repeat; } </style> </head> <body> <div id="wrapper"> <div id="header"> <div id="headerBox"> <div id="logo"><a href="index.php"><img src="images/Logo.jpg" width="200" height="129" alt="Logo" /></a> </div> <div id="headerRight"> <div class="headerRightContactText" id="headerRightContact"><a href="contact.html">Contact</a> NewJerseyRates.com</div> <div id="headerRightTagline">Customized, Automated NJ Mortgage Rate Quotes <span class="redText">Accurate and Up-to-the-Minute</span> </div> </div> </div> </div> <div id="navBar"> <ul class="navBar"> <li class="home"><a href="index.php">Home</a></li> <li class="faq"><a href="faq.html">FAQ</a></li> <li class="aboutCredit"><a href="About-Credit.html">About Credit</a></li> <li class="loanProg"><a href="Loan-Programs.html">Loan Programs</a></li> <li class="survey"><a href="Survey.html">Survey</a></li> <li class="homeInspec"><a href="Home-Buyers-Info.html">Home Buyers Info</a></li> <li class="about"><a href="about_us.html">About NewJerseyRates.com</a></li> <li class="partnerLinks"><a href="links.html">Partner Links</a></li> <li class="glossary"><a href="gloss.html">Glossary</a></li> </ul> </div> <div id="content"> <div id="leftNav"> <ul class="leftNav"> <li class="leftNavBuyHome"><a href="Buying-a-Home.php">Buying a Home<img class="navArrowHome" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Refinance.php">Refinance<img class="navArrowRefi" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Loan-Options.php">Loan Options<img class="navArrowLoanOpt" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Mortgage-Rates.php">Mortgage Rates<img class="navArrowMort" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Calculators-GuaranteedRate.php">Calculators<img class="navArrowCalc" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavAbout"><a href="About-GuaranteedRate.php">About Us<img class="navArrowAbout" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavPreApp"><a href="Pre-Approval.html">Instant Pre-Approval</a></li> <li class="leftNavCustomRates"><a href="index.php">Customized <br /> Mortgage Rates</a></li></ul> </div> <!-- InstanceBeginEditable name="Edit1" --> <div id="editArea"> <div id="iframe"><iframe id="iframeHome" src="<?php echo $todaysURL ?>" frameborder="0">Browser Not Compatible</iframe></div> </div> <!-- InstanceEndEditable --> </div> <div id="footer"> <div id="template-footer"> 500 State Rt. 35 Middletown, New Jersey 07701 | <script type="text/javascript"> <!-- var linkText = "Email Us " var preName = "lee.zacharczyk" var postName = "guaranteedrate.com" document.write("<a href=" + "mail" + "to:" + preName + "@" + postName + ">" + linkText + "</a>") //--> </script> | Web Design by <a href="http://www.littlechisel.com" target="new">Little Chisel Design</a> ©2013 All Rights Reserved</div> </div> </div> </body> <!-- InstanceEnd --></html> and the view source of Chrome and IE shows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Main.dwt" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>New Jersey (NJ) Mortgage Lender, Mortgage Rates, Fha, Refinance & Home Loans</title> <meta name="description" content="Get real time, accurate New Jersey (NJ) mortgage rates, refinancing and home loans." /> <meta name="keywords" content="new jersey, nj, new jersey refinance, new jersey refinancing, FHA mortgage, jumbo mortgage, mortgage interest rate, mortgage, mortgage rates, mortgage broker, refinance, home loan, mortgage company, mortgage lender, mortgage refinancing, new jersey refinancing, home mortgage, mortgage interest rate" /> <meta name="nibbler-site-verification" content="3a321e0559840ef51087c274ba6f8be369e42dbf" /> <link rel="shortcut icon" href="http://www.littlechisel.com/clients/GuaranteedRate/favicon.ico"/> <script type="text/javascript"> var frames = Array('https://www.guaranteedrate.com/loanoptions/vpname/markzacharczyk' 86.4*1000, 'https://www.guaranteedrate.com/loanoptions/vpname/leezacharczyk' 86.4*1000); var i = 0, len = frames.length; function ChangeSrc() { if (i >= len) { i = 0; } // start over document.getElementById('iframeHome').src = frames[i++]; setTimeout('ChangeSrc()', (frames[i++]*1000)); } window.onload = ChangeSrc; </script> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable --> <link href="css/GRateStyles.css" rel="stylesheet" type="text/css" /> <style> @media print { body { color: #000; background: #fff; } h1, h3 { color: #000; background: none; } #header, #footer, #leftNav, #right { display: none; } @page { margin: 2cm; } img { max-width: 100% !important; } ul, img { page-break-inside: avoid; } a { font-weight: bolder; text-decoration: none; } a[href^=http]:after { content:" <" attr(href) "> "; } } </style> <style type="text/css"> body { background-image: url(images/BkrdTexture.jpg); background-repeat: repeat; } </style> </head> <body> <div id="wrapper"> <div id="header"> <div id="headerBox"> <div id="logo"><a href="index.php"><img src="images/Logo.jpg" width="200" height="129" alt="Logo" /></a> </div> <div id="headerRight"> <div class="headerRightContactText" id="headerRightContact"><a href="contact.html">Contact</a> NewJerseyRates.com</div> <div id="headerRightTagline">Customized, Automated NJ Mortgage Rate Quotes <span class="redText">Accurate and Up-to-the-Minute</span> </div> </div> </div> </div> <div id="navBar"> <ul class="navBar"> <li class="home"><a href="index.php">Home</a></li> <li class="faq"><a href="faq.html">FAQ</a></li> <li class="aboutCredit"><a href="About-Credit.html">About Credit</a></li> <li class="loanProg"><a href="Loan-Programs.html">Loan Programs</a></li> <li class="survey"><a href="Survey.html">Survey</a></li> <li class="homeInspec"><a href="Home-Buyers-Info.html">Home Buyers Info</a></li> <li class="about"><a href="about_us.html">About NewJerseyRates.com</a></li> <li class="partnerLinks"><a href="links.html">Partner Links</a></li> <li class="glossary"><a href="gloss.html">Glossary</a></li> </ul> </div> <div id="content"> <div id="leftNav"> <ul class="leftNav"> <li class="leftNavBuyHome"><a href="Buying-a-Home.php">Buying a Home<img class="navArrowHome" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Refinance.php">Refinance<img class="navArrowRefi" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Loan-Options.php">Loan Options<img class="navArrowLoanOpt" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Mortgage-Rates.php">Mortgage Rates<img class="navArrowMort" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavRefi"><a href="Calculators-GuaranteedRate.php">Calculators<img class="navArrowCalc" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavAbout"><a href="About-GuaranteedRate.php">About Us<img class="navArrowAbout" src="images/navArrow.gif" alt="Nav Arrow" width="11" height="11"/></a></li> <li class="leftNavPreApp"><a href="Pre-Approval.html">Instant Pre-Approval</a></li> <li class="leftNavCustomRates"><a href="index.php">Customized <br /> Mortgage Rates</a></li></ul> </div> <!-- InstanceBeginEditable name="Edit1" --> <div id="editArea"> <div id="iframe"><iframe name="iframeHome" id="iframeHome" src="" frameborder="0">Browser Not Compatible</iframe></div> </div> <!-- InstanceEndEditable --> </div> <div id="footer"> <div id="template-footer"> 500 State Rt. 35 Middletown, New Jersey 07701 | <script type="text/javascript"> <!-- var linkText = "Email Us " var preName = "lee.zacharczyk" var postName = "guaranteedrate.com" document.write("<a href=" + "mail" + "to:" + preName + "@" + postName + ">" + linkText + "</a>") //--> </script> | Web Design by <a href="http://www.littlechisel.com" target="new">Little Chisel Design</a> ©2013 All Rights Reserved</div> </div> </div> </body> <!-- InstanceEnd --></html> Quote Link to comment Share on other sites More sharing options...
.josh Posted November 3, 2013 Share Posted November 3, 2013 you said you have 7 brokers to cycle through, but your $brokers array only has 2 links in them.. Quote Link to comment Share on other sites More sharing options...
kcelsi Posted November 3, 2013 Author Share Posted November 3, 2013 (edited) No, I don't have 7 brokers only two. There are 7 pages that each have different iframes to rotate between the two brokers daily. So each of the 7 (NewJerseyRates) pages should have Lee's (Guaranteed Rate) pages one day and all 7 should have Marks (Guaranteed Rate) pages the next day. Sorry so confusing. Edited November 3, 2013 by kcelsi Quote Link to comment Share on other sites More sharing options...
kcelsi Posted November 3, 2013 Author Share Posted November 3, 2013 I have been working on this and fixed some of the problems. Now I only have two issues. 1. The iframes are changing daily, but not at 12:00 am. It seems that they changed sometime in the middle of the day today. Should this be happening and how could I get them to change at 12 am? 2. I discovered that in the Safari browser only, the iframe source page is not the right one. For example, for the home page, I have www.guaranteedrate.com/loanoptions/vpname/leezacharczyk set to appear, but www.guaranteedrate.com/loanoptions is appearing instead. Must be something with Safari, but is this related to the php code or could it be something else? Thanks again for any help. Kathy Quote Link to comment Share on other sites More sharing options...
Barand Posted November 4, 2013 Share Posted November 4, 2013 Where you have the line $dayofyear = date('z'); you could also try checking the value of "date('Y-m-d H:i:s')" to see if the datetime is what you would expect it to be or if it out by several hours. If it is out, try adjusting the timezone. Your second point I cannot understand as the link value is created on the server and will be sent to all browsers ??? Quote Link to comment Share on other sites More sharing options...
kcelsi Posted November 4, 2013 Author Share Posted November 4, 2013 Thank you for the reply. I will try what you suggested. As for my Safari problem, it seems to by a mystery. Do you think it could be an issue with the www.guaranteedrate.com site? Could they somehow be redirecting the page on their end? I tried the Apple Safari forum also, but have not received any responses yet. Quote Link to comment Share on other sites More sharing options...
kcelsi Posted November 4, 2013 Author Share Posted November 4, 2013 Okay, so I found out the problem, but don't know a fix. Safari by default blocks iframes with different hosts (so, the main frame is newjerseyrates.com but the iframe is http://www.guaranteedrate.com), so safari is blocking the tracking cookies. Now knowing this, does anyone have a workaround that can fix this problem? Should I re-post this as a new discussion? Thanks. Quote Link to comment Share on other sites More sharing options...
Linces Posted May 25, 2014 Share Posted May 25, 2014 Sorry, i have same question, almost. In the code: <?php $brokers = array ( 'bac1.html', 'bac2.html', 'mx1.htl', 'lw1.html' ); $numbrokers = count($brokers); $dayofyear = date('z'); $todaysURL = 'http://www.delphifontes.com.br/'.$brokers[$tim%$numbrokers]; ?> What i need to modify for rotate the banners every 30 secs? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 25, 2014 Share Posted May 25, 2014 What you have is completely different type of problem. In the original post it was only necessary to have displayed the new link when the page loaded. You want it to be done while the page is loaded. This will require javascript or AJAX. The simplest way would be to create a javascript array and use setInterval() to fetch and display the next element every 30 seconds. If you are going to hijack someone else's thread, be sure of the problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.