Page 1 of 1

CGI - Page Serving Problem

Posted: Tue Apr 15, 2003 4:04 am
by Guest
Hi,

I have just created a script that logs the page hit and then serves up the main web page for a site, however when I serve the main page directly from the script all of the relative links become relative to my cgi-bin directory instead of to where the page is originally stored, this affects the images as well, they do not show up because their location is given to the page as a relative address to my cgi-bin.

Any ideas on how to solve this.

I am currently using an intermediate page that redirects automatically to the main page using a meta refresh, but I would really like to intergrate the logging seemlessly into my site so that the user doesn't even realise it has happened.

thanks.

Re:CGI - Page Serving Problem

Posted: Tue Apr 15, 2003 10:27 am
by AGI1122
I would have to see the code you use in the script.

Re:CGI - Page Serving Problem

Posted: Wed Apr 16, 2003 2:08 pm
by distantvoices
I wonder why he doesn't execute the script in a kind of hidden or invisible frame or picture. I do this with my php counter script. OK, it outputs the counter to the browser as a png picture.

Re:CGI - Page Serving Problem

Posted: Thu Apr 17, 2003 3:53 am
by Guest
Hi,

The script simply opens a file increments a counter then sevres up a simple page that has a META refresh on it set to 0 timeout so that it immediately redirects to my homepage. So the code is nothing special I just was looking for some ideas.

The reason I do not use it like you do in a picture is because it is used to count how many times a special link is clicked, so I do not want it executed everytime the page is accessed, I only want it executed when a special link to my site is clicked.

thanks for you ideas, I still have not solved the problem though.

thanks again.

Re:CGI - Page Serving Problem

Posted: Thu Apr 17, 2003 4:47 am
by distantvoices
is it possible to send a http header to the client via perl? in php, this is done with header(...); you need to send a full url to the browser. Maybe after this the relative links are ok too? i am not sure.

Re:CGI - Page Serving Problem

Posted: Thu Apr 17, 2003 7:08 am
by guest
Hi,

Thankyou very much, your last post inspired a search term that found exactly what I wanted.

In case anyone else finds this helpful this is the solution, you simply send the location back to the server like this:

print "Location: <URL>\n\n";

replace <URL> with the actual url that you want returned, for example to return this forums main page you would do this:

print "Location: http://www.mega-tokyo.com/forum/\n\n";

The users browser doesn't know the difference and all relative links are left intact.

thanks again.

Re:CGI - Page Serving Problem

Posted: Thu Apr 17, 2003 1:52 pm
by AGI1122
Yes use this code:

Code: Select all

print "Location: http://www.mega-tokyo.com/forum/\n\n";
That will work just fine. :)