Jump to content

[SOLVED] How to link pages depending on which page you arrived from?


Nuccah

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.