Skip to main content
mindmastery
Known Participant
February 18, 2020
Answered

PHP code guru please

  • February 18, 2020
  • 2 replies
  • 2231 views

Hi guys,

I was just wondering if anyone would know how to do this, with PHP - I used to mess around with PHP  on an old site, but have forgotten most of it...   Here's what I need to do - I want to place the same internal link on several dozen different pages on my site (we might call these pages A1, A2, A3 etc), which will all direct the users to the same page (page 'B') - however when they arrive at page B, I need it to display an entire page of 'unique' product info, relevent only to the (various A1, A2, A3 etc) pages they clicked through from.   Hope that makes sense.

eg.  If page A1 was about apples, then once they clicked the internal link through to page B, they would see apples displayed, on page B.   But if they clicked through from page A2, which was about oranges - they would instead see oranges on page B.  

I know this is achievable, I just dont remember the code that is needed to do it.   Any thoughts, or even a link to a tutorial that will show me how to do this, would be much appreciated : )

Cheers,

Craig

 

This topic has been closed for replies.
Correct answer Paul-M

OK, simple as possible might be to name your include files simply for example like apples.php oranges.php plums.php

so you now redirect using a paramemter like Ben said, for example:

 

 

mypage.php?product=apples
mypage.php?product=oranges
mypage.php?product=plums

 

 

 

On you target page create a variable and create the include filename from the url paramter, like this (assuming it will always have a value):

 

 

 

<?php
$filename = $_GET['product'];
include $filename.".php";
?>

 

 

 

 

2 replies

Legend
February 18, 2020

Ideally you want your product information in a database, then you would create a query filtered by the URL parameter

Paul-M - Community Expert
mindmastery
Known Participant
February 18, 2020

Ahhh, OK - thanks Paul.  Thats definitely getting way beyond my knowledge level, as I have only dealt with the 'include' folder for this stuff previously.   Good thought though, many thanks - it could certainly be outsourced if need be.

Cheers,

Craig  

Paul-MCorrect answer
Legend
February 18, 2020

OK, simple as possible might be to name your include files simply for example like apples.php oranges.php plums.php

so you now redirect using a paramemter like Ben said, for example:

 

 

mypage.php?product=apples
mypage.php?product=oranges
mypage.php?product=plums

 

 

 

On you target page create a variable and create the include filename from the url paramter, like this (assuming it will always have a value):

 

 

 

<?php
$filename = $_GET['product'];
include $filename.".php";
?>

 

 

 

 

Paul-M - Community Expert
BenPleysier
Community Expert
Community Expert
February 18, 2020

Are you referring to URL parameters as in <a href="product.php?id=oranges>Go to oranges</a>

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
mindmastery
Known Participant
February 18, 2020

Hi Ben,
Thanks for your reply.  Yes, that is definitely half of the equation solved, thanks!     Then.. my issue would be getting oranges to only appear on page B when the reader has clicked through from the 'orange' page - this seems somewhat curlier.   ie. If I placed code something like this on Page B  <?php include("include/oranges.php"); ?>  it would display oranges to the apple readers (and all the other fruits ; ) as well - not sure how I can get it to discern the apple readers from the orange readers : )    Many thanks for your thoughts.

Cheers,

Craig