nafetski Posted October 15, 2007 Share Posted October 15, 2007 I usually have my nose in photoshop or flash, so PHP is still very new to me. The project I've been given is to have a spanish version of our cardholder site. The way I've achieved it so far is.. Create a php file that has all of the english/spanish translations in arrays. An example would be $LINKS = array( "Home"=>array("Home","Home_SP"), "Reloadable_Cards"=>array("Reloadable Cards","Reloadable Cards_SP"), "Gift Cards"=>array("Gift Cards","Gift Cards_SP"), ); Then I declare the 0 index as english, and the 1 index as spanish. I then use the following function to output the data function getLinks($linkName){ global $ENGLISH, $SPANISH, $LINKS; // Checking current language // if (!isset($_SESSION['CURRENT_LANG'])){ $lang = $ENGLISH; } else { $lang = $_SESSION['CURRENT_LANG']; } return $LINKS[$linkName][$lang]; } So that way when I call the function getLinks with the array name, it will output the translation based on the session variable. Now, the problem that I'm having an awkward time with is actually declaring the session variable, then getting back to the page I was just at. I have 2 flags at the top of our page (one is english, one is spanish) and when they click it they are sent to a new php page, that looks like this. <?php require_once("/dms/php/libs/language/translationdata.php"); GLOBAL $SPANISH; session_start(); $_SESSION['CURRENT_LANG'] = $SPANISH; ?> <META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://localhost/mbeu"> Pretty simple (tho not sure if this is the correct way to go about things) however, the part of the code that I'm not happy with is the redirect. Currently it sends you back to the initial index of the site, but if they decide to switch translations then it's a very awkward transition. (having to renavigate to where they came from) What I would like to do is set the variable, then go right back to the page they were viewing. I tried using <A HREF="javascript:history.back()"> to accomplish this, but all it ends up doing is getting stuck in a browser loop. I'm sure there has to be some industry standard way to do this, and any help would be GREATLY appreciated. Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/73317-hello-d-setting-a-session-variable-via-a-hyperlink-then-redirect/ Share on other sites More sharing options...
joshi_v Posted October 15, 2007 Share Posted October 15, 2007 Helllo, Wants to say a word with you. when you are using global variables in a php page, they will be available in the same. They won't be accessible in the next page you post the variables. if you want them in the next page, then you can use the sessions. regarding second problem. when you used href link it is going to starting page. If you want to go back to the previous page, check what are the variables that are required to be in that page(It mught be redirecting the page due to lack of some varibales). if you use href with appending the required variables..you could be solve this issue another option is php include option. Try these options and let me know if you have any issues with it. Best of luck Joshi. Quote Link to comment https://forums.phpfreaks.com/topic/73317-hello-d-setting-a-session-variable-via-a-hyperlink-then-redirect/#findComment-369916 Share on other sites More sharing options...
nafetski Posted October 15, 2007 Author Share Posted October 15, 2007 Thanks for the reply =) Right now I already have a pretty large number of includes. The header and footer are both includes (and in the header is the link for the spanish and english php page that sets the session variable) Since it's an include, and it's used on hundreds of pages on the site - using a relative link isn't really an option for me. I'm not really sure what you mean by missing a variable. I'm still really new, could you be more specific? Quote Link to comment https://forums.phpfreaks.com/topic/73317-hello-d-setting-a-session-variable-via-a-hyperlink-then-redirect/#findComment-369923 Share on other sites More sharing options...
nafetski Posted October 15, 2007 Author Share Posted October 15, 2007 Shameless self bump, and I think I'm getting closer =P Instead of using a metaredirect I'm using <?php require_once("/dms/php/libs/language/translationdata.php"); GLOBAL $SPANISH; session_start(); $_SESSION['CURRENT_LANG'] = $SPANISH; Header ("Location: http://localhost/mbeu/index.php"); ?> As a way to set the session variable to spanish, then to redirect back to the root of the site. However, what I would LIKE to do is... In the header, I have added $_SESSION['currentpage'] = $_SERVER['PHP_SELF']; Is there a way that using the header redirect, that I can input the session variable in? That way it will redirect them to whatever page they were at last! =D Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73317-hello-d-setting-a-session-variable-via-a-hyperlink-then-redirect/#findComment-370047 Share on other sites More sharing options...
BlueSkyIS Posted October 15, 2007 Share Posted October 15, 2007 maybe header ("Location: ".$_SESSION['currentpage']); exit; Quote Link to comment https://forums.phpfreaks.com/topic/73317-hello-d-setting-a-session-variable-via-a-hyperlink-then-redirect/#findComment-370053 Share on other sites More sharing options...
nafetski Posted October 15, 2007 Author Share Posted October 15, 2007 \o/ I love you. Quote Link to comment https://forums.phpfreaks.com/topic/73317-hello-d-setting-a-session-variable-via-a-hyperlink-then-redirect/#findComment-370055 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.