Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php - Randomize Web Title, using arrays and the random function
Blessed
post Apr 8 2007, 03:32 PM
Post #1


Advanced Member
*******

Group: Members
Posts: 144
Joined: 22-March 07
Member No.: 40,472



PHP - Randomize Web Title with the rand function...

Define the variables numbers
we start at number 0
CODE
<?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
CODE
<?
// 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="http://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>
Reason for edit: added code tags
Go to the top of the page
 
+Quote Post
Saint_Michael
post Apr 9 2007, 02:26 AM
Post #2


$p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3
*********************

Group: [HOSTED]
Posts: 6,304
Joined: 21-September 04
From: 9r33|\| 399$ 4|\|D 5P4/\/\
Member No.: 1,218
T17 GFX Crew



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.
Go to the top of the page
 
+Quote Post
masugidsk8r
post Apr 9 2007, 03:00 AM
Post #3


Premium Member
********

Group: Members
Posts: 168
Joined: 21-February 07
Member No.: 38,999



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.
Go to the top of the page
 
+Quote Post
Blessed
post Apr 9 2007, 08:47 AM
Post #4


Advanced Member
*******

Group: Members
Posts: 144
Joined: 22-March 07
Member No.: 40,472



thanx for the reply m8's
i will check if i can add a once a month funtion to it laugh.gif
if someone can help me with that that would be great laugh.gif

This post has been edited by Blessed: Apr 9 2007, 08:47 AM
Go to the top of the page
 
+Quote Post
hippiman
post Apr 9 2007, 03:36 PM
Post #5


Premium Member
********

Group: Members
Posts: 150
Joined: 9-April 07
From: Nebraska
Member No.: 41,301



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.
Go to the top of the page
 
+Quote Post
Blessed
post Apr 12 2007, 08:02 AM
Post #6


Advanced Member
*******

Group: Members
Posts: 144
Joined: 22-March 07
Member No.: 40,472



i will post the script soon laugh.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Delphi(1)
  2. Php Sockets(4)
  3. Random Quote Script(6)
  4. Change / Modify The Title Bar Text In IE6 Or FF(3)
  5. [php] Walking Through Multidimensional Arrays(2)
  6. Arrays In Php(1)
  7. Php Random Titles(11)
  8. User Permission Function [php](3)
  9. Php - Forms, Date And Include(0)


 



- Lo-Fi Version Time is now: 24th July 2008 - 12:06 PM