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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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