homepage Welcome to WebmasterWorld Guest from 54.163.139.36
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Header Location Function
EricEC

5+ Year Member



 
Msg#: 3796220 posted 8:05 pm on Nov 28, 2008 (gmt 0)

Hello,

I have been researching the header location function and I can't seem to find an answer to my question. I do not know if I am asking this right, but is there a way to do this...

Say you have your site http://example.com

Whenever a user clicks a game, he goes to example.com/game/...

When the user clicks the "play game" button, he goes to play the game at say example.com/playgame/...

Now there are multiple games on the site so every game goes from arcade.com/game/... to example.com/playgame/...

Is there a way to use the header location function to send a user to multiple sites?

For example... The user is at example.com/game/1. He clicks the game and is forwarded on to another site to play the game. A different user is also on and is at example.com/game/2. He clicks the game to play and is forwarded on to a different site to play his game.

Is there a way to do this using the header location function? If so, where could I read up more about it?

Thanks for the help,

Eric

[edited by: eelixduppy at 8:25 pm (utc) on Nov. 28, 2008]
[edit reason] exemplified [/edit]

 

TeofenGL

10+ Year Member



 
Msg#: 3796220 posted 8:36 pm on Nov 28, 2008 (gmt 0)

What I fail to understand in your question is what criteria you would like to use to determine which site a user gets sent to.

If you have your criteria, this is roughly as follows:

switch ($condition){
case a:
$loc = "http://www.site1.com/game1/";
break;
case b:
$loc = "http://www.site2.com/game1/";
break;
//etc
default:
$loc = "http://www.siteX.com/gameX/";
}
header("Location: $loc");
exit;

EricEC

5+ Year Member



 
Msg#: 3796220 posted 3:07 am on Nov 29, 2008 (gmt 0)

I understand what you are saying. I am not very good with php and what not so basically all I want to do is have the same link forward a user on to the same site every time until I change it in some code.

If this is the case, would the above code do this or is there something else that I would need?

EricEC

5+ Year Member



 
Msg#: 3796220 posted 4:26 am on Nov 29, 2008 (gmt 0)

Here is what I would like...

<?php

if($playgame)
{
$playgame = "http://www.mysite.com/playgame.php?id=123";
$url = "http://www.example.com";
header("location: $url");
}

Here is what I get stuck. I want the next part of the code to keep the user at my site and let them play the game on my site. So is there some else function I could include such as...

else
{
header("location: Keep the person at my site");

exit/break; (whichever would be best)

Obviously, as I said, I am not very good with php, so I understand most of this doesn't work. I am just looking for a direction to go in.

Thanks,

Eric

vincevincevince

WebmasterWorld Senior Member vincevincevince us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3796220 posted 8:13 am on Nov 29, 2008 (gmt 0)

Location: headers redirect the user - that is they change the user's URL just as if the user clicked a link to that other site. It does not allow you to place someone else's page within your site.

What you are looking for is some form of a proxy system - a simple one would run:

print file_get_contents($_GET['realurl']);

Where a visitor to:
http://example.com/blah.php?realurl=http://foo.bar/game

Would see the content of foo.bar/game, but the URL remaining within example.com

However - I don't recommend this - and it opens up big holes for copyright liability and being abused by black-hat SEO companies.

EricEC

5+ Year Member



 
Msg#: 3796220 posted 4:19 pm on Nov 29, 2008 (gmt 0)

I understand that location: headers redirect the user. That is essentially what I am trying to do, just forward the user on to another site if they click a certain link in my site.

Is it possible to do if/else location: headers?

Patrick Taylor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3796220 posted 4:25 pm on Nov 29, 2008 (gmt 0)

The user is at example.com/game/1. He clicks the game and is forwarded on to another site to play the game. A different user is also on and is at example.com/game/2. He clicks the game to play and is forwarded on to a different site to play his game.

Why not use normal links (hyperlinks)?

EricEC

5+ Year Member



 
Msg#: 3796220 posted 2:50 am on Dec 1, 2008 (gmt 0)

Okay... Here is what I have. Would this work at all?

<?php

if ($_SERVER['REQUEST_URL'] == 'http://www.example1.com/playgame.php?id=251') {

header('Location: [example2.com...]

}

?>

vincevincevince

WebmasterWorld Senior Member vincevincevince us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3796220 posted 8:08 am on Dec 1, 2008 (gmt 0)

EricEC, what you have written will work, apart from you need to drop the [...com...] part from the check against REQUEST_URI (and make it URI)

However - I still don't know what's wrong with giving them a direct link, as the moment they click your one they will go to the other guy's site anyway - and that includes their URL bar changing to his site.

Is this so they don't know they are going to be sent away?

EricEC

5+ Year Member



 
Msg#: 3796220 posted 5:03 pm on Dec 1, 2008 (gmt 0)

Well, the main reason I am not giving a direct link is because I don't exactly know how to do it that way as silly as it may sound.

My script was purchased so its more advanced than what I know. It connects to my database and finds the correct game to play and what not. I don't know how to define a direct link for a specific game using the script I have, thats all. So I just decided that using the header location function would be easiest for me.

EricEC

5+ Year Member



 
Msg#: 3796220 posted 5:32 pm on Dec 1, 2008 (gmt 0)

Oh, and by the way, is I do use the header location function, is there a way, such as a condition statement or something that I could include to forward the user to another site say 50% of the time that the link is clicked?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved