FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to have dynamic link button





eday2010
So here is the issue: I am redesiging a site for an organization.The site is bilingual - english and french. The menu at the top and the left side is an HTML page on it's own. All the pages main body of the site call in the menu part with a line of PHP. Here is an example image:



Here is the problem: The button in the menu to get to the french part of the site needs to go to the same page in french that the person was reading in english instead of just going to the home page for the french side. I.E - someone was reading www.site.com/en/sexytopic.html and they click on the french button in the menu; it needs to take them to www.site.com/fr/topicsexy.html instead of just www.site.com/fr/home.html. It needs to go to the french version of every page that someone is reading, and vice versa for french to english.

What kind of chaos do i need to deal with to have this happen?
LukeakaDanish
Hm...ok..

In the beginning of your "sexytopic.html" document (I'm asuming you've set it up to be parsed by php) insert the following code:
Code:
 <?php
 $address = __FILE__;
 ?>

...then wherever you want the link to go (even in other included files) add:
Code:
<?php
 echo str_replace('/en/', '/fr/', $address);
 ?>


- this replaces all occurrences of "/en/" in "$address" with "/fr/" - to get the opposite effect, swap the first two variables around!
eday2010
Excellent! I will give it a try tomorrow. I just have to make sure that I name all the files the same in both directories Smile
LukeakaDanish
eday2010 wrote:
Excellent! I will give it a try tomorrow. I just have to make sure that I name all the files the same in both directories Smile


Yep Smile - tell me if you have any trouble getting it to work...

Oh yeah..."your welcome" Wink
eday2010
I get the following error:

Quote:
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
02/20/07 10:39:15
Apache/2.2.3 (Win32) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8d mod_autoindex_color PHP/5.2.0


I am using it in a DHTML dropdown menu, but it was giving me the same error when i was using it on its own. Where exactly does
Code:
<?php
 $address = __FILE__;
 ?>


go in the document? In the <head>, after it, before it? Does it even matter? When I get the error, the address bar has this in it:

Code:
http://localhost/en/<?php%20echo%20str_replace('/en/',%20'/fr/',%20$address);%20?>
LukeakaDanish
eday2010 wrote:

Code:
<?php
 $address = __FILE__;
 ?>


go in the document? In the <head>, after it, before it? Does it even matter?


Not at all...anywhere towards the top of the document...



Your problem however appears to be that your document isn't being parsed by php. Save it as .php and upload it to your hosting account and try again...
eday2010
Which document? the menu one of the body ones? I have the .htaccess file in place with this in it:

Code:
AddType application/x-httpd-php .php .html .htm


I'd like to keep the file extensions as .html since it's less confusing for the people here that will work with the site once I am gone. They know very little about website stuff.
LukeakaDanish
eday2010 wrote:
Which document? the menu one of the body ones? I have the .htaccess file in place with this in it:

Code:
AddType application/x-httpd-php .php .html .htm


I'd like to keep the file extensions as .html since it's less confusing for the people here that will work with the site once I am gone. They know very little about website stuff.


Haha ok your more clever than i suddenly assumed (the sheer amount of noobs around can do that to me Wink)

Eh...thats kinda confusing then...the address clearly shows that the php stuff HASN'T been parsed by php (its outputted with the "echo" and <?php tags...)

I don't really know how to fix your problem sorry :/ - are you certain that the document you put the link in is also being parsed by php, is the only relevant question I can think of Confused
eday2010
PROBLEM SOLVED! Here is how it was done:

In the menu file this code was put:

Code:
<?php
   /** Take care of all scripting variables before hand... */
   // Is there French in the Script Name? If so, replace a copy of it with /en/
   if ( strstr('/fr/', $_SERVER["SCRIPT_NAME"] ) ) {
      $swapLanguageURL =  str_replace('/fr/','/en/', $_SERVER["SCRIPT_NAME"]);
      $currentLang = 'french';      
   }  else {   // It must be English, so lets swap it with /fr/
      $swapLanguageURL = str_replace('/en/','/fr/', $_SERVER["SCRIPT_NAME"]);
      $currentLang = 'english';
   }
   
?>


Then in the button this was put:
Code:
a href="<?=$swapLanguageURL;?>" ...


WOOOOOOOOT!!!!
Related topics
Creating a new Operating System
Cursor Snatcher
Tips for Tweaking Xp
Does Frihost have a link button/bar?
writing COM components in Perl
back link code
account of 1000 gigabytes
Link Space 1FRIH$ / Month --- Button Link 2FRIH$ /month
Please visit and make some comment on my site
My Personal Site
Link Button + Blogroller
Link Exchange with BabsUlvaWho!
Making a Dynamic link button
Need help making a button to go to my home page on smf
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.