Jul 20, 2008

Php - Randomize Web Title - using arrays and the random function

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Php - Randomize Web Title - using arrays and the random function

Blessed
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>

 

 

 


Reply

Saint_Michael
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.

Reply

masugidsk8r
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.

Reply

Blessed
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

Reply

hippiman
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.

Reply

Blessed
i will post the script soon laugh.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. random arrays in php - 7.78 hr back. (1)
Similar Topics

Keywords : php, randomize, web, title, arrays, random, function

  1. Php - Forms, Date And Include
    Working with POST and GET and also the Date() function (0)
  2. User Permission Function [php]
    Determining User Permissions (3)
    There have been several recent request for methods to restrict access to various pages on a web-site
    based on User Permissions in sites that have a Login System in place. Here is some code showing one
    method to restrict access by providing a sub-set of your site's links based on the User's
    permissions. In this demonstration, I have defined a string for each 'level of user'
    determining which set(s) of links they can view on your site. Normal MySql procedure would be to
    read the User's permission level from a record in the database. For the purpose of ....
  3. Php Random Titles
    Learn to create neat-o random titles! (11)
    PHP Random Titles Description Ever wondered how some websites (ex:spoono.com) have those cool-o
    random titles appearing in the title bar? Now you get to learn how to do it using PHP. We will be
    using our knowledge of Variables and Echos in this tutorial. Try It Out Creating the code itself
    is fairly easy. To start, lets create some of our different titles. Code CODE <?php
    $title[1] = "This will be more fun that that time - never mind...";
    $title[2] = "Another random title... neat eh?"; $title[3] = ....
  4. Arrays In Php
    My Fourth PHP Tutorial (1)
    This is the fourth part of my PHP tutorial. You can view the last three here: Third Tutorial
    (Form Data and If statements) Second Tutorial (Variables) First Tutorial (What is PHP?) Intro
    To PHP Tutorial 4 - Arrays Released 4/13/07 By Chris Feilbach aka GhostRider Contact Info: E-mail:
    assembler7@gmail.com AIM: emptybinder78 Yahoo: drunkonmarshmellows Website:
    http://www.ghostrider.trap17.com Hello once again! During this tutorial I'm going to
    teach you about arrays. This tutorial does not have a project with it. Remember back to my second
    tutoria....
  5. [php] Walking Through Multidimensional Arrays
    Walk through multidimensional array with foreach and list (2)
    If you like PHP arrays like i do you probably wondered how to walk through multidimensional arrays.
    You can construct them maybe from your database or flat file, and output them with simple two
    functions foreach, and list.. Let's say we have something like this CODE $information
    = array (                         'id0001' => array ('ivan',
    'ivanovich', 'm', '24'),                         'id0002' =>
    array ('marko', 'markovich', 'm', '21'),             ....
  6. Change / Modify The Title Bar Text In IE6 Or FF
    custom text in titlebar in ie or firefox (3)
    Changing The Text In The Bar (IE and Firefox Only) This will allow you to change the text in
    the title bar of either msie6 (may work for ie7 beta or earlier versions) and mozilla firefox 1.0.
    By default this is set to Microsoft Internet Explorer provided by ##### or Mozilla Firefox .
    Here's how to change that..... For Internet Explorer (6) Warning! Changing the title
    for internet explorer requires editing the registry. Making changes in the registry in keys or
    values that are not listed here could cause your computer to crash or slow. Follow the fo....
  7. Random Quote Script
    (6)
    Here's a little random quote script that you can use to randomly choose from an array of quotes
    you provide. It's very easy to use on any page as it's an external script, you just call it
    from your page. I wouldn't use it for any more than about 50 quotes though, it would probably
    slow your site down too much. Here's the code: var ar = new Array(44) ar = "Do not meddle in
    the affairs of wizards, for they are subtle and quick to anger." ar = "Faithless is he that says
    farewell when the road darkens." ar = "I cordially dislike allegory in all its ....
  8. Php Sockets
    Introduction to an underused function of PHP (4)
    This tutorial is based on a question written in the PHP programming board Inspiration
    Introduction Sockets, an underused function in PHP, is a function that enables you to open
    connection to other peoples computers and vice versa. By sending commands to the operating server,
    it will first see if there's response, then, it sends or receives data that the operating server
    has available. Creation of a socket Of course, a first step in using sockets, is creating it,
    this is done by: CODE resource socket_create ( int domain, int type, int protocol) ....
  9. Using The Date() Function [php]
    (2)
    The date() function can be used in a good way, in some cases, and the most common place you would
    probably see this in use would be on forums. Let's get down to business... If you would like to
    display the date, you would have to put the echo tag before the date() function as so... CODE
    echo date("g:i:s"); Which would display as the common hours, minutes,
    seconds format (ex: 3:32:45). But you can also add wheather it is AM or PM, display the day (Sunday
    thru Monday), the year, pretty much anything that has to do with date. Here is a....
  10. [tutorial] Delphi
    Multi-Parsing Function (0)
    I've spent a while trying to create parsing function with Delphi. This language is very useful.
    This tutorial explains how to parse multiple instances of an item in one string. Here is the
    function (which I am actually very proud of): Code: function TForm1.MultiParse(MainString,
    BeginString, EndString: string): TStrings; var PosBeginString, PosEndString, i, LastPos: integer;
    tmpCopy: string; tmpStrings: TStrings; begin tmpStrings := TStringList.Create; LastPos := 0;
    for i := 1 to LastDelimiter(EndString, MainString) do begin PosBeginString := Pos....
  11. Delphi
    Simple Text Parsing Function (1)
    Because parsing is such an integral part of string manipulation, I took the time to make a quick and
    simple parse function. For you VBers, Delphi is a derivative of Pascal...it's powerful, simple,
    and (best of all) doesn't need external component (eg: ocx files). Hence the code: Code:
    function TForm1.SimpleParse(MainString, BeginString, EndString: string): string; var PosBeginString:
    integer; PosEndString: integer; begin PosBeginString := Pos(BeginString, MainString) +
    Length(BeginString); PosEndString := Pos(EndString, MainString); Result := Copy(MainString, ....

    1. Looking for php, randomize, web, title, arrays, random, function

Searching Video's for php, randomize, web, title, arrays, random, function
advertisement



Php - Randomize Web Title - using arrays and the random function



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE