Hello World! My first program. (Ps not HW)

5 replies
Hello all. So I am trying to write a simple script that will let me put forwarding on a godaddy domain for example forward-this-domain1 dot com to redirect-to-here dot com.

The php file can sit on the redirect-to-here dot com server and in godaddy i want to forward to say redirect-to-here dot com/ redirection/ index.php? domain=forward-this-domain1 dot com. I want this whole process to be logged.

So here is my first script written mostly by me ever.

PHP Code:
<?php

//variables
$logfile 'redirections.html';
$redir_url 'http: redirect-to-here dot com';
$IP $_SERVER['REMOTE_ADDR'];
$refer $_SERVER[''];

$domain = array("forward-this-domain1 dot com" => "forward-this2 dot com");

//set logfile output
$logdetails=  date("F j, Y, g:i a") . ': ' '<a href=http: network-tools dot com/default.asp?prog=whois&host='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>' ' from domain ' $domain ' and referrer ' $refer;

//set var to open logfile
$fp fopen($logfile"a");

//main script
fwrite($fp$logdetails);
fwrite($fp"<br />");
fclose($fp);

header('Location:' $redir_url);
exit();

?>
And this is my output to "redirections dot html"

Code:
January 5, 2010, 3:09 pm: xx.xxx.xx.xxx from domain Array and referrer
January 5, 2010, 3:09 pm: xx.xxx.xx.xxx from domain Array and referrer ##Referral directory if called from a director with no index##
How do I make "Array" say the domain variable instead? The host refer does seem to work though when its called from an actual web page, but not when forwarded through a domain on godaddy.

Hope I make sense. And I hope I didnt fudge the code so bad lol. I thought it was going pretty well until it didnt do what I really wanted it to lol.

Ps. didnt mean to obscure the links so much but the forum thought I was trying to spam it. I dont know if any domain other than the network tool is active or owned.
#program #world
  • Profile picture of the author rctelles
    What the duece? I guess it did let me post the code. I apologize for the double post.
    {{ DiscussionBoard.errors[1579886].message }}
  • Profile picture of the author HomeBizNizz
    It is something wrong with the forum then you post code in the blogpost...
    {{ DiscussionBoard.errors[1592656].message }}
  • Profile picture of the author chaos69
    Originally Posted by rctelles View Post

    Hello all. So I am trying to write a simple script that will let me put forwarding on a godaddy domain for example forward-this-domain1 dot com to redirect-to-here dot com.

    How do I make "Array" say the domain variable instead? The host refer does seem to work though when its called from an actual web page, but not when forwarded through a domain on godaddy.
    The problem is the way you are echoing the domain value; arrays are somewhat more complex that a standard variable, think of them as a collection of variables. In this case, your associative array;

    The value of $domain has no value - since it is an array.
    The value of $domain[''forward-this-domain1 dot com'] is 'forward-this2 dot com'

    This is why you are getting "Array" as the output.

    You need to output is as the above;

    $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http: network-tools dot com/default.asp?prog=whois&host='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>' . ' from domain ' . $domain['forward-this-domain1 dot com'] . ' and referrer ' . $refer;

    Assuming you are only working with the one element in your array.

    If you have more elements in the array, you will need to work out what array key you need to use. In your example above, this is as easy as;

    $requested_url=$_GET['domain'];

    $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http: network-tools dot com/default.asp?prog=whois&host='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>' . ' from domain ' . $domain[$requested_url] . ' and referrer ' . $refer;


    Disclaimer: You should check the value that is stored in $_GET['domain'] is valid or you may end up with some unexpected results. Always clean the data, and check its what you are expecting. In this case, you can check if the requested domain exists in your array by using the array_key_exists function.
    Signature
    Best Ways To Make Money Online

    Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
    “Yeah,” reply the bytes. “Make us a double.”
    {{ DiscussionBoard.errors[1592792].message }}
    • Profile picture of the author saschakimmel
      If SEO is important to you you should add this header right before the "Location" header is sent to the browser:
      header("HTTP/1.0 301 Moved Permanently");

      As chaos69 has written - always check the values for the domain - otherwise it could easily be used to redirect to SPAM domains by spammers with your domain name in the URL.
      Signature

      ** Get my ViralListMachine software now for free and build your own list virally by giving away free stuff @ http://www.virallistmachinegiveaway.com **

      {{ DiscussionBoard.errors[1601006].message }}
      • Profile picture of the author rctelles
        Thanks for both your advice. Isnt SEO important to everyone?! hehe. I been really busy the last couple days but I will definitely fool around with the suggestions yall made. Thanks again!
        {{ DiscussionBoard.errors[1601041].message }}

Trending Topics