CGI - Page Serving Problem

Programming, for all ages and all languages.
Post Reply
Guest

CGI - Page Serving Problem

Post 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.
AGI1122

Re:CGI - Page Serving Problem

Post by AGI1122 »

I would have to see the code you use in the script.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:CGI - Page Serving Problem

Post 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.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Guest

Re:CGI - Page Serving Problem

Post 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.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:CGI - Page Serving Problem

Post 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.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
guest

Re:CGI - Page Serving Problem

Post 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.
AGI1122

Re:CGI - Page Serving Problem

Post by AGI1122 »

Yes use this code:

Code: Select all

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