?
Solved

redirect

Posted on 2006-06-01
21
Medium Priority
?
310 Views
Last Modified: 2013-12-25
hello,
I would like to create a CGI script In languaje C
very simple for my website lets say the name
is redirect.cgi so if I click on a link like this
www.domain.com/redirect.cgi?link=www.google.com
it goes directly to google! how can I do that ?
thanks
0
Comment
Question by:aplelois
  • 11
  • 4
  • 4
19 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16806028
/* your usual C-stuff here */
/* you'll get "link=www.google.com" in enviornment variable QUERY_STRING which you need to parse yourself */
printf("HTTP/1.0 302 Moved\nLocation:http://www.other.tld\n\n");
exit(0);
0
 

Author Comment

by:aplelois
ID: 16811691
I dont really have any c stuff
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16812137
Do you want to write it in C?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:aplelois
ID: 16812888
yes
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16813086
So which specific bits do you need help with?

ahoffmann has answered your question about the redirects.

Are you wanting information about how to parse CGI parameters with C?  If so, look at http://www.boutell.com/cgic/
0
 

Author Comment

by:aplelois
ID: 16813114
no, I want to create a really simple app called "redirect.cgi"
so if im at index.html and I make a link to google.com
I want to use the redirect this way
<a href="cgi-bin/redirect.cgi?link=www.google.com">Google</a>
<a href="cgi-bin/redirect.cgi?link=www.yahoo.com">Yahoo</a>

get me ?
0
 

Author Comment

by:aplelois
ID: 16813281
so what do you guys say ?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16813424
So if you know how to parse CGI parameters with C and ahoffman has given you the code to do the redirect, what's left?
0
 

Author Comment

by:aplelois
ID: 16813462
in php is very simple

html code
<a href="redirect.php?link=http://www.yahoo.com">Yahoo</a>

php code

<?php
header("Location: " . $_GET['link']);
die();
?>


so if anyone knows how to do it in cgi c please show it to me thanks!!
0
 

Author Comment

by:aplelois
ID: 16813469
it doesnt really have to be C it can be C++ too
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16813845
if you still have the solution in PHP, why do you need one in C?
In my fist post I gave you all the relevant parts to do it, you just have to fill in the usual C stuff to get it working.

If you have any problems post your current code and describe which problems your have with it.
0
 

Author Comment

by:aplelois
ID: 16813869
>>if you still have the solution in PHP, why do you need one in C?
because I want to learn how to do it in other languje like c or c++

>>In my fist post I gave you all the relevant parts to do it, you just have to fill in the usual C stuff to get it working.
this is what I have and is not working

#include <stdio.h>

int main()
{

   printf("HTTP/1.0 302 Moved\n);
   printf("Location:http://www.google.com\n\n");
   exit(0);
}
0
 

Author Comment

by:aplelois
ID: 16813878
ok this works

#include <stdio.h>

int main()
{

   printf("Location:http://www.google.com\n\n");
   exit(0);
}
0
 

Author Comment

by:aplelois
ID: 16813881
but how can I do it like this

<a href="redirect.cgi?link=http://www.yahoo.com">Yahoo</a>
0
 

Author Comment

by:aplelois
ID: 16813887
and this gives me an error

#include <stdio.h>

int main()
{
   printf("Location: " . $_GET['link']);
   exit(0);
}
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 2000 total points
ID: 16814030
>  printf("Location: " . $_GET['link']);
this is invalid C syntax
You better get a good book about C programming (plain old K&R from 197x is best:).
It's not very helpfull if we explain basic C syntax here.
Please make yourself used to C first.

> .. $_GET['link'])
makes no sence in C, as I said in my very first post http:#16806028 you have to read the value of link from the environment variable QUERY_STRING

> because I want to learn how to do it in other languje like c
but your question was about "how to do redirect in C" which is answerd now.
0
 

Author Comment

by:aplelois
ID: 16814040
well, i see that im not going to get the answer here so im asking in CS to delete this question.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16815393
for what did you not get an answer?
You do not mean an answer to "how to proram C", do you?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16838333
As previously mentioned, to parse CGI parameters with C or C++, you need a CGI library.

See http://www.boutell.com/cgic/

This contains plenty of example C code for parsing CGI parameters.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question