...

View Full Version : php redirect



gilgalbiblewhee
12-20-2007, 07:33 AM
I'm making a script for inserting html pages into a database table. It's a 700-page ebook convert from pdf to html with the frames of page links on the left and navigation on the top.

Within the pages, I added textareas and a submit button within a form. Everything works. THe problem is that I need to do this manually clicking each page link on the left frame 700 times.

Since the forms on each page direct to a page where it inserts into the database table I need to put a redirect somehow that will lead to the next page. For example:

I have
http://localhost/ebooks/pg_0004.php

And I want to go to:
http://localhost/ebooks/pg_0005.php

I came up with the following script to go incrementally
http://localhost/ebooks/pg_0005.php
http://localhost/ebooks/pg_0006.php...


I'm open to any other suggestions on the script but how do I redirect to the next page automatically after the inserting into the database is finished?

$myarray = explode('000', $previousurl);
foreach($myarray as $value)
{
$urlsnip = $value;
}
$thestringa = $urlsnip[0] . $urlsnip[1] . $urlsnip[2] . $urlsnip[3] . $urlsnip[4];
//echo $thestringa . '<br />';
$thestringb = $urlsnip[0] + 1 . $urlsnip[1] . $urlsnip[2] . $urlsnip[3] . $urlsnip[4];
//echo $thestringb . '<br />';
$newurl = str_replace($thestringa, $thestringb, $previousurl);

echo $newurl;


header( 'Location: ' . $newurl ) ;
exit;

matak
12-20-2007, 10:31 AM
you can't echo anything before header redirect, couse you'll get error
"headers already sent..."

Inigoesdr
12-20-2007, 01:46 PM
$newurl = (int) substr(basename($_SERVER['SCRIPT_NAME']), 3);
header('Location: pg_' . str_pad($newurl, 4, '0', STR_PAD_LEFT));

gilgalbiblewhee
12-21-2007, 01:40 AM
you can't echo anything before header redirect, couse you'll get error
"headers already sent..."

Any other way to do it? JavaScript?

Inigoesdr
12-21-2007, 02:14 AM
You could use JavaScript, or a meta refresh, or you could comment out the echo, since it doesn't do anything anyway, and use the code I posted.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum