dazzclub Posted March 17, 2008 Share Posted March 17, 2008 He people, A quick question, i have a page that displays a product depending on which id is passed through the url. lets call it display-product.php. Now there are several ways of getting to this page. 1) submitting a search and clicking on the retrieved result which then takes you to display-product.php and 2)browsing through a product list and then click on a product for more information which then takes you to display-product.php How can i create a link that goes back to the correct page?? kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/ Share on other sites More sharing options...
lemmin Posted March 17, 2008 Share Posted March 17, 2008 You could pass the current page as a value to display-product.php along with the product id. Or use the referer variable. Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/#findComment-494396 Share on other sites More sharing options...
dazzclub Posted March 17, 2008 Author Share Posted March 17, 2008 Hi there, using the referer variable, would that look something like $_HTTP....? kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/#findComment-494404 Share on other sites More sharing options...
lemmin Posted March 17, 2008 Share Posted March 17, 2008 $_SERVER['HTTP_REFERER']; This isn't the best method, but it is probably the easiest to implement. Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/#findComment-494409 Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 If there're only two possibilites of pages they could have come from to get to this page, it'd be pretty easy to put a $_GET variable in the URL to tell which page they came from. Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/#findComment-494416 Share on other sites More sharing options...
dazzclub Posted March 17, 2008 Author Share Posted March 17, 2008 hmmm, not the best method?? is that for secuiry reasons. I'll do more research on this topic to get a better understanding. I`ll think om gonna try with getting the id from the url. kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/#findComment-494418 Share on other sites More sharing options...
dazzclub Posted April 19, 2008 Author Share Posted April 19, 2008 Hi, I thought I'd post back my findings. What I opted to do after doing some research and with the help of you guys is to capture the id and then pass it through to the next page so the page can look at the id number and pull out the right one. so in my case i had a navigation which where a list of links. These links, if pressed go to the products case studies, case_studies.php case studies ------------------ Bud Exposed Fosters Ice Galliano Guinness Pool Heineken Jersey Diary Stella Artois Diamond White Metz Tetley Tea Tia Maria Guinness Thirstmometer Carling The first thing i should mention is that the links above are all being pulled from my table in a database using this script; <?php $casestudy = "SELECT * FROM casestudiesmenu"; $result = mysqli_query($connection, $casestudy); While ($row = mysqli_fetch_array($result)){ $case_name = $row["case_name"]; $title = $row["title"]; $id=$row["id"]; echo ' <li><a href="case-studies.php?ID=' .$row["id"]. '" title="'. $row["title"].'" class="class4" >' . $row["case_name"]. '</a></li>'; } ?> Now when i hover a link it displays, case-studies.php?ID= Now i need script that will capture the id and then retrieve the correct case study accordingly, and for this i will place the script in the case-studies.php and the script looks like this; if ( (isset($_GET['ID'])) && (is_numeric($_GET['ID'])) ) { //correctly accessed $id=$_GET['ID']; } else { $errors[] = 'You have accessed this page incorrectly.'; } { $sql = "SELECT * FROM case_studies WHERE ID = $id"; If ($r = mysqli_query ($connection, $sql)) { //sending the query to the mySQL server While ($row = mysqli_fetch_array($r)) { //inputs the data into the table $id = $row['ID']; $case_title = $row['case_title']; $content = $row['content']; $download = $row['download']; $image = $row['image']; } } } ?> [code/] This isnt meant to be a tutorial at all , i just wanted to show you guys how i had accomplished this task and if it helps anyone then thats even better eh. again thanks to everyone in this forum for their patience and help. kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/96612-capture-a-link-to-go-back-to-the-right-page/#findComment-521257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.