Browser Drops URL Query Variables

the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Browser Drops URL Query Variables

Post by the_wesley_watkins »

I am trying to use a browser to display an HTML page, and the HTML needs to start with certain URL query variables but the Browser drops everything after the filename.

Code: Select all

URL$ = "index.html?var=6"
BROWSER "n" URL URL$ AT 0,0 SIZE SCREEN_WIDTH(), SCREEN_HEIGHT()
However, when the browser loads up, the "var=6" is dropped from the url.

Code: Select all

PRINT "URL: " & BROWSER_TEXT$("n", document.baseURI)
returns only "index.html"

What can I do!?

the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Re: Browser Drops URL Query Variables

Post by the_wesley_watkins »

I've noticed it's only with local files that this happens.

If you used URL Variables for a website, they are kept. For example,

Code: Select all

URL$ = "http://kibernetik.pro/forum/viewtopic.php?f=26&t=1971" /* this forum */
BROWSER "n" URL URL$ AT 0,0 SIZE SCREEN_WIDTH(), SCREEN_HEIGHT() 
sB actually loads this specific forum. It seems to just not work with local files...

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Browser Drops URL Query Variables

Post by GeorgeMcGinn »

There is no difference between the var=6 in the first post, and the f=26 in your second post.

I've had no issues with dropping of any variables in a URL.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Re: Browser Drops URL Query Variables

Post by the_wesley_watkins »

I agree! Other than the fact that in the first example, I am loading a browser with a locally stored html file, and on the other, I am loading a website from the internet. Here's some code to help understand what I'm dealing with:

Code: Select all

URL1$ = "test.html?var=6"
BROWSER 1 URL URL1$ AT 0,500 SIZE SCREEN_WIDTH(), 100
URL2$ = "http://kibernetik.pro/forum/viewtopic.php?f=26&t=1974"
BROWSER 2 URL URL2$ AT 0,650 SIZE SCREEN_WIDTH(), 100


PRINT "URL1$:"
PRINT url1$
PRINT
PRINT "Browser 1 URL:"
PRINT "" & BROWSER_TEXT$("1", "document.baseURI")

PRINT
PRINT

PRINT "URL2$: "
PRINT url2$
PRINT
PRINT "Browser 2 URL:"
PRINT BROWSER_TEXT$("2", "document.baseURI")
And the result is
IMG_0409.PNG
IMG_0409.PNG (345.31 KiB) Viewed 2993 times
Notice how even though the URL1$ variable has the URL Variable "var=6", it is dropped when you load it in the browser initially. However, the ones for the link leading to this forum remain...

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Browser Drops URL Query Variables

Post by GeorgeMcGinn »

Wesley,

Here is a program that I use to test URLs, including the execution of CGI Scripts.

I'll look as I haven't run this for a while, but I believe it is all there, and the code is well commented. Ask if you have any questions.

I commented out the "PRINT HTTP Response=R$" statement as that will print the HTML, which in most cases, will exceed the buffer and at the top you will miss the messages.

Also, create a DATA Directory and place the file "HTTPErrorDescription.txt" into it, also attached here, as if you do get an error, it has more detailed info about it.

NOTE: This blog will not allow file extensions with .file or .data, so I changed it to .txt in the attachment and in the code as well. Ignore the comments about this being a .file unless you want to change it back.

Code: Select all

' CGIScript.sb - This program will execute your PERL CGI Script and produce
'                       a detailed error report. Useful in catching major issues
'                       with your script and/or network. 
' NOTE: Program will also work on PHP, as it will also return a response and
'           status code that this program will interpret.
'
' A file accompanies this program with all the details from the RFC2616 
' document to display all the status code syntax messages. 
'
' *** /DATA/HTTPErrorDescription.file                                 ***
' *** DO NOT MODIFY THAT FILE AT ALL - PROGRAM INDEXES INTO THIS FILE ***
'

OPTION BASE 1

' Sample variables to hold parameters to pass to CGI Script
PC$="passcode123"
FL$="/DATA/VM-SARA_20061010.txt"

' URL goes into U$. Below shows how to pass params with quotes.
' Replace "yourserver.com" with the name of the server your script resides
REM U$ ="http://www.yourserver.com/cgi-bin/uplink.pl?a="&CHR$(34)&FL$&CHR$(34)
REM U$="http://www.yourserver.com/cgi-bin/weather.cgi"
U$="http://www.ebay.com/itm/Apple-IMac-27-inch-Desktop-DCPN241KFQPG-Late-2013/152608345572?_trksid=p2047675.c100009.m1982&_trkparms=aid%3D888007%26algo%3DDISC.MBE%26ao%3D1%26asc%3D45041%26meid%3D1322a27812c344dba91444acbe840aa2%26pid%3D100009%26rk%3D1%26rkt%3D2%26sd%3D263046127574"

A$=""
H$(1) = "content-type:text/html"
H$(2) = "content-length:"&LEN(A$)

PRINT "CGI Script Execute/Debug"!PRINT!PRINT
PRINT "URL to execute: ";U$

' Execute CGI Script and Check for Error Responses
HTTP U$ HEADER H$ POST A$
E$=HTTP_ERROR$
R$=HTTP_RESPONSE$()
S$=HTTP_STATUS()

PRINT
PRINT "   HTTP Error: ";E$
PRINT "  HTTP Status: ";S$
'*** PRINT "HTTP Response: ";R$

' IF HTTP_STATUS is not 200, execute Error Reporting
IF VAL(S$) > 200 THEN
   HTTP_ERROR(S$)
   PRINT
   PRINT
   PRINT!PRINT MSG$
   PRINT!PRINT
   I=1
   DO
      PRINT ERR_SYNTAX$(I)
      I=I+1
   UNTIL ERR_SYNTAX$(I) = ""
   GOTO endprog
ELSE
   IF S$="0" OR S$="" THEN
      PRINT
      PRINT
      PRINT!PRINT "Your script was not parsed due to an unidentified error."
      PRINT "Please check your CGI Script as this error is either a parsing"
      PRINT "or header error."
      GOTO endprog
   ENDIF   
ENDIF   

PRINT!PRINT "Program ended normally"               

endprog:
   STOP


DEF HTTP_ERROR(S$)
'------------------------------------------------------------------------
' Retrieve message and URL to search for error message.
' If Status=200, then set message to OK - Normal End of Process
' Otherwise, build the error message to show code, message, document URL
' and section to search for resolution.
'

    URL$="http://www.ietf.org/rfc/rfc2616.txt"
    ERR_DESC$="/DATA/HTTPErrorDescription.txt"
    Tempstr$=""
    S=S$
    SC=40
    ES=42
    .MSG$=""
    DIM IX(5)!IX(1)=1!IX(2)=3!IX(3)=10!IX(4)=17!IX(5)=35 
    DIM ERR_S$(SC),ERR_L$(SC),ERR_M$(SC), E_Section$(ES),E_Start(ES),E_End(ES)
    DIM .ERR_SYNTAX$(100)
    FOR I=1 TO SC
        READ ERR_S$(I),ERR_L$(I),ERR_M$(I)
    NEXT I    

    FOR I=1 TO ES
        READ E_Section$(I),E_Start(I),E_End(I)
    NEXT I    

' Find the Error Message
    S1=VAL(LEFT$(S$,1))
    S=IX(S1)
    FOR I=S TO SC
        IF ERR_S$(I)=S$ THEN
           IF S$="200" THEN
              .MSG$="OK: "&S$&" – Normal End of Process"
              I=SC
           ELSE   
              .MSG$="ERROR: "&S$&" – "&ERR_M$(I)&" – Description below from "&ERR_L$(I)&" in "&URL$
              ERR_Section$=ERR_L$(I)
              I=SC
           ENDIF
        ENDIF   
    NEXT I

    Section$=RIGHT$(ERR_Section$,7)
    IF LEFT$(Section$,1) = " " THEN Section$=RIGHT$(Section$,6)
    SLen=LEN(Section$)

    FOR I=1 TO ES
        E_Section$(I)=LEFT$(E_Section$(I),SLen)
        IF Section$=E_Section$(I) THEN
           Start_Line=E_Start(I)!End_Line=E_End(I)
           FOR X=1 TO Start_Line
               FILE ERR_DESC$ READLINE Tempstr$
           NEXT X  
           IF X-1=Start_Line THEN
              .ERR_SYNTAX$(1)=Tempstr$
              Z=1
              Start_Line=Start_Line+1
              FOR Y=Start_Line TO End_Line
                  Z=Z+1
                  FILE ERR_DESC$ READLINE Tempstr$
                  .ERR_SYNTAX$(Z)=Tempstr$
              NEXT Y
           ENDIF
        ENDIF
    NEXT I                             

'---------------------------------------------------------------------------
' ERROR MESSAGE DATA
DATA "100","Section 10.1.1","CONTINUE"
DATA "101","Section 10.1.2","Switching Protocols"
DATA "200","Section 10.2.1","OK"
DATA "201","Section 10.2.2","Created"
DATA "202","Section 10.2.3","Accepted"
DATA "203","Section 10.2.4","Non-Authoritative Information"
DATA "204","Section 10.2.5","No Content"
DATA "205","Section 10.2.6","RESET Content"
DATA "206","Section 10.2.7","Partial Content"
DATA "300","Section 10.3.1","Multiple Choices"
DATA "301","Section 10.3.2","Moved Permanently"
DATA "302","Section 10.3.3","Found"
DATA "303","Section 10.3.4","See Other"
DATA "304","Section 10.3.5","NOT Modified"
DATA "305","Section 10.3.6","Use Proxy"
DATA "307","Section 10.3.8","Temporary Redirect"
DATA "400","Section 10.4.1","Bad Request"
DATA "401","Section 10.4.2","Unauthorized"
DATA "402","Section 10.4.3","Payment Required"
DATA "403","Section 10.4.4","Forbidden"
DATA "404","Section 10.4.5","NOT Found"
DATA "405","Section 10.4.6","Method NOT Allowed"
DATA "406","Section 10.4.7","NOT Acceptable"
DATA "407","Section 10.4.8","Proxy Authentication Required"
DATA "408","Section 10.4.9","Request TIME-out"
DATA "409","Section 10.4.10","Conflict"
DATA "410","Section 10.4.11","Gone"
DATA "411","Section 10.4.12","Length Required"
DATA "412","Section 10.4.13","Precondition Failed"
DATA "413","Section 10.4.14","Request Entity Too Large"
DATA "414","Section 10.4.15","Request-URI Too Large"
DATA "415","Section 10.4.16","Unsupported Media Type"
DATA "416","Section 10.4.17","Requested range NOT satisfiable"
DATA "417","Section 10.4.18","Expectation Failed"
DATA "500","Section 10.5.1","Internal Server Error"
DATA "501","Section 10.5.2","NOT Implemented"
DATA "502","Section 10.5.3","Bad Gateway"
DATA "503","Section 10.5.4","Service Unavailable"
DATA "504","Section 10.5.5","Gateway TIME-out"
DATA "505","Section 10.5.6","HTTP Version NOT supported"

' 43 DATA Entries – Section #,START LINE #, END LINE # (Index File)
DATA "10.1.1",1,10
DATA "10.1.2",11,24
DATA "10.2.1",25,39
DATA "10.2.2",40,56
DATA "10.2.3",57,72
DATA "10.2.4",73,82
DATA "10.2.5",83,99
DATA "10.2.6",100,107
DATA "10.2.7",108,147
DATA "10.3.1",148,168
DATA "10.3.2",169,190
DATA "10.3.3",191,215
DATA "10.3.4",216,234
DATA "10.3.5",235,271
DATA "10.3.6",272,281
DATA "10.3.7",282,285
DATA "10.3.8",286,305
DATA "10.4.1",306,310
DATA "10.4.2",311,325
DATA "10.4.3",326,328
DATA "10.4.4",329,337
DATA "10.4.5",338,347
DATA "10.4.6",348,353
DATA "10.4.7",354,377
DATA "10.4.8",378,387
DATA "10.4.9",388,392
DATA "10.4.10",393,411
DATA "10.4.11",412,430
DATA "10.4.12",431,436
DATA "10.4.13",437,443
DATA "10.4.14",444,453
DATA "10.4.15",454,464
DATA "10.4.16",465,469
DATA "10.4.17",470,484
DATA "10.4.18",485,490
DATA "10.5.1",491,494
DATA "10.5.2",495,500
DATA "10.5.3",501,505
DATA "10.5.4",506,517
DATA "10.5.5",518,526
DATA "10.5.6",527,535
DATA "10.9.9",999,999

ENDDEF


Attachments
HTTPErrorDescription.txt
(26.2 KiB) Downloaded 222 times
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Re: Browser Drops URL Query Variables

Post by the_wesley_watkins »

None of this is server side. It's all locally on the iPhone/iPad.

I have an HTML file stored in a "lib" Folder.

I am using it as the URL for a Browser. (i.e. BROWSER "n" URL "lib/index.html?var=6" AT 0,0 SIZE 100,100).

However, what I am saying is the "var = 6" at the end of the URL gets truncated. And this only happens with local HTML files. If you use a link to a website as the URL for the browser, (i.e. BROWSER "n" URL "viewtopic.php?f=26&t=1971" AT 0,0 SIZE 100,100), the URL variables "f=26" and "t=1971" remain.

I know this because when I return the current URL of the browser using BROWSER_TEXT$("n", "document.baseURI"), the browser displaying the local HTML file has dropped the "var = 6", yet the browser displaying the link to a website has kept the "f=26" and "t=1971"

I'm doing all of this on client side, not server side.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Browser Drops URL Query Variables

Post by Mr. Kibernetik »

This kind of URL: viewtopic.php?f=26&t=1974 is not a HTML file URL. It is a command to PHP script.

the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Re: Browser Drops URL Query Variables

Post by the_wesley_watkins »

Regardless, I guess my question is just how can I load a local HTML file into a browser and include variables in the URL?

When my application starts, I need to pass a url variable to the url because I have some local client side javascript that uses the variable.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Browser Drops URL Query Variables

Post by Mr. Kibernetik »

the_wesley_watkins wrote:
Mon Sep 18, 2017 4:45 pm
Regardless, I guess my question is just how can I load a local HTML file into a browser and include variables in the URL?

When my application starts, I need to pass a url variable to the url because I have some local client side javascript that uses the variable.
Maybe we have HTML experts here who can comment.
Why do you think it is possible to include variables in the URL?

the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Re: Browser Drops URL Query Variables

Post by the_wesley_watkins »

I already have a program that does this.

Version 1 loads up "index.html" and uses anchor tags to go to other pages (such as <a href="lesson.html?lessonnumber=1">Lesson 1</a>) and it works fine with that, meaning I am able to pull the "lessonnumber=1" out of the URL in my javascript file.

In Version 2, I want to START the program by passing a URL variable to "index.html", such as "index.html?coins=24"

However, when I run

Code: Select all

BROWSER "n" URL "index.html?coins=24" AT 0,0 SIZE 500,500
the "?coins=24" gets truncated(dropped) from the URL. I know this because

Code: Select all

BROWSER_TEXT("n", "document.baseURI")
returns only "index.html".

I need access to the "coins = 24" to start my program properly. I keep it saved locally in a file, and when the user starts up the app, I want to send it in to the HTML.

Post Reply