Referer Page

If I put a link in this page when listing an item for sale:

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=1360970503

and my link will be like this:

http://mysite.com/url.asp?CODE=test

Can I do a script that will display two things:
1) The ebay item ID from the referer page
2) Code from the link I inserted into the page

I tried to do this but can't finish it:

--------------

<%
Dim URL ' As String

URL = Request.ServerVariables("HTTP_REFERRER")

response.write "<HTML><HEAD></HEAD><BODY>Your Ebay Item Number is: <br>"
response.write URL
response.write "</BODY></HTML>"


%>
amira123Asked:
Who is Participating?
 
jsmckenzieCommented:
0
 
jsmckenzieCommented:
Not all servers send a referrer, so you can't guarantee that HTTP_REFERRER will always have a value.
0
 
amira123Author Commented:
Well, I am specifically trying to do this with Ebay.  Do you know if ebay does or does not?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
jsmckenzieCommented:
Sorry -- meant to say not all browsers send referrer info.
0
 
jsmckenzieCommented:
plus ebay would have to put a link to your page in order to get the referrer information (doubtful, but you could always ask...).  If you are putting the link with the item number in the page, why would you need to get the number from somewhere else?  Perhaps I don't understand what you're trying to do.

You can display the info from your link by using this:

Response.Write Request.QueryString("CODE")
0
 
amira123Author Commented:
Ebay item numbers are addigned automatically by ebay once an item is inserted by me for an auction.

I can insert the link to my page by way of adding the link to the item description.

So we do need to do this this way:

1) Get the code number from my link that that is in the description area.

2) Get the ebay item number from the referere link

What would the code look like?
0
 
jsmckenzieCommented:
sorry--haven't really used ebay.

so if you came from the ebay page your referrer would be http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=1360970503.  So to display the item number (assuming that the referrer information gets passed to your page, and assuming that the item number is the last thing on the URL) you could do something like this:

sReferrer = Request.ServerVariables("HTTP_REFERRER")
iItemPosition = InStr(sReferrer,"item=")
iItemNumber = Right(sReferrer,Len(sReferrer)-iItemPosition)
Response.Write "Your item number is " & iItemNumber

then to get the code from your link:

sCode = Request.QueryString("CODE")
Response.Write "The code is " & sCode


0
 
jsmckenzieCommented:
you might have to make it:

iItemPosition = InStr(sReferrer,"item=") + 5
0
 
amira123Author Commented:
Ok it gives this error:

Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'Right'

/scripts/ebay_refer/url.asp, line 4
0
 
Michel SakrCommented:
all major browsers send referer data.. and since 95% are using IE and 4% NS you'll get it..
0
 
amira123Author Commented:
ok so I got this to work:

<%

page = request.servervariables("HTTP_REFERER")
response.write "The page that refered you is<br>" & page & "<p>"

sCode = Request.QueryString("CODE")
Response.Write "The code is<br>" & sCode

%>

now i need to examine the value page and fine this pattern:
item=xxxxxx

and extract the xxxxx from it whatever number of characters is this xxxxx made up of.

How is that done?
0
 
jsmckenzieCommented:
ok -- it should be:

iItemPosition = InStr(sReferrer,"item=") + 4

instead of

iItemPosition = InStr(sReferrer,"item=") + 5

That should get you the item number.


It's true that almost all browsers can return a refer value, but in some you can turn it off, and if you cut & paste a URL you won't get the correct refer info.  So you'll want to check for an empty referrer (and empty item number):

sReferrer = Request.ServerVariables("HTTP_REFERRER")

If Len(sReferrer) > 0 Then
   iItemPosition = InStr(sReferrer,"item=")
   If iItemPosition > 0 Then
      iItemNumber = Right(sReferrer,Len(sReferrer)-iItemPosition)
      Response.Write "Your item number is " & iItemNumber
   Else

      Response.Write "Can't get the item number."  

   End If

Else

  Response.Write "Can't get the HTTP_REFERRER"

End If
0
 
amira123Author Commented:
Well something is wrong with this code because it works the way I posted earlier.

Can you post your complete code so I can test it too?

Thanks
0
 
amira123Author Commented:
I am sorry, i meant to say that the code i posted earlier works but the one you posted dosent.  It says "Can't get the HTTP_REFERRER".  I don't understand what am I doing wrong?
0
 
jsmckenzieCommented:
sReferrer = Request.ServerVariables("HTTP_REFERER")
sItemName = "item="

If Len(sReferrer) > 0 Then
  iItemPosition = InStr(sReferrer, sItemName) + (Len(sItemName) - 1)
  If iItemPosition > 0 Then
     iItemNumber = Right(sReferrer, Len(sReferrer)-iItemPosition)
     Response.Write "Your item number is " & iItemNumber
  Else

     Response.Write "Can't get the item number."  

  End If

Else

 Response.Write "Can't get the HTTP_REFERER"

End If
0
 
amira123Author Commented:
I thought I was losing my mind.  Thanks a bunch!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.