Jump to content
xisto Community
Sign in to follow this  
Blessed

Php - Randomize Web Title using arrays and the random function

Recommended Posts

PHP - Randomize Web Title with the rand function... Define the variables numbers we start at number 0


<?php $title[0] = "Web title 0"; // Title 0 $title[1] = "Web title 1"; // Title 1 $title[2] = "Web title 2"; // Title 2 $title[3] = "Web title 3"; // Title 3 $title[4] = "Web title 4"; // Title 4 ?>

now we use the rand() function to get a randomize the web title. rand(0, 4) means we start at 0 and end at 4 i can get 0,1,2,3,4 one of those. It depends how many arrays you have


<? // get a random number $randomize = rand(0, 4); // Change four to how many arrays you have echo ($title[$randomize]); ?> see it in action. ++++++++++++++++++++ <?php $title[0] = "Web title 0"; // Title 0 $title[1] = "Web title 1"; // Title 1 $title[2] = "Web title 2"; // Title 2 $title[3] = "Web title 3"; // Title 3 $title[4] = "Web title 4"; // Title 4 // get a random number $randomize = rand(0, 4); // Change four to how many arrays you have ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; <html xmlns="https://www.w3.org/1999/xhtml/"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo ($title[$randomize]); ?></title> </head> <body> Just a simple PHP tut </body> </html>


Share this post


Link to post
Share on other sites

Interesting php code there, from the jist of it this php script it randomly changes the title of your website, I could see some good function with this, however I could the inconvience of this script as well, and that you could have a hard time getting your website index, just on the fact that every user that goes to the site will have a different title every time, thus google could think your cheating in some way. Maybe you could add a a peice of time code into this script say to change it once of month to spread the time delay out.

Share this post


Link to post
Share on other sites

In my opinion, I don't find this method a very good SEO practice. Google wouldn't like this and so would other search engines. However, it would be good to teach Random numbers as an exercise or practice for PHP, but even that is misleading in some way. It's okay for maybe a sub-page of a site but that's about it.anyway, thanks for posting this tutorial. This is the first time I learned how to use the rand() function. Thank you again.

Share this post


Link to post
Share on other sites

If you want to make it change every month from when you start it, you could use mysql or a text file, and store the last date that it was changed, and if time() > (what's stored) + (30*24*60*60), then it would show a different title. I think there's also a way to use "date('Y-m-d', strtotime('+1 month'))" (I found this in another tutorial and it worked), but I'm not sure if the ">" sign would work for dates. There might be some other way to do it that's better, but I haven't really looked into it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.