Jump to content

dombrorj

Members
  • Posts

    67
  • Joined

  • Last visited

    Never

Everything posted by dombrorj

  1. Better yet... I have this script, which is a sequential rotator. Works perfectly, but I need to append a variable to the end of the URLs in "links.txt" So httx://mysite.com/rotate.php?variable=123. Need to Get that variable and add it to the end of the URLs. rotate.php looks like this $linksfile ="./links.txt"; $links = file("$linksfile"); $use_this=array_shift($links);//take a line to use from the top array_push($links,$use_this);// puts the line back on the bottom trim("$use_this");//remove new line character from end of line file_put_contents("$linksfile","");//empty the links file foreach($links as $link)//loop through the links array { file_put_contents("$linksfile","$link",FILE_APPEND);//append the links to the linksfile } echo "<a href=\"$use_this\">$use_this</a>"; //echo the link links.txt http://link1.com?variable= http://link2.com?variable= http://link3.com?variable= Any idea how I could do that?
  2. I'm trying to use the following URL rotator, but it only works about 1 out of every 3-4 times its executed. Otherwise it does nothing. Just gets stuck at the "link.php" pages and returns a a blank, white page instead of doing the header redirect. <?php $variable = $_GET['variable']; $offers = array ( "link1.php?variable=$variable", "link2.php?variable=$variable", "link1.php?variable=$variable" ); { $url = $offers[rand(-1, count($offers) + 1)]; header("Location: $url"); } ?> Any ideas what I'm doing wrong here? Thanks!
  3. This is still working for me, but I'd like to append a variable from the URL to the end of the URLs the links.txt file. So, my link pointing to rotator.php is: mysite.com/rotator.php?variable=abc I need to get "abc" and append it to the end of the URLs in link.txt http://www.mysite.com/link1.html?variable= http://www.mysite.com/link2.html?variable= In the rotator.php file, I added $variable = $_GET['variable']; But I can't seem to echo $variable in the script above without breaking. Any way to do this? Thanks!
  4. Thanks, that solved that. I'm a designer and working with extremely limited coding skills here so really appreciate the help here. Couple questions... How can I get the scrip to do a header redirect rather than echo? Is your script going to start with link 1 for each unique visitor? Or, if person A visits the site and clicks, they'll go to link 1... then person B from a different ip clicks and goes to link 2. I'm trying to get the later to work. The reason I was using the code above was because of some concerns with volume of traffic. This page receives thousands of visitors an hour, and a previous script I was using was putting too much load on the server. The other issue was when multiple people were visiting and simultaneously clicking the link, it would fail.
  5. I think this code will work, but for some reason it gives me a blank page and enters 0s in pos.txt, even though there are 5 urls listed in links.txt. It doesn't redirect when executed. What's wrong here? <?php $linksfile ="links.txt"; $posfile = "pos.txt"; $links = file($linksfile); $numlinks = count($linksfile); $fp = fopen($posfile, 'r+') or die("Failed to open posfile"); flock($fp, LOCK_EX); $num = fread($fp, 1024); if($num<$numlinks-1) { fwrite($fp, $num+1); } else { fwrite($fp, 0); } flock($fp, LOCK_UN); fclose($fp); header("Location: {$links[$num]}"); ?>
  6. Thanks teamatomic... Edit: That's making progress. I have 5 url in the array. With your script above, it outputs the first and 5th url together, like: http://mysite.com/link1.htmlhttp://mysite.com/link2.html Also, the script needs to be a redirect script rather than echoing the URL. So the user will click "redirect.php" and it will take them to 1 of the 5 URLS. Does that make sense? Thanks again
  7. I'm trying to set up a script that will rotate the URLs a user visits when they click a link. When they "Click Here" I'd like it to direct them to 1 of 5 urls in the list. This should be sequential, so if 100 people click the link, each of the 5 links should be visited 20 times total. In other words, it can't randomly select the URL to direct the user. It should be evenly distributed. Here's what I have so far, but is not working... ROTATE.PHP <?php $linksfile ="links.txt"; $posfile = "pos.txt"; $links = file($linksfile); $numlinks = count($linksfile); $fp = fopen($posfile, 'r+') or die("Failed to open posfile"); flock($fp, LOCK_EX); $num = fread($fp, 1024); if($num<$numlinks-1) { fwrite($fp, $num+1); } else { fwrite($fp, 0); } flock($fp, LOCK_UN); fclose($fp); header("Location: {$links[$num]}"); ?> LINK.TXT http://www.mysite.com/link1.html http://www.mysite.com/link2.html http://www.mysite.com/link3.html http://www.mysite.com/link4.html http://www.mysite.com/link5.html POS.TXT (blank txt file) Thanks in advance!
  8. That did it! Thanks to both of you for your help. Much appreciated
  9. Excellent, thanks! I couldn't get it to work at first when the doc was saved as an html file. Once I saved as a php file and uploaded to server, it worked. Is that necessary? (clearly don't know what I'm doing) One other question... the format of the month is spelled out entirely, i.e. "December" Is there an easy way to make the months abbreviated, i.e. "Dec" Thanks!
  10. I'm trying to get whatever the date was 3 days ago to display in an html document. And I need is the month on one line and the day on another. If today's date is January 2nd, for example, the date has to display December 31. So my html looks like this... <head> </head> <body> <p>the date 3 days ago was: <br> December <br> 31 </body> Can someone help me with the php code to use here? What I've found so far won't actually display anything in my browser, so I may be doing it entirely wrong. I use other php scripts, and am certain my server has php 5 enabled. But maybe there's something else that has to be enabled? Thanks for the help.
  11. Wow! That's looks good! I'll see if I can get this to work and post back soon. Thank you for sharing!
  12. I like that, thank you! That's good thinking. Edit: From ym_chaitu's response, I removed the "Mozilla" part of the string (around line 10) and used Lamez's code above. What I'm left with now is FF and IE redirecting to Google, which is good. But now Safari and Chrome are both redirecting to Yahoo, when Chrome should go to Ask.com. I haven't checked Opera though. Making progress! <?php function getBrowser() { $u_agent = $_SERVER['HTTP_USER_AGENT']; $ub = 'other'; if(preg_match('/MSIE/i',$u_agent)){ $ub = 'ie'; } elseif(preg_match('/Firefox/i',$u_agent)){ $ub = 'firefox'; } elseif(preg_match('/Safari/i',$u_agent)){ $ub = 'safari'; } elseif(preg_match('/Chrome/i',$u_agent)){ $ub = 'chrome'; } elseif(preg_match('/Opera/i',$u_agent)){ $ub = 'opera'; } return $ub; } $browser = getBrowser(); if($browser == 'ie'){ $url = 'http://www.google.com'; }elseif($browser == 'firefox'){ $url = 'http://www.google.com'; }elseif($browser == 'safari'){ $url = 'http://www.yahoo.com'; }elseif($browser == 'chrome'){ $url = 'http://www.ask.com'; }elseif($browser == 'opera'){ $url = 'http://www.ask.com'; } header("Location: ".$url); ?> Thanks again for the help with this.
  13. I just tried that as well, and same issue. On your 6th line, there's a closed parenthesis missing that caused it to break(after $browser=='chrome), but when I added that all browsers are still redirecting to Google. Is there anything else in the script that is not allowing it to follow the 'elseif' statement? I appreciate the help!
  14. I thought that would work too. But when I test it, all browsers redirect to the first "if" function. For example, I did exactly what you have above and everything is redirecting to google.com. Even Safari, Chrome, etc.
  15. Hi, I'm trying to make a simple php script that will redirect users based on their browser type. I'm looking to send IE and Firefox users to one URL, and Safari/Opera/Chrome visitors to another URL. Here is what I have so far that is working, but can't figure out how to add additional redirect options based on the browser type. <? //this function gets the header sent by browser and returns name of the browser or 'other' if the browser is not in the list function getBrowser() { $u_agent = $_SERVER['HTTP_USER_AGENT']; $ub = 'other'; if(preg_match('/MSIE/i',$u_agent)) { $ub = 'ie'; } elseif(preg_match('/Firefox/i',$u_agent)) { $ub = 'firefox'; } elseif(preg_match('/Mozilla/i',$u_agent)) { $ub = 'firefox'; } elseif(preg_match('/Safari/i',$u_agent)) { $ub = 'safari'; } elseif(preg_match('/Chrome/i',$u_agent)) { $ub = 'chrome'; } elseif(preg_match('/Opera/i',$u_agent)) { $ub = 'opera'; } return $ub; } $browser=getBrowser(); if (($browser=='ie')) header( 'Location: http://www.google.com' ) ; else header( 'Location: http://www.yahoo.com' ) ; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.