php redirect

Discussion in 'PHP' started by gilgalbiblewheel, Dec 19, 2007.

  1. #1
    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;
    PHP:
     
    gilgalbiblewheel, Dec 19, 2007 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    
    if (mysql_query("INSERT INTO table VALUES ('whatever') WHERE something = 'something'")) {
        header("Location: whatever");
        exit;
    }
    
    PHP:
     
    Kaizoku, Dec 19, 2007 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    What does the insert do? If it's to insert the values into the db I have that. That's not a problem.

    I'm concerned about:
    1. how to add +1 to 0004.php to make it 0005.php
    2. How to redirect to 0005.php.
     
    gilgalbiblewheel, Dec 19, 2007 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    Why did you wrote this then...
    Anyways..
    
    $currentPage = substr($_SERVER['PHP_SELF'], 0, -4);
    $nextPage = sprintf("%04d", $currentPage + 1) . ".php";
    header("Location: " . $nextPage);
    
    PHP:
     
    Kaizoku, Dec 20, 2007 IP
  5. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    It says :

    
    $currentPage = substr($_SERVER['PHP_SELF'], 0, -4);
    $nextPage = sprintf("%04d", $currentPage + 1) . ".php";
    header("Location: " . $nextPage); //line 120
    PHP:
     
    gilgalbiblewheel, Dec 20, 2007 IP
  6. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    Even when I echo it doesn't show the current page and the next:
    $currentPage = substr($_SERVER['PHP_SELF'], 0, -4);
    $nextPage = sprintf("%04d", $currentPage + 1) . ".php";
    echo $currentpage;
    echo $nextpage;
    //header("Location: http://localhost/ebooks/pg_0005.php");
    //header("Location: " . $nextPage);
    PHP:
     
    gilgalbiblewheel, Dec 20, 2007 IP
  7. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #7
    If you don't mind using a bit of html:

    
    $currentPage = substr($_SERVER['PHP_SELF'], 0, -4);
    $nextPage = sprintf("%04d", $currentPage + 1) . ".php";
    echo "<meta HTTP-EQUIV=REFRESH content=0; url=$nextPage>";
    
    Code (markup):
    Try that.

    BTW: I think your echo does not work because you have to put:
    
    echo "$current[B]P[/B]age";
    Code (markup):
     
    tushardhoot1, Dec 20, 2007 IP
  8. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    I think that would be the best option.
    Is there a way to give it a few seconds before redirecting?
     
    gilgalbiblewheel, Dec 20, 2007 IP
  9. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Change content=0 to however many seconds you wish.
     
    tushardhoot1, Dec 20, 2007 IP
  10. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #10
    Something seems wrong though. When I echo the nextPage it shows pg_0001.php. It doesn't redirect to the proper page. I'll have a second look at it.
     
    gilgalbiblewheel, Dec 20, 2007 IP
  11. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #11
    You need to exit after a php redirect
    
    $currentPage = substr($_SERVER['PHP_SELF'], 0, -4);
    $nextPage = sprintf("%04d", $currentPage + 1) . ".php";
    header("Location: " . $nextPage);
    exit;
    
    PHP:
     
    Kaizoku, Dec 20, 2007 IP
  12. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #12
    I tried it. It doens't work. I think the best option is to go with HTML or JavaScript.
     
    gilgalbiblewheel, Dec 20, 2007 IP
  13. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #13
    $currentPage = substr($_SERVER['PHP_SELF'], 0, 7);
    $nextPage = sprintf("%04d", $currentPage + 1) . ".php";
    echo "<meta HTTP-EQUIV=REFRESH content=0; url=$nextPage>";

    Just a guess...might not work.
     
    tushardhoot1, Dec 20, 2007 IP
  14. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #14
    I think it needs quotes around the url right? But still didn't work.
    <meta HTTP-EQUIV=REFRESH content=10; url='http://localhost/ebooks/pg_0005.php'>
    Code (markup):
     
    gilgalbiblewheel, Dec 20, 2007 IP
  15. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #15
    there's a problem:

    My previous page is:

    http://localhost/ebooks/pg_0004.php

    The current page is:
    http://localhost/ebooks/inserttext.php
    This is where the script is found:
    echo "<meta HTTP-EQUIV=REFRESH content=10; url=" .$newurl. ">";
    PHP:
    When I echo $newurl; it gives me what I need:
    New URL: http://localhost/ebooks/pg_0005.php
    But it never goes there. Should I put the relative path or absolute ( including the http:...but it doesn't work.)


    The next page is:
    http://localhost/ebooks/pg_0005.php
     
    gilgalbiblewheel, Dec 20, 2007 IP
  16. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #16
    "<meta HTTP-EQUIV=REFRESH content=10; url=$newurl>"

    The first " canceled out the second " in yours.
     
    tushardhoot1, Dec 20, 2007 IP
  17. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #17
    What do you mean?
    Does it have to be in the head section? Maybe that's why it doesn't work.
     
    gilgalbiblewheel, Dec 20, 2007 IP
  18. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #18
    No it doesn't.

    I mean when you put:

    echo "<meta HTTP-EQUIV=REFRESH content=10; url=" .$newurl. ">";

    The sever automatically links the 2 red ones and the 2 navy ones. The double quotes at the start of the echo makes sure the script checks for any variables, so that covers that.

    Or you can do:

    echo '<meta HTTP-EQUIV=REFRESH content=10; url=" .$newurl. ">';
     
    tushardhoot1, Dec 20, 2007 IP
  19. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #19
    Sorry buddy. Just realized you need it between <head></head>

    My Bad..

    Sorry once again.
     
    tushardhoot1, Dec 20, 2007 IP
  20. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #20
    But it still doesn't work:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    <meta HTTP-EQUIV=REFRESH content=10; url="http://localhost/ebooks/pg_0005.php" />	
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<title>Untitled Document</title>
    	</head>
    Code (markup):
    It refreshes the page instead of redirecting.
     
    gilgalbiblewheel, Dec 20, 2007 IP