Jump to content

header redirect and pagination


doddsey_65

Recommended Posts

I am using a header redirect after a user makes a post which goes to their post.

 

example they made a post which has an id of 236, then the url redirect would be

 

index.php?forum=1&topic=1&post=236#p236

 

i have the <a name> set up on each post and it works fine until the post is on a different page.

the url should be:

 

index.php?forum=1&topic=1&page=2&post=236#p236

 

but how would i be able to tell the header redirect which page to go to. I was thinking if statements like:

 

if ($number_of_results >=10) { $page = 2; }

 

but that would involve alot of if statements with no way of knowing how many pages the topic could have.

 

Is there an easier way?

Link to comment
https://forums.phpfreaks.com/topic/217540-header-redirect-and-pagination/
Share on other sites

function redirect( $url ){
if (! headers_sent( ) ){

header( "Location: ".$url );
exit( 0 );
}
echo "<script language=Javascript>document.location.href='".$url."';</script>";
exit( 0 );
} 

$test = $_POST['test'];
$page_vars = $_GET['page_vars']; //etc

if($test){
redirect('http://site.com/index.php?forum=1&topic=1&page=2&post=236#p236'); //redirect to any url
}

function redirect( $url ){
if (! headers_sent( ) ){

header( "Location: ".$url );
exit( 0 );
}
echo "<script language=Javascript>document.location.href='".$url."';</script>";
exit( 0 );
} 

$test = $_POST['test'];
$page_vars = $_GET['page_vars']; //etc

if($test){
redirect('http://site.com/index.php?forum=1&topic=1&page=2&post=236#p236'); //redirect to any url
}

 

im no expert but from the looks of your code you are assuming that i will know the page number. But thats my problem because when its inserted into the database i wont know which page number it is on to redirect to. I could use several if statements but surely theres a better way.

Archived

This topic is now archived and is closed to further replies.

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