Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-20-2005, 06: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
Old 06-20-2005, 08:48 AM   #2 (permalink)
jeffro
Person of interest
 
jeffro's Avatar
 
Join Date: Mar 2003
Location: New Jersey
Posts: 102
jeffro is on a distinguished road
I have very little VB experience, but this is what I see.
Here might be your problem:
Code:
If IsNull(Request.Form("gotoUrl")) And Len(Request.Form("gotoUrl")) > 2 Then
You are checking if gotoUrl is null, then checking if it is greater than 2 characters long. If you don't provide a gotoUrl, the first condition will be true, but then you check if it is greater than 2 characters long, which will be false making it skip the condition where gotoUrl is null. Try taking out:
Code:
And Len(Request.Form("gotoUrl")) > 2
Let us know if that works.
__________________
Jeffro
Linux counter#:213782
GnuPG ID: 406238E7
jeffro is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP N00b - How to check if a variable is set? or empty? helz MS Technologies ( ASP, VB, C#, .NET ) 3 11-04-2004 10:19 AM
OpenGL.dll Mr.Anderson Platform/API C++ 3 08-13-2004 10:07 AM
check if session variable is null? sde Java 3 07-07-2004 12:27 PM
what language is this? sde All Other Coding Languages 10 05-25-2004 03:57 PM


All times are GMT -8. The time now is 06:57 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting