PathUrl()

PathUrl()

Postby Ruth » Mon Jun 03, 2024 4:50 pm

Dear friends,

I use PathUrl() and it perfectly returns to me the relative path such as "/folder/subfolder".

Maybe someone could advise me an equally nice function for the full URL, including protocol and domain name like "https://example.com/folder/subfolder".

ChatGPT told me to work around this with AP_HeadersIn(). Is this the correct way to do it?

Kind regards to all and many thanks in advance,
Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: PathUrl()

Postby karinha » Mon Jun 03, 2024 5:01 pm

Good afternoon Ruth, 1000 pardons for my ignorance, but can you tell me what it is: PathUrl() ??

Buenas tardes Ruth, 1000 perdones mi ignorancia, pero ¿puedes decirme qué es: PathUrl() ??

Gracias, tks.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: PathUrl()

Postby Ruth » Mon Jun 03, 2024 5:11 pm

Dear Mr. Santos,

I have to say sorry...maybe I should have posted in Mod_Harbour. Sometimes I confuse everything :)
I use the PathUrl() from here
https://github.com/FiveTechSoft/mod_harbour/wiki/Functions-provided-by-the-mod-Harbour

Very kind regards and thank you
Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: PathUrl()

Postby Ruth » Tue Jun 04, 2024 10:20 am

Dear friends,

now I have the URL with the formula AP_GetEnv("HTTPS") + AP_HeadersIn + PathUrl().

Code: Select all  Expand view  RUN
 

    if AP_GetEnv( "HTTPS" )  = "on"
        cUrl := "https://"
else
cUrl := "http://"        
    endif
    cUrl += AP_HeadersIn()["Host"]
    cUrl += PathUrl()
   
    ? cUrl


Maybe someone is interested in our cheetsheet where we store what we need very often in this context. I politely use the chance to post it here...maybe it is helpful for someone. This would be great :)



Kind regards to all of you and have a nice day,
Ruth


Code: Select all  Expand view  RUN

STATIC hApp := {=>}

function main
    local cTest := "my Test"
    local cHtml :="<H1>Title</H1>"    
    local cUrl := ""
   
   
    ? 'hb_GetEnv( "PRGPATH" )   ... PRGPATH DOS'
    hApp["cPRGPATH"] := hb_GetEnv( "PRGPATH" )
    ? hb_GetEnv( "PRGPATH" )
   

    ? "<hr>"

    ?  'STRTRAN( hb_GetEnv( "PRGPATH" )  ,"/","\")'
    hApp["cPRGPATH"] := STRTRAN( hApp["cPRGPATH"]  ,"/","\")
    ? STRTRAN( hb_GetEnv( "
PRGPATH" )  ,"/","\")
   
 

    ? "
<hr>"

   
    ? 'AP_GetEnv("
DOCUMENT_ROOT")   ...  Document Root of Apache'
    ? AP_GetEnv("
DOCUMENT_ROOT")
   
    ? "
<hr>"
   
    ? 'DOCUMENT_ROOT DOS: STRTRAN( AP_GetEnv( "
DOCUMENT_ROOT" )  ,"/","\")'
    hApp["
cdocroot"] := STRTRAN( AP_GetEnv( "DOCUMENT_ROOT" )  ,"/","\")
    ? STRTRAN( AP_GetEnv( "
DOCUMENT_ROOT" )  ,"/","\")
   
    ? "
<hr>"

    ? 'noslashending(hApp["
cdocroot"])'
    hApp["
cdocroot"] := noslashending( hApp["cdocroot"] )
    ? noslashending( hApp["
cdocroot"] )

   
   

    ? "
AP_FileName()"
    ? AP_FileName()

    ? "
<hr>"

    ? 'AP_GetEnv("
HTTPS")'
    ?  AP_GetEnv("
HTTPS")

   
    ? "
<hr>"

    ? "
<hr>"
    ? "
<hr>"
    ? "
<hr>"


    ? "
<b>url formula</b>"    
    ? 'AP_GetEnv("
HTTPS") + AP_HeadersIn + PathUrl()'
    ? AP_GetEnv("
HTTPS")
   
    if AP_GetEnv( "
HTTPS" )  = "on"
        cUrl := "
https://"
else
cUrl := "http://"        
    endif
    cUrl += AP_HeadersIn()["Host"]
    cUrl += PathUrl()
   
    ? cUrl

    ? "<hr>"
    ? "<hr>"
    ? "<hr>"




    ? "<hr>"
   
    ? "<hr>"

    ? "<b>Umgebungsvariablen</b>"
    ? " "
    ? "-------------------------------------------------------------------------------"
    ? "ALLUSERSPROFILE"
    ? hb_GetEnv( "ALLUSERSPROFILE" )
    ? "-------------------------------------------------------------------------------"
    ? "APPDATA"
    ? hb_GetEnv( "APPDATA" )
    ? "-------------------------------------------------------------------------------"
    ? "CLIENTNAME"
    ? hb_GetEnv( "CLIENTNAME" )
    ? "-------------------------------------------------------------------------------"
    ? "COMMANDER_DRIVE"
    ? hb_GetEnv( "COMMANDER_DRIVE" )
    ? "-------------------------------------------------------------------------------"
    ? "COMMANDER_EXE"
    ? hb_GetEnv( "COMMANDER_EXE" )
    ? "-------------------------------------------------------------------------------"
    ? "COMMANDER_INI"
    ? hb_GetEnv( "COMMANDER_INI" )
    ? "-------------------------------------------------------------------------------"
    ? "COMMANDER_PATH"
    ? hb_GetEnv( "COMMANDER_PATH" )
    ? "-------------------------------------------------------------------------------"
    ? "CommonProgramFiles"
    ? hb_GetEnv( "CommonProgramFiles" )
    ? "-------------------------------------------------------------------------------"
    ? "CommonProgramFiles(x86)"
    ? hb_GetEnv( "CommonProgramFiles(x86)" )
    ? "-------------------------------------------------------------------------------"
    ? "CommonProgramW6432"
    ? hb_GetEnv( "CommonProgramW6432" )
    ? "-------------------------------------------------------------------------------"
    ? "COMPUTERNAME"
    ? hb_GetEnv( "COMPUTERNAME" )
    ? "-------------------------------------------------------------------------------"
    ? "ComSpec"
    ? hb_GetEnv( "ComSpec" )
    ? "-------------------------------------------------------------------------------"
    ? "FP_NO_HOST_CHECK"
    ? hb_GetEnv( "FP_NO_HOST_CHECK" )
    ? "-------------------------------------------------------------------------------"
    ? "HOMEDRIVE"
    ? hb_GetEnv( "HOMEDRIVE" )
    ? "-------------------------------------------------------------------------------"
    ? "HOMEPATH"
    ? hb_GetEnv( "HOMEPATH" )
    ? "-------------------------------------------------------------------------------"
    ? "LOCALAPPDATA"
    ? hb_GetEnv( "LOCALAPPDATA" )
    ? "-------------------------------------------------------------------------------"
    ? "LOGONSERVER"
    ? hb_GetEnv( "LOGONSERVER" )
    ? "-------------------------------------------------------------------------------"
    ? "NUMBER_OF_PROCESSORS"
    ? hb_GetEnv( "NUMBER_OF_PROCESSORS" )
    ? "-------------------------------------------------------------------------------"
    ? "OS"
    ? hb_GetEnv( "OS" )
    ? "-------------------------------------------------------------------------------"
    ? "Path"
    ? hb_GetEnv( "Path" )
    ? "-------------------------------------------------------------------------------"
    ? "PATHEXT"
    ? hb_GetEnv( "PATHEXT" )
    ? "-------------------------------------------------------------------------------"
    ? "PROCESSOR_ARCHITECTURE"
    ? hb_GetEnv( "PROCESSOR_ARCHITECTURE" )
    ? "-------------------------------------------------------------------------------"
    ? "PROCESSOR_ARCHITEW6432"
    ? hb_GetEnv( "PROCESSOR_ARCHITEW6432" )
    ? "-------------------------------------------------------------------------------"
    ? "PROCESSOR_IDENTIFIER"
    ? hb_GetEnv( "PROCESSOR_IDENTIFIER" )
    ? "-------------------------------------------------------------------------------"
    ? "PROCESSOR_LEVEL"
    ? hb_GetEnv( "PROCESSOR_LEVEL" )
    ? "-------------------------------------------------------------------------------"
    ? "PROCESSOR_REVISION"
    ? hb_GetEnv( "PROCESSOR_REVISION" )
    ? "-------------------------------------------------------------------------------"
    ? "ProgramData"
    ? hb_GetEnv( "ProgramData" )
    ? "-------------------------------------------------------------------------------"
    ? "ProgramFiles"
    ? hb_GetEnv( "ProgramFiles" )
    ? "-------------------------------------------------------------------------------"
    ? "ProgramFiles(x86)"
    ? hb_GetEnv( "ProgramFiles(x86)" )
    ? "-------------------------------------------------------------------------------"
    ? "ProgramW6432"
    ? hb_GetEnv( "ProgramW6432" )
    ? "-------------------------------------------------------------------------------"
    ? "PROMPT"
    ? hb_GetEnv( "PROMPT" )
    ? "-------------------------------------------------------------------------------"
    ? "PSModulePath"
    ? hb_GetEnv( "PSModulePath" )
    ? "-------------------------------------------------------------------------------"
    ? "PUBLIC"
    ? hb_GetEnv( "PUBLIC" )
    ? "-------------------------------------------------------------------------------"
    ? "SESSIONNAME"
    ? hb_GetEnv( "SESSIONNAME" )
    ? "-------------------------------------------------------------------------------"
    ? "SystemDrive"
    ? hb_GetEnv( "SystemDrive" )
    ? "-------------------------------------------------------------------------------"
    ? "SystemRoot"
    ? hb_GetEnv( "SystemRoot" )
    ? "-------------------------------------------------------------------------------"
    ? "TEMP"
    ? hb_GetEnv( "TEMP" )
    ? "-------------------------------------------------------------------------------"
    ? "TMP"
    ? hb_GetEnv( "TMP" )
    ? "-------------------------------------------------------------------------------"
    ? "USERDOMAIN"
    ? hb_GetEnv( "USERDOMAIN" )
    ? "-------------------------------------------------------------------------------"
    ? "USERDOMAIN_ROAMINGPROFILE"
    ? hb_GetEnv( "USERDOMAIN_ROAMINGPROFILE" )
    ? "-------------------------------------------------------------------------------"
    ? "USERNAME"
    ? hb_GetEnv( "USERNAME" )
    ? "-------------------------------------------------------------------------------"
    ? "USERPROFILE"
    ? hb_GetEnv( "USERPROFILE" )
   

    ? "<hr>"
   
 
   
   
    ? "javascript document.location"
    ?"<script>document.write(document.location)</script>"

    TEMPLATE
    <script>
    document.write(document.location)
    </script>
ENDTEXT

? "<hr>"


? "Page path is (javascript)"
?"<script>document.write(document.location.pathname)</script>"
TEMPLATE
<script>
document.write(document.location.pathname)
</script>
ENDTEXT


? "<hr>"



? "--------------------------------------"
? "check if a call is from http or https HTTPS:// return is on"
? AP_GetEnv( "HTTPS" )

? "--------------------------------------"
? "mod harbour PathUrl()"
? PathUrl()

? "--------------------------------------"
? 'hb_GetEnv( "PRGPATH" )'
? hb_GetEnv( "PRGPATH" )
? "--------------------------------------"

/*
AP_RPuts( uValue )  Sends a value, converted into a string, to the client. Returns nil  ...
AP_PostPairs() --> Hash returns a hash with all POST pairs, key and value   ...
AP_SetContentType( cType )  sets the type of the response page
*/


? "--------------------------------------"
? 'AP_HeadersIn()  Hash returns a hash with all headers pairs, key and value'
? ValToChar( AP_HeadersIn() )
? 'AP_HeadersIn()["Host"]'

? AP_HeadersIn()["Host"]

? "--------------------------------------"
? 'AP_UserIP()  cUserIP returns the IP, as string, of the client '
? AP_UserIP()

? "--------------------------------------"
? "<h3>AP_Body()  Returns the request body as a string</h3>"
? AP_Body()
? "--------------------------------------"

? 'AP_Method()  returns "GET" or "POST" according to the client request'
? AP_Method()
? "--------------------------------------"

? "AP_FileName() --> cFileName  returns the filename.prg provided to Apache by the client"
? ValToChar(AP_FileName())
? "--------------------------------------"

? "AP_GetPairs() --> Hash   returns a hash with all GET pairs, key and value "
? ValToChar(AP_GetPairs())
? "--------------------------------------"

? "AP_Args() --> cArgs  returns the args provided to Apache by the client if any "
? ValToChar( AP_Args() )
? "--------------------------------------"


TEMPLATE PARAMS cTest, cHtml
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>

<br>
{%hb_GetEnv("PRGPATH")%}

<br>
<?prg return  hb_GetEnv("PRGPATH")  ?>

<br>
<?prg return  cHtml  ?>

<p>./testinclude.prg</p>

<br>

{% MemoRead( hb_GetEnv( "PRGPATH" ) + "/testinclude.prg" ) %}


<br>

<a href="#?test=<?prg return cTest ?>">Pasa variable <?prg return cTest ?></a>
</body>

</html>

ENDTEXT

return

//----------------------------------------------------------------------------//

function noslashending( cPathMask )  // returns cPathMask without slash ending
    local cTmp := ALLTRIM( cPathMask )
   
    if right(cTmp,1) = "\" .or. right(cTmp,1) = "/"
        cPathMask := left( cPathMask, ( len(cPathMask)- 1 ) )
    endif
return cPathMask  
//---------------------------------------------------------------------------//
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 33 guests