Jump to content

Getting 'Cannot redeclare' Error and trying to find a workaround


Jeffro

Recommended Posts

I have a page1.php which calls page1insert.php via require_once.  page1insert.php has about 10 functions and then does a database insert. 

 

This works great.

 

The problem...

 

I have about 100 different page1's (page1.php, page2.php, etc..) that need to call 100 of these different insert.php pages (all doing different database inserts to the same database/table).  Running these all individually works great but I'm wanting to figure out a way to run all 100 as a cron job.  I thought I could just create a new cron.php page and put the following in:

 

include 'page1.php';

include 'page2.php';

include 'page3.php';

include 'page4.php';

etc...

 

Unfortunately, as soon as it hits page2insert.php this gives: Cannot redeclare clean_url() (previously declared in...  /mypath/ of page1insert.php.

 

Any idea what's causing this and how I might make it work?  When I google this, it says that using a require_once will resolve the problem but that's not happening.  Since all my insertpages have different names and are being called separately by each page1 (page2, page3, etc), I didn't think this would be an issue. 

 

Thanks for any help. 

I'm guessing that in every insert file you're redefining the "clean_url()" function, and perhaps more after. Move all of these generic function(s) into a file of their own and require_once that separately within each insert file. You need to include it there and not within the cron file so that theycan still be used separately.

I'm guessing that in every insert file you're redefining the "clean_url()" function, and perhaps more after. Move all of these generic function(s) into a file of their own and require_once that separately within each insert file. You need to include it there and not within the cron file so that theycan still be used separately.

 

Thank you!  You were exactly right and it worked.  Whew!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.