new entry function

Post Reply
sourceuno
Posts: 225
Joined: Mon Apr 09, 2001 3:58 pm

new entry function

Post by sourceuno »

I've written a search script that displays search results as links to certain sites. I want to be able check if the site exists after the user clicks the link. I've used the following entry function to redirect the user, but it isn't accepting the URL parameter.

<A NAME=redirect someurl PUBLIC>
<fetch $someurl>
<if $ret ne "">
<header NAME="Location" VALUE=$someurl>
<exit>
<else>
Site doesn't exist.
</if>
</A>

<a name=main public>
<a href="$url/redirect.html?someurl=www.somesite.com/subdir/somefile.htm">Click here.</a>
</a>

What's wrong with this script?
bart
Posts: 251
Joined: Wed Apr 26, 2000 12:42 am

new entry function

Post by bart »

The problem is that you're not really passing the parameter, it's coming from the CGI environment. Rewrite the function declaration like this and it will work as
expected:

<A NAME=redirect PUBLIC>
...
</a>

In your program above the "more-local" variable is overriding the value coming from the CGI environment.
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

new entry function

Post by Kai »

Actually, that URL syntax is ok, since parameters to entry functions are initialized from global (therefore CGI) variables if no default value is given.

There are two problems. One is that your URL isn't fully-qualified, which <fetch> and the Location header expect; it should be http://www.somesite.com/subdir/somefile.htm. Also, the scope qualifier PUBLIC must come before any parameters:

<A NAME=redirect PUBLIC someurl>

otherwise it's taken as a parameter name. So your function was really PRIVATE (undeclared functions are PRIVATE if they have parameters), so using it as the entry function would just enter at <main> instead.
bart
Posts: 251
Joined: Wed Apr 26, 2000 12:42 am

new entry function

Post by bart »

Oops.. I guess I better RTM.
Post Reply