Jump to content

PHP redirect


jmmille

Recommended Posts

Ok guys,

 

I'm on a college campus so my internal IP is always the same.  I run a web radio streaming music and I don't want to have to remember the IP so I'm trying to set me student webspace to redirect to my radio.

 

On campus, everyone has 130.x.x.x ip addresses so I thought I would set it to redirect people on campus and tell the off-campus people to use VPN to get an on campus IP address.

 

Here's what I have so far:

<?php 
    $ip = @$REMOTE_ADDR;
    $ips = explode(".", $ip);
    if($ips[0] == 130) {
    header('Location:http://IPaddress:8888');
    } else {
    echo "You are not located on campus.  If you wish to listen to streaming music, please use VPN then try again."; }
    exit;
?>

 

When I try this script, it just stalls saying "waiting on response from server."

 

Any help will be appreciated.

Link to comment
Share on other sites

<?php 
    $ip = $_SERVER['REMOTE_ADDR'];

 

I hope register_globals is off. At any rate try the above for the ip address, it could be register_globals is off but either way you should access the ip  using the above.

 

As for why it is saying "Waiting on response" no clue. If you are trying to hit your own server, that may be the issue. You might also try a meta redirect or javascript redirect instead. See if that changes anything.

Link to comment
Share on other sites

Thanks for the tip.

 

I changed the $ip variable with no luck.  Then I looked into it a little more and campus is currently having server problems.  I'm thinking the server I'm hosted on is one of the problem ones.  I'll have to try it again in a bit.

 

Thanks guys

Link to comment
Share on other sites

<?php 
    $ip = $_SERVER['REMOTE_ADDR'];
    $ips = explode(".", $ip);
    if($ips[0] == 130) {
    header('Location: http://127.0.0.1:8888'); // Change 127.0.0.1 to the relevant one
    } else {
    echo "You are not located on campus.  If you wish to listen to streaming music, please use VPN then try again."; }
    exit;
?>

 

That works fine for me. You could try purchasing a cheap .US/com/net domain, and putting the script on there with the hosting you get. (No more than $10)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.