Page 1 of 1

PHP code within a URL.

Posted: Thu Feb 08, 2007 6:28 am
by nimmØ2
Well I'm new to the forum, obviously.
I know a little less than the basics in many computer fields, such as programming, web design, 3d modeling, etc.
However, PHP is something I'd like to learn and actually get into.

Currently I'm trying to write a simple script that will redirect the user to a semi-random URL.
Example:
http://www.mysite.com
would redirect the user to
http://www.1241564.mysite.com/index.php
with '1241564' being the random part of the URL.

I've picked up the code for redirecting the user to a new page from within PHP,

Code: Select all

<?php
header( 'Location: http://www.mysite.com/index.php' ) ;
?>
and the code for generating random numbers,

Code: Select all

srand(time());
$random = (rand()%9999999);
I'm just not quite sure how to put them together.
Thanks for your time.

Posted: Thu Feb 08, 2007 6:33 am
by mickd

Code: Select all

header('location: http://'.$random.'.mysite.com/index.php');
Hope this helps or is what you are after.

Posted: Thu Feb 08, 2007 6:51 am
by nimmØ2
mmm, yummy.
Looks perfect, I just didn't know how to do it.

If you don't hear from me in this thread, it works, thanks so much, and thanks again.
If I have a problem, you'll hear it, and more thanks soon enough. :)

Posted: Thu Feb 08, 2007 7:00 am
by nimmØ2
Heck, it works like a charm.
Couldn't resist. Thanks again. :D

Posted: Thu Feb 08, 2007 7:03 am
by Chris Corbyn

Posted: Thu Feb 08, 2007 7:10 am
by nimmØ2
Ah, very handy. I also have two books on PHP.
I've been planning to get into if for about 8-ish months now.
Made a transition between two countries, and here I am now.

Gots the Yellow/Black Apress reference and the Sam's Teach-Yourself series book.
I also have resources bookmarked, such as w3schools.com. Now I get to add the manual.

Thanks again. (I ought to make that my signature, as it'll be a long while before I put anything besides that after the end of each post.)