Page 1 of 2 12 LastLast
Results 1 to 16 of 18

Thread: Passing variables, writing text files, etc

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Location
    Pit, stone.
    Posts
    643
    Thanks
    0
    Thanked
    0 times in 0 posts

    Passing variables, writing text files, etc

    Right. I know no VBScript, JavaScript, or anything, only a little HTML (but I'm willing to learn!).

    What I'm trying to do is this:

    Someone clicks a link on a webpage.

    The link takes them through to a redirect page on our server, which takes the place they want to go to from the address, writes that to a text file, and redirects to the end page.

    EG:

    go to www.startpage.com/links

    click the link http://www.daverobev.com/blah/defaul...=www.hexus.net

    Write www.hexus.net to www.daverobev.com/blah/data.txt

    redirect to www.hexus.net


    I can do all of the things I need to do.

    The problem is, I can't do them all at once. I'm using someone else's code from other webpages we use, plus bits and bobs learned from the net.

    We use (I think) VBScript to do the writing to text file from a form.

    I'm using JavaScript to get the url.

    So I can quite happily redirect using java and a function that gets a text string starting at the = of www.site.com?url=, and store that in a variable...and then use window.location = "http://" +variable.

    Help?
    Well Hello!

  2. #2
    Senior Member
    Join Date
    Nov 2003
    Location
    central london
    Posts
    215
    Thanks
    0
    Thanked
    0 times in 0 posts
    vbscript and javascript are clientside scripting languages. e.g. everything occurs on the visitor's machine.
    if what you're trying to do is write a file onto the clients machine, then remember that the majority of broswers disallow this, what with nasty pr0n dialers and their ilk.

    if you want to write to a file on the server you need a server-side scripting language like asp or php. i'd personally recommend php as i learnt it before i learnt a bit of asp, and i prefered the former.
    http://www.php.net/ is a good start. problem is your server must support php or asp, otherwise you could try cgi (if your webhost supports it) which seems like a monster to learn (simple programs look like you've bashed your head against the keyboard a few times.) another alternative is jsp.
    If your webhost doesn't support any of those, then erm, pay more...

    hth



  3. #3
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,773
    Thanks
    22
    Thanked
    40 times in 24 posts
    Most ASP programs are written in VBScript. If you have never done any programming before, VBScript is highly recommended as it has easy to follow syntax and easy to follow core functions.

    But don't let me influence your decision
    Simon


  4. #4
    Senior Member
    Join Date
    Jul 2003
    Location
    Pit, stone.
    Posts
    643
    Thanks
    0
    Thanked
    0 times in 0 posts
    Yeah sorry I was getting a bit confused, its ASP the stuff that I had already, not VBS (hence not having <script language="VBScript"> and </script> duh!)..

    I think I need to do this over two pages....or, 4 pages, depending how you look at it.

    Page of links -> page that gets the URL into a form -> page that writes the URL to textfile and redirects to -> where the person who clicked the link wants to go!

    And yes, the textfile is on our server, so we log the number of hits to a clients website..or rather the number of hits through the links page!
    Well Hello!

  5. #5
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,773
    Thanks
    22
    Thanked
    40 times in 24 posts
    Can be done with one page.

    Code:
    <%
    
    If not isempty(Request.Querystring("myparam")) then
        WriteToLogFile()
        Response.Redirect(QueryToURL(Request.Querystring("myparam")))
    End if
    
    Response.Write("<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?myparam=whatever"">My link</a>")
    
    %>
    WriteToLogFile() is a sub which takes care of the logging or writing to text file and QueryToURL() takes the query string and converts to your URL.

    This is just an example of a way to do what I think you're trying to do
    Simon


  6. #6
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    I thought I was the only one up this early! Shad beat me by a few minutes.

    Save the code below as linklog.asp, change the path of the log file and off you go.

    Code:
    <%@ Language=VBScript %>
    <%
        Dim szURL
        szURL = Request.QueryString("url")	
        If szURL <>  "" Then
            Dim oFSO
            Dim oLogFile
    		
            Set oFSO = CreateObject("Scripting.FileSystemObject")
            Set oLogFile = oFSO.OpenTextFile("c:\temp\log.txt", 8, True)  '8 for append
            oLogFile.WriteLine(szURL)
            oLogFile.Close
    
            SET WriteStuff = NOTHING
            SET myFSO = NOTHING
    
            Response.Redirect("http://" & szURL)
    End If
    %>
    
    <html>
    <head>
    </head>
    <body>
    
    <A href="linklog.asp?url=www.hexus.net">www.hexus.net</A>
    <BR>
    <A href="linklog.asp">www.hexus.net</A>
    
    </body>
    </html>
    Last edited by Mart; 22-11-2003 at 08:26 AM.

  7. #7
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    The other way of getting the info you need analyse your IIS logfiles. You could get some code to do this or import into excel and sort by page column and then by querystring column.

    This is the entry from my log and you can see the url passed to linklog.asp.


    2003-11-22 06:59:47 127.0.0.1 - 127.0.0.1 80 GET /doctor/linklog.asp url=www.hexus.net 302 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)

  8. #8
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,773
    Thanks
    22
    Thanked
    40 times in 24 posts
    Nice post Mart

    I'd advise against putting the target url in the query string though, anybody could put their own url in an manipulate your logs.

    Maybe base64 encode it or use a table of urls and only pass a primary key.

    I mean if you want to take it further, what's there will work nicely
    Simon


  9. #9
    Senior Member
    Join Date
    Jul 2003
    Location
    Pit, stone.
    Posts
    643
    Thanks
    0
    Thanked
    0 times in 0 posts
    I think I get most of that...could you clarify a couple of things please Mart?

    szURL...what does the sz stand for? I get oObject, and things like cCharacter and dDate..

    Where in that

    szURL = Request.QueryString("url")

    bit does it strip out the current URL and only take the bit past ?URL=...does Querystring do that? If so, how does it read the current URL of the page in?

    If not, where is the bit that reads the page location?

    I'm not stupid, I'm just finding my feet with this OOP stuff!

    And thanks to all for the help, I could just use a few more comments in the code like...this line means this, etc. I'd much rather be given the building blocks and find the solution myself than have it all handed to me

    Ta,

    Dave
    Well Hello!

  10. #10
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    The answers in order.....

    1. I use sz for string variables , comes from being a Visual C++ developer. (see Hungarian notation)

    2. The querystring is all of the text in a url after the question mark. It is made up of name=value pairs. Each pair is seperated by &. In the example there is only 1 pair. The QueryString method of the Request object takes a name and returns its associated value. (If it exists). It saves you having to dig through the querystring text yourself.

    3. All the links within the page point back to the page itself. The url of the destination is passed as a querstring variable. If there is a name value pair with name 'url' then the code will retrieve the value and redirect the page to the destination.

    So all the links would have to like.....

    <A href="linklog.asp?url=www.hexus.net">Go to hexus!</A>

    instead of.....

    <A href="www.hexus.net">Go to hexus!</A>

    The last link would miss out the logging step completely and go straight to the destination.
    Last edited by Mart; 22-11-2003 at 11:02 PM.

  11. #11
    Senior Member
    Join Date
    Jul 2003
    Location
    Pit, stone.
    Posts
    643
    Thanks
    0
    Thanked
    0 times in 0 posts
    Hi,

    makes sense, I was kinda mulling it over in my head in bed last night and had kinda thought thats probably what it meant (the querystring...well, its querying a string isn't it!), what with my ASP book helping too...

    Thanks for the help!
    Well Hello!

  12. #12
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,773
    Thanks
    22
    Thanked
    40 times in 24 posts
    Sounds like you've already got a book, but 'Beginning Active Server Pages 3.0' by Wrox is an excellent place to start if you need another
    Simon


  13. #13
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    Glad to hear you figured it out.

    Shad, I have a collection of bearded freaks on my bookshelf too

    Mart

  14. #14
    Senior Member
    Join Date
    Jul 2003
    Location
    Pit, stone.
    Posts
    643
    Thanks
    0
    Thanked
    0 times in 0 posts
    What have I got for reading at the moment, hmm..

    ASP Programming for the Absolute Beginner by John Gosney

    Absolute Beginners Guide to C 2nd ed. by Perry

    HTML for the World Wide Web 5th ed by Castro

    Linux: The Complete Reference: 4th ed

    and some Visual FoxPro book at work.

    Well, it'll give me something to read over christmas, right??
    Well Hello!

  15. #15
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    The MSDN website is also a mine of information msdn.microsoft.com.

    ASP Objects + methods reference:

    http://msdn.microsoft.com/library/de...tm/ref_asp.asp

  16. #16
    Put him in the curry! Rythmic's Avatar
    Join Date
    Jul 2003
    Location
    Twyford, Berks
    Posts
    758
    Thanks
    1
    Thanked
    0 times in 0 posts
    Absolute essential is Microsofts Platform SDK:

    http://www.microsoft.com/msdownload/...sdk/sdkupdate/

    Everything you need to know about MS products (except certain servers such as SQL and Exchange that have their own documentation)
    Now go away before I taunt you a second time.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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