doddsey_65 Posted November 2, 2010 Share Posted November 2, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/217540-header-redirect-and-pagination/ Share on other sites More sharing options...
dreamwest Posted November 2, 2010 Share Posted November 2, 2010 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 } Quote Link to comment https://forums.phpfreaks.com/topic/217540-header-redirect-and-pagination/#findComment-1129338 Share on other sites More sharing options...
doddsey_65 Posted November 2, 2010 Author Share Posted November 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217540-header-redirect-and-pagination/#findComment-1129352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.