|
Post by votan on Jul 8, 2008 9:59:47 GMT -5
Well, might be a dumb noob-question.. but how can I pass variables from one RB script to another script that gets called via the "run" command from inside the first script?
|
|
jerry
Junior Member
Posts: 83
|
Post by jerry on Nov 25, 2018 21:34:37 GMT -5
10 years and not a single reply.... Votan, if you are still here... search for GLOBAL in the help document. Just what you need!
|
|
|
Post by donnybowers on May 9, 2021 14:32:00 GMT -5
I've been looking for an answer to the same question. But what he was asking isn't how to make a variable GLOBAL in one program. He wanted to pass a variable into another program called up by the RUN command. One might need to be able to do this for various reasons. My reason is that I need to pass a username from one program (section of my website) to another so that the user doesn't have to log in every time they go to another section of the site.
|
|
|
Post by meerkat on May 10, 2021 6:17:19 GMT -5
I normally use the UserInfo$ variable to pass information when running another program. Granted my systems are not big. Usually around 20 different programs. One system is about 80+ programs. I always need the userNumber + other info. It is always passed from one program to another program that has been RUN. There are other ways to pass info like the UrlKey$ There is other info available - try this and see what you get; print "UrlInfo";UserInfo$ print "UrlKey";UrlKey$ print "UserAddress";UserAddress$ print "ProjectRoot";ProjectRoot$ print "ResourceRoot";ResourceRoot$
|
|
|
Post by donnybowers on May 10, 2021 17:09:17 GMT -5
Eureka! Thank you meerkat!
What I can do is have a directory for temp files. Using UserAddress$ as the file name I can pass the all the information I need on the user in a text file with the person's user address as the file name. The program will scan that directory and if it finds a file with the correct user address it will open that file and get the username and anything else the program might need to continue with what they're trying to do. Then just delete the file once the info is in memory. It's perfect because the user address is unique. Thank you very much! I don't know why I didn't think of that before.
|
|
|
Post by StefanPendl on May 11, 2021 6:24:16 GMT -5
If multiple users are behind the same firewall they will share the external IP address of that firewall. So it can be that multiple users share the same IP address. How about adding a unique ID for each user in the database that saves the user credentials? The unique ID would be used to identify the user + password combination.
|
|
|
Post by donnybowers on May 11, 2021 16:59:44 GMT -5
If multiple users are behind the same firewall they will share the external IP address of that firewall. So it can be that multiple users share the same IP address. How about adding a unique ID for each user in the database that saves the user credentials? The unique ID would be used to identify the user + password combination. Very good point! I intend to have a database, and each user will have a unique ID. But when you enter a program cold it has no idea who you are and has no way to identify you other than the IP address. If the user clicks on a link that takes them to another program, there either has to be a way to pass an identifier to that new program or else they have to log in again on the new page. If I can pass just a username then I can use that user name to look them up in the database and get whatever information I had them enter at registration and any permissions they may be granted on the site. But if I can't pass anything from one program to the next the database does no good in this case. You could put the users IP address into the database, but IP addresses are not always static, especially with cell phones. Plus if their name starts with a Z you would have to read through the entire database before you would find it, slowing down your web page. How can the program tell who just came online on the page (other than their IP address) unless there's a way to pass some kind of identifier to that program? I see your point about multiple people sharing the IP address. I'm sure my wife and I both have the same IP address because we're both using the same router. Maybe I just have to design my site around having to sign in every time you want to post something. And hopefully in the future Carl will be able to add the CommandLine$ function which is really all you would need for this kind of thing. That would be the perfect command for this because it's already part of most of the popular BASIC dialects. The only time my users will need credentials is when they're posting something to the site. In the mean time they'll just have to get used to doing all their posting in one session and then surfing the site without their credentials. If they wanted to send someone a message or something they would just have to log in again. I'm not crazy about it, but this I can work around.
|
|
|
Post by donnybowers on May 11, 2021 17:13:46 GMT -5
Eureka! Just add the username to the filename. Have the program count if there are multiple instances of the same IP and if so then you would have to have the user re-verify. 0=not logged in, 1=one person with that address, 2=two people with the same address etc.
So the file name might look something like this:
DonnyBowers-127.0.0.1 (an address we all share. LOL)
the hyphen being the delimiter. Just this would be enough to prevent another user from the same IP from logging into the wrong account. Usernames are required to be unique. Remember too that the file would be deleted immediately after the person was authorized so it would be rare for two people at the same IP address to have a file there at the same time.
The only thing I don't like about this method is the extra wear on the storage media, but you gotta do what you gotta do until there's a way to pass a variable from one program to the next. I'm sure something like CommandLine$ will be in the next version of RB. It's actually a post and request thing on the network, but what better language for a simple variable pass then CommandLine$ in a BASIC web language.
|
|
|
Post by donnybowers on May 11, 2021 18:50:46 GMT -5
I normally use the UserInfo$ variable to pass information when running another program. Granted my systems are not big. Usually around 20 different programs. One system is about 80+ programs. I always need the userNumber + other info. It is always passed from one program to another program that has been RUN. There are other ways to pass info like the UrlKey$ There is other info available - try this and see what you get; print "UrlInfo";UserInfo$ print "UrlKey";UrlKey$ print "UserAddress";UserAddress$ print "ProjectRoot";ProjectRoot$ print "ResourceRoot";ResourceRoot$ Here's what I get when I run that code: UrlInfo: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0 UrlKey: UserAddress: 127.0.0.1 ProjectRoot: ResourceRoot:
UserAddress$ and UrlInfo$ give you the most information when you're trying to learn about your user.
|
|
|
Post by StefanPendl on May 12, 2021 9:01:34 GMT -5
The equivalent to the CommandLine$ variable for desktop programs is the UrlKey$ variable for web applications. If you use my example of the other thread to submit variables at the "command line" = URL for the web you will receive something like:
?app=program2&sid=my_unique_session_id The full url to test this would be:
http://localhost:8008/seaside/go/runbasicpersonal?app=program2&sid=my_unique_session_id Where program2 is the name of the RB source code posted above published as a program.
|
|