Jump to content

Recommended Posts

I upgraded from php 4.x to 5.2 and used to be able to use the following code successfully, now it's not working:

 

<? if ($lan=="spanish") { ?>

<p class="translate"><a href="page.php">english</a></p>
<p>hola</p>

<? } else { ?>

<p class="translate"><a href="page.php?lan=spanish">english</a></p>
<p>hello</p>

<? } ?>

 

Right now that code would only give me "hola" and clicking to translate to english doesn't change the text.

 

Maybe a simple question, I'm very much a php newb. Thanks in advance.

read up on Register Globals which have been disabled in PHP5 and removed in PHP6

 

your Need to update your code ($lan to $_GET['lan'])

<? if ($_GET['lan']=="spanish") { ?>

<p class="translate"><a href="page.php">english</a></p>
<p>hola</p>

<? } else { ?>

<p class="translate"><a href="page.php?lan=spanish">english</a></p>
<p>hello</p>

<? } ?>

 

you could do

$lan = $_GET['lan'];

at the start of the page or

extract($_GET)

but i highly recommend you update your code correctly extracting user-input is a very bad move

Thanks so much, I fixed the code and it worked! Thanks for the speedy reply as well. Definitely need to brush up on my php, been a long time and the last time I used it was my first. Will "close" this thread. Thanks again.

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.