GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   quick php code help... (https://gfy.com/showthread.php?t=939847)

qwe 11-22-2009 09:30 PM

quick php code help...
 
I want to put alot of urls into the php file, and once php file gets executed it will redirect to those urls one by one... like if I have 100 urls, once php file loads it will go to first url, then once php file get executed again it will load second url, and so on, then once it reaches the end it will start from the begging ... can someone hook me up please :)

Basic_man 11-22-2009 09:33 PM

Quote:

Originally Posted by qwe (Post 16576081)
I want to put alot of urls into the php file, and once php file gets executed it will redirect to those urls one by one... like if I have 100 urls, once php file loads it will go to first url, then once php file get executed again it will load second url, and so on, then once it reaches the end it will start from the begging ... can someone hook me up please :)

Can get you up & running in no time with this. Get a hold on me on ICQ : 349-164-75 :thumbsup

qwe 11-22-2009 09:57 PM

still looking :)

qwe 11-22-2009 10:57 PM

bump bump

woj 11-22-2009 11:03 PM

If you are looking to invest a few bucks, icq: 33375924

Nookster 11-22-2009 11:09 PM

Here's help. Otherwise, I could make it for you but $$ talks.

quantum-x 11-23-2009 04:04 AM

Quick and dirty way to do it:
Code:


<?
$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
$url = array_shift($urls);
array_push($urls,$url);
file_put_contents('URLS.txt',implode("\r\n",$urls));

header('Location:'.$url);
?>

Will work. Untested, don't ask for me to fix it if it doesn't kick - pay woj instead.

Nookster 11-23-2009 04:03 PM

Quote:

Originally Posted by quantum-x (Post 16576469)
Quick and dirty way to do it:
Code:


<?
$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
$url = array_shift($urls);
array_push($urls,$url);
file_put_contents('URLS.txt',implode("\r\n",$urls));

header('Location:'.$url);
?>

Will work. Untested, don't ask for me to fix it if it doesn't kick - pay woj instead.

It helps to completely read what he was looking for.

HomerSimpson 11-23-2009 04:24 PM

array + array_rand - and it's all done...

read the manual...

quantum-x 11-23-2009 04:58 PM

Quote:

Originally Posted by Nookster (Post 16578450)
It helps to completely read what he was looking for.

Care to point out what it doesn't do?
Takes a list of URLS. Each time the script is loaded, it redirects to the next, and so forth.
What did I miss?

Killswitch - BANNED FOR LIFE 11-23-2009 05:08 PM

Quote:

Originally Posted by Nookster (Post 16578450)
It helps to completely read what he was looking for.

I hope you don't call yourself a programmer.

StuartD 11-23-2009 05:33 PM

Quote:

Originally Posted by quantum-x (Post 16576469)
Quick and dirty way to do it:
Code:


<?
$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
$url = array_shift($urls);
array_push($urls,$url);
file_put_contents('URLS.txt',implode("\r\n",$urls));

header('Location:'.$url);
?>

Will work. Untested, don't ask for me to fix it if it doesn't kick - pay woj instead.

Yup, that would work.
A real solution would be to use a db or even xml file, but quantum-x has a solution that will work quite well :thumbsup

rowan 11-23-2009 05:40 PM

q-x's solution will truncate the url file if the HD runs out of space. :)

(I know it's a quick and dirty free solution, just pointing out one potential issue.)

sarettah 11-23-2009 06:09 PM

Quote:

Originally Posted by rowan (Post 16578741)
q-x's solution will truncate the url file if the HD runs out of space. :)

(I know it's a quick and dirty free solution, just pointing out one potential issue.)

Hmm. I don't think so. If the file had XX number of urls and took up XX amount of space at the beginning of the program it would still have xx number of urls and take up xx amount of space at the end. So, if the file fit on the HD before it still does after.

just :2 cents:

qwe 11-23-2009 06:38 PM

Quote:

Originally Posted by quantum-x (Post 16576469)
Quick and dirty way to do it:
Code:


<?
$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
$url = array_shift($urls);
array_push($urls,$url);
file_put_contents('URLS.txt',implode("\r\n",$urls));

header('Location:'.$url);
?>

Will work. Untested, don't ask for me to fix it if it doesn't kick - pay woj instead.

gives me this error

Parse error: syntax error, unexpected T_VARIABLE in /www/users/for/multiurl.php on line 3

Killswitch - BANNED FOR LIFE 11-23-2009 06:49 PM

$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

qwe 11-23-2009 06:53 PM

Quote:

Originally Posted by Killswitch (Post 16578875)
$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

now i get this:

Fatal error: Call to undefined function: file_put_contents() in /www/users/for/multiurl.php on line 5

XD2 11-23-2009 06:55 PM

Quote:

Originally Posted by qwe (Post 16578858)
gives me this error

Parse error: syntax error, unexpected T_VARIABLE in /www/users/for/multiurl.php on line 3

Second Line which is the first line of code needs a ; on the end.

Code:

$urls = file('URLS.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
EDIT: Didn't refresh page and see it had been answered :)

Killswitch - BANNED FOR LIFE 11-23-2009 06:56 PM

Quote:

Originally Posted by qwe (Post 16578883)
now i get this:

Fatal error: Call to undefined function: file_put_contents() in /www/users/for/multiurl.php on line 5

file_put_contents() is a php5 function.

rowan 11-23-2009 06:57 PM

Quote:

Originally Posted by sarettah (Post 16578796)
Hmm. I don't think so. If the file had XX number of urls and took up XX amount of space at the beginning of the program it would still have xx number of urls and take up xx amount of space at the end. So, if the file fit on the HD before it still does after.

just :2 cents:

It's happened to me. ;) When you open a file for write it's first truncated, so if there's something else writing at that time, or the file system allows a truncate but not write when it's chock full, you'll end up with a 0 byte file. For a rotating buffer like this it's probably better to use a pointer and save that in a separate file - at least if that gets trashed then it just starts at 0 again...

Deej 11-23-2009 06:57 PM

... pay woj ...

rowan 11-23-2009 06:59 PM

Replace the file_put_contents(...) line with this

$fp = fopen('URLS.txt', 'r+');
fwrite($fp, implode("\r\n",$urls))
fclose($fp);

Killswitch - BANNED FOR LIFE 11-23-2009 07:00 PM

Quote:

Originally Posted by Killswitch (Post 16578892)
file_put_contents() is a php5 function.

Code:

<?php
  if(!function_exists('file_put_contents')) {
    function file_put_contents($filename, $data, $file_append = false) {
      $fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
        if(!$fp) {
          trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
          return;
        }
      fputs($fp, $data);
      fclose($fp);
    }
  }
?>

That should fix your problem. I highly suggest upgrading PHP to 5.x

rowan 11-23-2009 07:05 PM

Hey Killswitch, is the chick in your avatar some random_unverifiable_one_off_chick or from a program?

qwe 11-23-2009 07:08 PM

Quote:

Originally Posted by rowan (Post 16578902)
Replace the file_put_contents(...) line with this

$fp = fopen('URLS.txt', 'r+');
fwrite($fp, implode("\r\n",$urls))
fclose($fp);

after few runs i get this

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 128 bytes) in /www/users/for/multiurl.php on line 6

qwe 11-23-2009 07:09 PM

Quote:

Originally Posted by Killswitch (Post 16578903)
Code:

<?php
  if(!function_exists('file_put_contents')) {
    function file_put_contents($filename, $data, $file_append = false) {
      $fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
        if(!$fp) {
          trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
          return;
        }
      fputs($fp, $data);
      fclose($fp);
    }
  }
?>

That should fix your problem. I highly suggest upgrading PHP to 5.x

hey switch, where do I put that ? instead of file_put_contents line?

rowan 11-23-2009 07:10 PM

Quote:

Originally Posted by qwe (Post 16578933)
after few runs i get this

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 128 bytes) in /www/users/for/multiurl.php on line 6

lol... so it's a BIG list? I think it's time to call on woj. This isn't so simple any more.

qwe 11-23-2009 07:12 PM

Quote:

Originally Posted by rowan (Post 16578940)
lol... so it's a BIG list? I think it's time to call on woj. This isn't so simple any more.

nope, urls.txt has 10 urls in it, thats it

rowan 11-23-2009 07:16 PM

Quote:

Originally Posted by qwe (Post 16578943)
nope, urls.txt has 10 urls in it, thats it

Has it grown? I can't think why else PHP would be complaining it's out of memory.

rowan 11-23-2009 07:17 PM

And you can see that free help isn't always so quick... by now you probably could have paid to get a working solution that you didn't have to worry about...

qwe 11-23-2009 07:18 PM

Quote:

Originally Posted by rowan (Post 16578954)
Has it grown? I can't think why else PHP would be complaining it's out of memory.

yap, used to be 1kb file, now it's 137kb file with only 1 url in it instead of 10... hrmm

quantum-x 11-23-2009 07:30 PM

Why the fuck are you running PHP4 - In one month's time it will have been discontinued for THREE YEARS.

No wonder shit is breaking ;)

rowan 11-23-2009 07:30 PM

Does each redirect NEED to be sequential? If you do it randomly and there's enough loads (ie enough of a sample) then each URL will receive the same average amount of traffic anyway.

qwe 11-23-2009 07:30 PM

Quote:

Originally Posted by Killswitch (Post 16578903)
Code:

<?php
  if(!function_exists('file_put_contents')) {
    function file_put_contents($filename, $data, $file_append = false) {
      $fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
        if(!$fp) {
          trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
          return;
        }
      fputs($fp, $data);
      fclose($fp);
    }
  }
?>

That should fix your problem. I highly suggest upgrading PHP to 5.x

ok I put that before file_put_contents line and it works, but after it redirects to the site it deletes that site from urls.txt file for some reason ?

quantum-x 11-23-2009 07:30 PM

Quote:

Originally Posted by rowan (Post 16578895)
It's happened to me. ;) When you open a file for write it's first truncated, so if there's something else writing at that time, or the file system allows a truncate but not write when it's chock full, you'll end up with a 0 byte file. For a rotating buffer like this it's probably better to use a pointer and save that in a separate file - at least if that gets trashed then it just starts at 0 again...

As with anything when you write to the filesystem. You should be / your host should be monitoring disc space anyhow.

If you're out of space PHP will probaby grind itself to death when attempting to even run :)

qwe 11-23-2009 07:32 PM

Quote:

Originally Posted by rowan (Post 16578991)
Does each redirect NEED to be sequential? If you do it randomly and there's enough loads (ie enough of a sample) then each URL will receive the same average amount of traffic anyway.

it doesn't have to be, can be random too if it's easier

rowan 11-23-2009 07:34 PM

Quote:

Originally Posted by qwe (Post 16578996)
it doesn't have to be, can be random too if it's easier

Far easier.

<?php
$urls = file("URLS.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
header("HTTP/1.0 302 redirect");
header("Location: " . $urls[(rand(0, count($urls) - 1))]);
?>

qwe 11-23-2009 07:38 PM

Quote:

Originally Posted by rowan (Post 16579003)
Far easier.

<?php
$urls = file("URLS.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
header("HTTP/1.0 302 redirect");
header("Location: " . $urls[(rand(0, count($urls) - 1))]);
?>

works like a charm, thanks bro :thumbsup

rowan 11-23-2009 07:40 PM

Damn, I should have left out a semicolon or two and extorted $3.82 from you.

GrouchyAdmin 11-23-2009 07:41 PM

Sweet fucking Christ.

qwe 11-23-2009 07:43 PM

Quote:

Originally Posted by rowan (Post 16579024)
Damn, I should have left out a semicolon or two and extorted $3.82 from you.

:1orglaugh btw, it should not have any issues with big files? or it's limited to like 1-100 urls or so ?

rowan 11-23-2009 07:57 PM

Quote:

Originally Posted by qwe (Post 16579032)
:1orglaugh btw, it should not have any issues with big files? or it's limited to like 1-100 urls or so ?

The answer will cost $3.82. :winkwink:

So long as your URL list isn't megs in size it should be fine. If it gets too big then PHP will die with an out of memory error.

Killswitch - BANNED FOR LIFE 11-23-2009 08:03 PM

Quote:

Originally Posted by rowan (Post 16578918)
Hey Killswitch, is the chick in your avatar some random_unverifiable_one_off_chick or from a program?

I found it on some site, I think it's one of those ex girlfriend site pics that are on every ex gf site.

Quote:

Originally Posted by qwe (Post 16578963)
yap, used to be 1kb file, now it's 137kb file with only 1 url in it instead of 10... hrmm

I put the code on my dev server and ran it, by the looks of it, when putting the first url to the bottom, it's putting enters in there somewhere..

quantum-x 11-23-2009 08:13 PM

Quote:

Originally Posted by Killswitch (Post 16579070)
I found it on some site, I think it's one of those ex girlfriend site pics that are on every ex gf site.



I put the code on my dev server and ran it, by the looks of it, when putting the first url to the bottom, it's putting enters in there somewhere..

That was my attempt to extort him, shhhh

Killswitch - BANNED FOR LIFE 11-23-2009 08:16 PM

Quote:

Originally Posted by quantum-x (Post 16579087)
That was my attempt to extort him, shhhh

I told him the problem, I didn't give him the fix.

Please send $1.28 to me when he pays you, for keeping my mouth shut. Thanks.

quantum-x 11-23-2009 08:24 PM

Quote:

Originally Posted by Killswitch (Post 16579098)
I told him the problem, I didn't give him the fix.

Please send $1.28 to me when he pays you, for keeping my mouth shut. Thanks.

egold ?

Killswitch - BANNED FOR LIFE 11-23-2009 08:29 PM

Quote:

Originally Posted by quantum-x (Post 16579111)
egold ?

WU please.

Doctor Feelgood 11-23-2009 09:19 PM

Quote:

Originally Posted by qwe (Post 16576081)
I want to put alot of urls into the php file, and once php file gets executed it will redirect to those urls one by one... like if I have 100 urls, once php file loads it will go to first url, then once php file get executed again it will load second url, and so on, then once it reaches the end it will start from the begging ... can someone hook me up please :)

something like this javascript popup

Code:

<!--
var how_many_ads = 3;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {url="http://www.url1.com/";}
if (ad==2) {url="http://www.url2.com/";}
if (ad==3) {url="http://www.url3.com/";}
rotpop=window.open('','rotpop','toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,top=1,left=1,width=790,height=570');
rotpop.blur();
rotpop.location=url;
-->



All times are GMT -7. The time now is 10:07 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc