Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool New to PHP and need urgent help!

    Hi All,

    I'm looking to do something like this but in a PHP environment. I just started in PHP and still reading up but this has the get up ASAP. It's a biligual site, and use as a switch. When in english if they want to read the same information they just click spanish. Vice versa from spanish to english.

    <%@ LANGUAGE="VBSCRIPT" %>
    <%
    sString = Request.ServerVariables("HTTP_REFERER")
    sFullFileName = Mid (sString, Instr (sString, ".asp"))
    iLen = Instr (sString, ".asp")-3
    sFileName = Mid (sString, 1, iLen)
    sExtension = Mid (sString, iLen+1, 2)
    if (sExtension = "en") Then
    sExtension = "es"
    else
    sExtension = "en"
    end if
    sNewFileName= sFileName & sExtension & sFullFileName
    Response.Redirect sNewFileName
    %>

    Thank you!

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Since you're already coding in ASP, I'd recommend DL the PHP manual.chm. It helped my transition over to PHP.
    I won't write the code for this but I'll show you what you'll need to use. Hopefully, it will help you to write it.

    ASP
    Code:
    <%@ LANGUAGE="VBSCRIPT" %>
    You don't need this above language specification in PHP.
    ASP
    Code:
    <%          %>
    PHP Code:
    <?php           ?>
    ASP:
    Code:
    sString = Request.ServerVariables("HTTP_REFERER")
    PHP Code:
     sString $_SERVER['HTTP_REFERRER']; 
    ASP
    Code:
    Mid()
    PHP Code:
    substr() 
    Not exactly identical but you can play with substr() and get what you want.

    ASP
    Code:
    Response.Redirect sNewFileName
    PHP Code:
    header(location$sNewFileName);
    exit; 
    If this isn't enough to get you started let me know.

    P.S. strlen() is used to return the string's length.
    Last edited by StupidRalph; 02-17-2006 at 01:57 AM.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #3
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh

    So far... I'm missing something but not sure!
    I may just have put up crap also...

    PHP Code:
    <?php
    $sString 
    $_SERVER['HTTP_REFERRER'];
    $sFullFileName substr($sStringstrlen($sString".php"));
    $iLen strlen($sString".php")-3;
    $sFileName substr($sString1$iLen);
    $sExtension substr($sString$iLen+12);
    if ( 
    $sExtension == "en") {
       
    $sExtension "es";
    }else{
       
    $sExtension "en";
    }
    $sNewFileName$sFileName $sExtension $sFullFileName;
    header(location$sNewFileName);
    exit;
    ?>
    Last edited by Machichi; 02-17-2006 at 03:58 AM.

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    What error are you getting?

    And actually the header parameter should have been a string. Sorry I left that out.


    PHP Code:
    <?php
    $sString 
    $_SERVER['HTTP_REFERRER'];
    $sFullFileName substr($sStringstrlen($sString".php"));
    $iLen strlen($sString".php")-3;
    $sFileName substr($sString1$iLen);
    $sExtension substr($sString$iLen+12);
    if ( 
    $sExtension == "en") {
       
    $sExtension "es";
    }else{
       
    $sExtension "en";
    }
    $sNewFileName$sFileName $sExtension $sFullFileName;
    header("Location: $sNewFileName");
    exit;
    ?>
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #5
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Warning: Wrong parameter count for strlen() in /home/babbu/public_html/lithium/lang.php on line 3

    Warning: Wrong parameter count for strlen() in /home/babbu/public_html/lithium/lang.php on line 4
    en

  • #6
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    PHP Code:
    strlen($sString".php")-
    Should be

    PHP Code:
    strlen($sString.".php")-
    . concatenates the strings.
    Omnis mico antequam dominus Spookster!

  • #7
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    I wonder why I didn't get that parse error....???
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #8
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    awesome...

    but getting

    http://bubba/lithium/en

    when it should be http://bubba/lithium/index-es.php

    so in my index-en.php I have a link going to lang.php that is this code... I want it to change the en from the file name to es.

    PHP Code:
    <?php
    $sString 
    $_SERVER['HTTP_REFERRER'];
    $sFullFileName substr($sStringstrlen($sString.".php"));
    $iLen strlen($sString.".php")-3;
    $sFileName substr($sString1$iLen);
    $sExtension substr($sString$iLen+12);
    if ( 
    $sExtension == "en") {
       
    $sExtension "es";
    }else{
       
    $sExtension "en";
    }
    $sNewFileName$sFileName.$sExtension.$sFullFileName;
    header("Location: $sNewFileName");
    exit;
    ?>

  • #9
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Echo out your 3 variables so we can see what each is outputting. And also, lets comment out the redirect until we get the script working.

    PHP Code:
    echo "sFilename = " $sFileName "<br />\n";
    echo 
    "$sExtension = " $sExtension "<br />\n";
    echo 
    "$sFullFileName = " .  $sFullFileName "<br />\n"
    PHP Code:
    <?php 
    $sString 
    $_SERVER['HTTP_REFERRER']; 
    $sFullFileName substr($sStringstrlen($sString.".php")); 
    $iLen strlen($sString.".php")-3
    $sFileName substr($sString1$iLen); 
    $sExtension substr($sString$iLen+12); 
    if ( 
    $sExtension == "en") { 
       
    $sExtension "es"
    }else{ 
       
    $sExtension "en"

    $sNewFileName$sFileName.$sExtension.$sFullFileName
    //header("Location: $sNewFileName"); 
    //exit; 

    echo "sFilename = " $sFileName "<br />\n";
    echo 
    "$sExtension = " $sExtension "<br />\n";
    echo 
    "$sFullFileName = " .  $sFullFileName "<br />\n"
    ?>
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #10
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sFilename =
    en = en
    =

    Hmmm this give a good hint

  • #11
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    NM - got it now.
    Last edited by NancyJ; 02-17-2006 at 12:43 PM.

  • #12
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    The main problem with the above script is you spelled referer wrongly

    This is what I think you're trying to do - take the url of a page and replace en with es or vice versa and if neither is found, go to the english page - this is how I would do it

    PHP Code:
    $pageName $_SERVER['HTTP_REFERER'];

    if(
    substr($pageName, -55)== "-en.php")
    {
      
    $newPage str_replace("-en.php""-es.php"$pageName);
    }
    elseif(
    substr($pageName, -55)== "-es.php")
    {
      
    $newPage str_replace("-es.php""-en.php"$pageName);
    }
    else
    {
      
    $newPage str_replace(".php""-en.php"$pageName);
    }
    header("Location: $newPage"); 
    If you didnt want to default to english and you knew there was always either -en or -es in the url then you could even shorthand it to:
    PHP Code:
    $pageName $_SERVER['HTTP_REFERER'];

    $newPage = (substr($pageName, -55)== "-en.php") ? str_replace("-en.php""-es.php"$pageName) : str_replace("-es.php""-en.php"$pageName);

    header("Location: $newPage"); 
    Last edited by NancyJ; 02-17-2006 at 01:07 PM.

  • #13
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Working for -es.php page to -en.php page but not the other way arround.

    Thank for your help people BTW

  • #14
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    which version are you using?

    Do you have a link to a live version so we can see it?

  • #15
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://lithium/index-es.php?l=3&c=e0

    While using your code...

    PHP Code:
    $pageName $_SERVER['HTTP_REFERER'];

    $newPage = (substr($pageName, -55)== "-en.php") ? str_replace("-en.php""-es.php"$pageName) : str_replace("-es.php""-en.php"$pageName);

    header("Location: $newPage"); 
    Last edited by Machichi; 02-17-2006 at 10:14 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •