Nuccah Posted April 6, 2009 Share Posted April 6, 2009 I'm new to PHP, and while I've gotten along with working on a website by mimicking and using trial and error for most of my problems, making some codes have proven to be difficult. This is what I need some help with: The website has 3 languages: english, spanish, french. All use different pages (eg. index_eng, index_sp, etc) What I need to figure out is how to have them converge into a single page (eg video.php) and then, depending on where they originally came from, automatically redirect them to the next page (by language) after the video is done (or by clicking the Skip Video link). Help is greatly appreciated.. I've been trying to figure this out for hours. Quote Link to comment Share on other sites More sharing options...
JD* Posted April 6, 2009 Share Posted April 6, 2009 You should be able to use $_SERVER['HTTP_REFERER'] to get the page that they came from, parse out the last part of the url with a strstr and then store that in a variable for when you go to do the redirection. Of course, that hinges on the fact that they will hit your index page first, then the video and not go straight to it. Quote Link to comment Share on other sites More sharing options...
Nuccah Posted April 6, 2009 Author Share Posted April 6, 2009 You should be able to use $_SERVER['HTTP_REFERER'] to get the page that they came from, parse out the last part of the url with a strstr and then store that in a variable for when you go to do the redirection. Of course, that hinges on the fact that they will hit your index page first, then the video and not go straight to it. My fault, reading that over I didn't explain it as well as I should have. The initial page they are coming from is one of those index pages. EG: page1_eng, clicks on link, goes to the video page, watches or skips video, and is directed to their final destination. I need to be able for that final destination to be in the language from the initial page as the video page is universal. Quote Link to comment Share on other sites More sharing options...
JD* Posted April 6, 2009 Share Posted April 6, 2009 As per what I posted, on the video page you can query the referring page (where they came from) to get the last URL. You can then do a split based on the _, since that seems to be common, by doing an explode, which will turn your url into an array. Then just get the last piece of the array, which will have your eng/sp/etc, which you can then use to say "forward me to next_whatever.php" $url = $_SERVER['HTTP_REFERER']; $url = explode("_", $url); That goes at the top of your page. Then, you can write to your link echo '<a href="next_'.$url[1].'.php">Click here to skip/continue</a>'; And that will take them to the next page with the proper follow. Just make sure "next" is your page name, and you may have to check on which part of the array you need to get if there is more than one underscore (_) in your url. Quote Link to comment Share on other sites More sharing options...
Nuccah Posted April 6, 2009 Author Share Posted April 6, 2009 As per what I posted, on the video page you can query the referring page (where they came from) to get the last URL. You can then do a split based on the _, since that seems to be common, by doing an explode, which will turn your url into an array. Then just get the last piece of the array, which will have your eng/sp/etc, which you can then use to say "forward me to next_whatever.php" $url = $_SERVER['HTTP_REFERER']; $url = explode("_", $url); That goes at the top of your page. Then, you can write to your link echo '<a href="next_'.$url[1].'.php">Click here to skip/continue</a>'; And that will take them to the next page with the proper follow. Just make sure "next" is your page name, and you may have to check on which part of the array you need to get if there is more than one underscore (_) in your url. After the explode takes the en, fr, sp, w/e after the _, is there a way to set a boundary between the _ and the .php at the end? (index_en.php) The final destination looks like cars.php?cat=302&lang=en.php with the script working (after taking out the extra .php you added in) I need it to look like cars.php?cat=302&lang=en Quote Link to comment Share on other sites More sharing options...
JD* Posted April 6, 2009 Share Posted April 6, 2009 I'm sure there is a better way with a regular expression or some such, but you could split it again with an explode based on the ".", then get the [0] place of it Quote Link to comment Share on other sites More sharing options...
Nuccah Posted April 7, 2009 Author Share Posted April 7, 2009 I'm sure there is a better way with a regular expression or some such, but you could split it again with an explode based on the ".", then get the [0] place of it I decided to go a different route and used an elseif statement which worked perfectly since there are only 3 possible outcomes. Thanks for your help. Quote Link to comment 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.