View Single Post
Old 06-20-2005, 07:51 AM   #1 (permalink)
jcpp
Registered User
 
Join Date: Jun 2005
Posts: 1
jcpp is on a distinguished road
Check if variable is empty or is not set.

Hi all,

I'm trying to create an redirect script.
I want to post a variable 'gotoUrl' (form) to the script. The script must redirect to the url specified in 'gotoUrl'. This is no problem.
But:
When I go directly to this script, by typing the url, I have no 'gotoUrl' specified. The script must redirect me to a defaultUrl.
If I submit a form to this script, but the 'gotoUrl' is empty, this script must redirect me to the HTTP_REFERER.

The script you find below is almost working. The only thing that is nog working yet, is the redirect to the defaultUrl.

Can anyone help me please?

Code:
<%
Option Explicit

dim strGotoUrl, strDomain, strBaseUrl, strDefaultUrl

strDefaultUrl = "http://www.google.com/"
strDomain = Request.ServerVariables("SERVER_NAME")
strBaseUrl = "http://" & strDomain

If IsNull(Request.Form("gotoUrl")) And Len(Request.Form("gotoUrl")) > 2 Then
      Response.Redirect(strDefaultUrl)
ElseIf Request.Form("gotoUrl") = "" Then
      Response.Redirect(Request.ServerVariables("HTTP_REFERER"))
Else
      If InStr(Request.Form("gotoUrl"), "http://") <= 0 Then
      'interne links'
            strGotoUrl = strBaseUrl & Request.Form("gotoUrl")
      Else
      'externe links'
            strGotoUrl = Request.Form("gotoUrl")
      End if

      If strGotoUrl = "noValue" Or strGotoUrl = "" Then
            Response.Redirect(Request.ServerVariables("HTTP_REFERER"))
      Else
            Response.Redirect(strGotoUrl)
      End If
End IF
%>
jcpp is offline   Reply With Quote