Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: php redirect

  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    php redirect

    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?
    PHP Code:
         $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] + $urlsnip[1] . $urlsnip[2] . $urlsnip[3] . $urlsnip[4];
            
    //echo $thestringb . '<br />';
            
    $newurl str_replace($thestringa$thestringb$previousurl);
            
            echo 
    $newurl;
            
            
    header'Location: ' $newurl ) ;
    exit; 

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    you can't echo anything before header redirect, couse you'll get error
    "headers already sent..."

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    $newurl = (int) substr(basename($_SERVER['SCRIPT_NAME']), 3);
    header('Location: pg_' str_pad($newurl4'0'STR_PAD_LEFT)); 

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by matak View Post
    you can't echo anything before header redirect, couse you'll get error
    "headers already sent..."
    Any other way to do it? JavaScript?

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •