header() not the right one for redirecting after output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
orallo
Forum Newbie
Posts: 3
Joined: Thu Sep 14, 2006 11:28 am

header() not the right one for redirecting after output

Post by orallo »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi All,

I've got what should be a simple question, but I've not been able to finde the answer so far...

Here is what I am trying to do, I need to read several (large) tables from one database and import them into another database.  I'd like to set it up, so once a table has been uploaded, the page automatically goes to another php file and prints something out like "processing table 2" etc, etc.

I've tried redirecting one page to the next, etc, etc,  but the browser gets no output at all.

the code is something like this:

copydata.php

Code: Select all

<?php
$DataBaseName="Table1";
CopyDataBase($DataBaseName, $FilePath);
echo ("********** Table $DataBaseName IMPORTEd");
header( 'Location:http://localhost/ARCO/copydata1.php') ; exit;
?>
and then copydata2.php

Code: Select all

<?php
$DataBaseName="Table2";
CopyDataBase($DataBaseName, $FilePath);
echo ("********** Table $DataBaseName IMPORTEd");
header( 'Location:http://localhost/ARCO/copydata2.php') ; exit;
?>
and so on...

Basically I need to find a way to load a different page on the browser once some fucntion has done its task.

Thanks in advance.
Orallo


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

It is frobidden to output somethinl before sending a header.
If you want to send a header, you need to send the header and then output what you want.

But...

You can use META tag:

Code: Select all

<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=http://www.some.org/some.html">
</head>
<body>
.... your text ...
</body>
</html>
See more at: http://vancouver-webpages.com/META/metatags.detail.html

P.S
Remember to add [php[color]] and [code[/color]] to your posts!
Last edited by ok on Thu Sep 14, 2006 11:43 am, edited 1 time in total.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

When it has finished, move it to a page with a little javascript in that 'physically' opens a new page, otherwise it's the equivalent of having it all on one page.
orallo
Forum Newbie
Posts: 3
Joined: Thu Sep 14, 2006 11:28 am

Post by orallo »

Hi OK,

META REFRESH tags are good and all... but the problem is the table import takes different amounts of time for different tables, some take a couple of seconds and others take several minutes.

So I cant use them, is there any other way?

Thanks,
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

You can use them:

Code: Select all

<?php
$DataBaseName="Table1";
CopyDataBase($DataBaseName, $FilePath);
?>
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=http://www.some.org/some.html">
</head>
<body>
<?php
echo "Table $DataBaseName IMPORTEd";
?>
</body>
</html>
PHP will output the HTML only after you done transferring your table!
orallo
Forum Newbie
Posts: 3
Joined: Thu Sep 14, 2006 11:28 am

Post by orallo »

Hi Again OK,

Yes, that does indeed work, this solved one problem... but made another one appear.

See, the reason why I was splitting the DB upload process is because the script was talking too long and I was getting the "Fatal error: Maximum execution time of 240 seconds exceeded in C:\wwwroot\ARCO\dbfunctions.php on line 69" error. (as you see I already upped the time from 30 (default) to 240 seconds, but the table is rather big (about 30K records) and it "only" loads about 12K before it times out.

I thought splitting the process up, would help since there are many small tables and just a few big ones... but the BIG BIG ones, wont play ball...

Is there a way to do an asynchronous call or something to that effect that would allow to check on the status of things and wait till completion?

Any other Ideas?
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

1. You can use PhpMyAdmin http://www.phpmyadmin.net.
2. You can set in the begining of the PHP file:

Code: Select all

set_time_limit(0);
This will give you "no time limit".
Post Reply