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
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
}

Link to comment
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
}

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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