PHP code within a URL.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nimmØ2
Forum Newbie
Posts: 14
Joined: Thu Feb 08, 2007 3:55 am

PHP code within a URL.

Post 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.
Last edited by nimmØ2 on Thu Feb 08, 2007 6:34 am, edited 1 time in total.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

Code: Select all

header('location: http://'.$random.'.mysite.com/index.php');
Hope this helps or is what you are after.
nimmØ2
Forum Newbie
Posts: 14
Joined: Thu Feb 08, 2007 3:55 am

Post 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. :)
nimmØ2
Forum Newbie
Posts: 14
Joined: Thu Feb 08, 2007 3:55 am

Post by nimmØ2 »

Heck, it works like a charm.
Couldn't resist. Thanks again. :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

nimmØ2
Forum Newbie
Posts: 14
Joined: Thu Feb 08, 2007 3:55 am

Post 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.)
Post Reply