PHP question

C

Chris Hope

Viper said:
On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
forward people that goto http://www.MYDOMAIN.com to that page. Now is
there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
Where $rand would pick 1 2 or 3 then send the user to that index page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5, 15)."
 
V

Viper

Chris said:
Viper said:
On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
forward people that goto http://www.MYDOMAIN.com to that page. Now is
there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
Where $rand would pick 1 2 or 3 then send the user to that index
page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5, 15)."

Thanks that helped a bit. :)
This works:

<?
$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
header("location: $newpage")

;?>
 
C

Chris Hope

Viper said:
Chris said:
Viper said:
On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
forward people that goto http://www.MYDOMAIN.com to that page. Now
is there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
Where $rand would pick 1 2 or 3 then send the user to that index
page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5, 15)."

Thanks that helped a bit. :)
This works:

<?
$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
header("location: $newpage")

;?>

You could also do something like this, although there's a little more
overhead involved as it has to initiate the array and use memory:

$pages = array(
"somepage.php",
"anotherpage.php",
"someotherpage.php"
...
);

$rand = rand(0, sizeof($pages)-1);

$newpage = "http://www.MYDOMAIN.com/pages/" . $pages[$rand];
header("location: $newpage");
exit;
 
C

Charles Sweeney

Viper said:
Chris said:
Viper said:
On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
forward people that goto http://www.MYDOMAIN.com to that page. Now is
there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
Where $rand would pick 1 2 or 3 then send the user to that index
page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5, 15)."

Thanks that helped a bit. :)
This works:

<?
$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
header("location: $newpage")

;?>

Well done that man! Looks neat.
 
V

Viper

Charles said:
Viper said:
Chris said:
Viper wrote:

On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?>
to forward people that goto http://www.MYDOMAIN.com to that page.
Now is there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
Where $rand would pick 1 2 or 3 then send the user to that index
page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5, 15)."

Thanks that helped a bit. :)
This works:

<?
$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
header("location: $newpage")

;?>

Well done that man! Looks neat.

Thanks but now I have to wonder how search engines will handle it. See what
I am planning to do is take all the domains I own that have no pages on them
and make up "portal" pages using PPC Search engines. I want it to show a
different portal page that has a different set of PPC Search engines links
on it each time they visit. But will Google, etc even list these pages?
 
C

Charles Sweeney

Viper said:
Charles said:
Viper said:
Chris Hope wrote:
Viper wrote:

On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?>
to forward people that goto http://www.MYDOMAIN.com to that page.
Now is there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location:
http://www.MYDOMAIN.com/pages/index$rand.php");?> Where $rand
would pick 1 2 or 3 then send the user to that index page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5,
15)."

Thanks that helped a bit. :)
This works:

<?
$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
header("location: $newpage")

;?>

Well done that man! Looks neat.

Thanks but now I have to wonder how search engines will handle it. See
what I am planning to do is take all the domains I own that have no
pages on them and make up "portal" pages using PPC Search engines. I
want it to show a different portal page that has a different set of
PPC Search engines links on it each time they visit. But will Google,
etc even list these pages?

As I understand it, when using a redirection, Google will index the page
it gets sent to, but drop the sending page.
 
K

Karl Core

Charles Sweeney said:
As I understand it, when using a redirection, Google will index the page
it gets sent to, but drop the sending page.


AFAIK that's only if Google knows it is a redirection - i.e. if you're
sending the proper headers while redirecting.
Would googlebot know if Viper's site is redirecting it?
 
J

Jeffrey Silverman

AFAIK that's only if Google knows it is a redirection - i.e. if you're
sending the proper headers while redirecting.
Would googlebot know if Viper's site is redirecting it?

Probably. PHP is pretty decent about complying with header standards.
 
J

Justin Koivisto

Viper said:
Charles said:
Viper wrote:

Chris Hope wrote:

Viper wrote:


On one of my sites I use
<? header("location: http://www.MYDOMAIN.com/pages/index.php");?>
to forward people that goto http://www.MYDOMAIN.com to that page.
Now is there a way to make it randomly pick a file to send to?

Like
<?
$num = $rand(1,3)
header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
Where $rand would pick 1 2 or 3 then send the user to that index
page?

Yes.

http://www.php.net/rand

"int rand ( [int min, int max])

If called without the optional min, max arguments rand() returns a
pseudo-random integer between 0 and RAND_MAX. If you want a random
number between 5 and 15 (inclusive), for example, use rand (5, 15)."

Thanks that helped a bit. :)
This works:

<?
$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
header("location: $newpage")

;?>

Well done that man! Looks neat.

Thanks but now I have to wonder how search engines will handle it. See what
I am planning to do is take all the domains I own that have no pages on them
and make up "portal" pages using PPC Search engines. I want it to show a
different portal page that has a different set of PPC Search engines links
on it each time they visit. But will Google, etc even list these pages?

Depending on how your files are set up, instead of doing a redirect with
headers, you could use an include or an fpassthru call. That way, the
content is displayed without a redirect...
 
P

Per Jessen

Karl said:
AFAIK that's only if Google knows it is a redirection - i.e. if you're
sending the proper headers while redirecting.
Would googlebot know if Viper's site is redirecting it?

Yes, the PHP header() function sends a proper 30x redirect header as specified
by the caller.
 
C

Charles Sweeney

Karl said:
AFAIK that's only if Google knows it is a redirection - i.e. if you're
sending the proper headers while redirecting.
Would googlebot know if Viper's site is redirecting it?

Good point, and good day to you sir.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top