How to stop this?

Started on the old forum in February 2011 · view the original in the archive · old links redirect here

24 replies · 1,438 views · started 15 years ago · 1 min read

7 participants
arnage Lead · 811 posts #1

Sending a link to the exit page by:

/index.php?a=going&go=site.tld

On going page is:

elseif ($a == 'going') {

$go = $_GET['go'];
if (!isset($go) or $go == '' ) { exit; }
header('Location: http://'.$go.'/');

	exit;
}

Problem is that $go can be changed via url and I don't know how to block it. Have tried some ideas but nothing.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Mysterio Lead · 630 posts #2

Problem seems to easy to solve but I don't know what you really need. Try to explain once and I will help immediately.

mysterio.al - programming is a functional art

arnage Lead · 811 posts #3

Thanks mate. 🙂 Here's an example in the guest book when a visitor clicks on a posted link all is fine: "http://mysite.tld/index.php?a=going&go=POSTED_site.tld" but when in the address bar someone type a completely different link, the script sends it there. For example, "http://mysite.tld/index.php?a=going&go=ANOTHER_site.tld" < There to be blocked.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
wap2k Developer · 168 posts #4
elseif ($a == 'going') {

	$whitelist = Array(
	"google.com",
	"yahoo.co.uk"
	);

	$go = $_GET['go'];

if(!isset($go) || $go == '' || !in_array($go,$whitelist)) { exit; }
	header('Location: http://'.$go.'/');
 exit;
}

Just add the sites you wish to allow to the White List Array.

arnage Lead · 811 posts #6

wap2k wrote:

elseif ($a == 'going') {

	$whitelist = Array(
	"google.com",
	"yahoo.co.uk"
	);

	$go = $_GET['go'];

if(!isset($go) || $go == '' || !in_array($go,$whitelist)) { exit; }
	header('Location: http://'.$go.'/');
 exit;
}

Just add the sites you wish to allow to the White List Array.

Thanks for reply but i can't do it this way because visitors post their links in guest book.

khan89 wrote: u can send the data in post format. Then it will not show on address bar.

I'ld like to avoid using _post in this case.

I have tried to define the second variable and preg_match them, then false in if statement, !=, !==, return true/false... Nothing works. I have no idea.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #8

$_GET is encoded automaticly, its not problem in encoding bro. 🙂 Probably some detail... I tried now define/defined, strpos and I don't know what else have tried and still can't block it.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
something else Fellow · 2,296 posts #9
else if($a == 'going'){ 
$go = $_GET['go']; 
$link = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM table_name WHERE field_name LIKE '%".$go."%'"));
if($link[0]>0&&$go!='')
header('Location: http://'.$go.'/'); 
else
header('Location: http://back2yourSite.con');
exit; 
}
frostymarvelous Senior · 266 posts #10

As mysterio said, what do you want? Is the page a safe redirect? A redirect to your own site? What? After all, I assume a user won't click a link he doesn't want to visit.

Perfection comes at a cost

I accept liberty!

arnage Lead · 811 posts #11

something else wrote:

else if($a == 'going'){ 
$go = $_GET['go']; 
$link = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM table_name WHERE field_name LIKE '%".$go."%'"));
if($link[0]>0&&$go!='')
header('Location: http://'.$go.'/'); 
else
header('Location: http://back2yourSite.con');
exit; 
}

Thanks but i have no sql in this matter and can't figureout how to define needed data.

frostymarvelous wrote: As mysterio said, what do you want? Is the page a safe redirect? A redirect to your own site? What? After all, I assume a user won't click a link he doesn't want to visit.

But I did explain in the next post...

This is not for the lavalair, I never wanted to have a forum, and probably never will. Im trying to write my site script.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
something else Fellow · 2,296 posts #12
else if($a == 'going'){  
$go = $_GET['go'];  
if(substr_count($data,$go)>0&&$go!='') 
header('Location: http://'.$go.'/');  
else 
header('Location: http://back2yourSite.con'); 
exit;  
}
wap2k Developer · 168 posts #13

This also does what you are wanting

elseif ($a == 'going') {
$go = $_GET['go']; 

$GuestbookPostText = "Please visit my site http://wapmii.com. Thanks"; 

if(strpos($GuestbookPostText,$go)===false || !isset($go) || $go == '') { exit; } 
    header('Location: http://'.$go.'/'); 
    exit;
}
arnage Lead · 811 posts #14

Im sorry for bodering u guys but i think its not problem in processing data, its a problem to define the data to be processed. One of my last attempt yesterday was to recode guest book lines, i have add new var, $linkrow to read array from file, then foreach ($linkrow as $go) to read every row in the colon, so it can be get to matching and to display in guest book page.

Link is the same: echo ' '.$go.'';

Now in "going" exit page is:

$go = $_GET['go'];
$link = $_GET['linkrow'];
$getgo = strpos($link, $go); // preg_match also not work
if ($getgo === true) {
header('Location: http://'.$getgo.'/');
	exit;
}
else { exit; }

Of course, not work. Im gonna eat the keybord.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
frostymarvelous Senior · 266 posts #15

We want to help, but honestly, most of us don't understand what it is you want to do. Just read the replies. Everyone is assuming one thing or the other

Perfection comes at a cost

I accept liberty!

arnage Lead · 811 posts #16

For example, user post his link in my guest book. Posted link is coding-talk.com

Open xhtml source of guest book page and u will see:

/index.php?a=going&go=coding-talk.com

Copy-Paste it in ADDRESS BAR of your browser or use Opera option "Copy Link Address" and it looks this:

http://mysite.rs/index.php?a=going&go=coding-talk.com

Click ENTER it opens coding-talk.com

<<< PROBLEM >>>

In ADDRESS BAR change coding-talk.com WITH google.com:

http://mysite.rs/index.php?a=going&go=[B]google.com[/B]

Click ENTER it opens google.com

google.com IS NOT POSTED site link in the guest book and this request (added in address bar) must be terminated by calling exit;

I hope im understandable now. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
eeeh_aarrh Junior · 32 posts #17
$go = $_GET['go']; 
$link = $_GET['linkrow']; 
$getgo = strpos($link, $go); // preg_match also not work 
if ($getgo === true) { 
header('Location: http://'.$go.'/'); 
    exit; 
} 
else { exit; }

Added after 10 minutes:

Where would you get the value of the real url that is supposed to match $go?

arnage Lead · 811 posts #18

Thats what im think problem is and don't know how to define it properly. Im defined it in guest book like:

$linkrow = array($row[this]);
foreach ($linkrow as $go) {
$go = str_replace('http://', null, $go);
$go = htmlentities($go, ENT_QUOTES);
echo '
<a href="/index.php?a=going&go='.urlencode($go).'"><span class="si_y">'.$go.'</span></a>';
}
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
frostymarvelous Senior · 266 posts #19

If you want to redirect users to google if they click a link, simply use this at the top of your page

If (isset($_GET['go'])) // check if the go var is set 
{
header('Location:http://google.com');// redirect to google no matter the url which was posted. No reason to do any checks unless you wish to substitute based on a condition.
exit;//make sure the rest of the code is not run.
}

Perfection comes at a cost

I accept liberty!

arnage Lead · 811 posts #20

frostymarvelous wrote: If you want to redirect users to google if they click a link, simply use this at the top of your page

If (isset($_GET['go'])) // check if the go var is set 
{
header('Location:http://google.com');// redirect to google no matter the url which was posted. No reason to do any checks unless you wish to substitute based on a condition.
exit;//make sure the rest of the code is not run.
}

I don't want that bro. 🙂 I used coding-talk.com and google.com links just as an example. This is exactly the problem, read the last line >>>

arnage wrote: For example, user post his link in my guest book. Posted link is coding-talk.com

Open xhtml source of guest book page and u will see:

/index.php?a=going&go=coding-talk.com

Copy-Paste it in ADDRESS BAR of your browser or use Opera option "Copy Link Address" and it looks this:

http://mysite.rs/index.php?a=going&go=coding-talk.com

Click ENTER it opens coding-talk.com

<<< PROBLEM >>>

In ADDRESS BAR change coding-talk.com WITH google.com:

http://mysite.rs/index.php?a=going&go=google.com

Click ENTER it opens google.com

google.com IS NOT POSTED site link in the guest book and this request (added in address bar) must be terminated by calling exit;

I hope im understandable now. :)

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close