Random Quotes in Signature -- Changing text

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

Random Quotes in Signature -- Changing text

Postby zver » 24 Jul 2007, 23:56

Hi :wave:

I don't know if this is in the right topic. But I have seen Highway of Life's :hello: posts, and in his signature there is a different text at every post. You will se if Highway of Life will post twice here.

I think that effect is cool, and I would like to reproduce it. But I need help. SO I decided to post here and see the results.
zver
Crewman
Crewman
 
Posts: 7
Joined: 13 Jul 2007, 01:39
Gender: Male


Re: Changing text

Postby Highway of Life » 25 Jul 2007, 06:02

Its a random changing signature.

Here is how I do it.
I create a new PHP file, and I place a bunch of quotes in it, each quote is on a newline.
I then split it line-by-line, and randomly pick one of the lines.
I send the content type to be javascript, and print the result of the random quote.
Code: Select all
<?php
$quotes 
'Lots of
quotes'
;
$split_array explode("\n"$quotes);
$rand_keys array_rand($split_array10);
header("Content-type: application/x-javascript");
echo 
"<!--\n";
//echo 'document.write("' . $split_array[$rand_keys] . '");' . "\n";
echo 'var Quote = new Array()' "\n";
foreach (
$rand_keys as $i => $value)
{
    echo 
'Quote[' $i '] = \'' $split_array[$rand_keys[$i]] . '\';' "\n";
}
echo 
'var Q = Quote.length;
var whichQuote = Math.round(Math.random() * (Q - 1));
function showQuote()
{
    document.write(Quote[whichQuote]);
}
showQuote();' 
"\n";
echo 
'-->';
?>


I save the file as a PHP file with the name: 7_signature.php, and place it anywhere in my webroot directory.
Then I created a new BBCode:
BBCode:
Code: Select all
[signature]{NUMBER}[/signature]

HTML:
Code: Select all
<script type="text/javascript" src="./path/to/scripts/{NUMBER}_signature.php"></script>


And then in my signature, I use:
Code: Select all
[signature]7[/signature]

Thats it!!
And I get:
Now everytime you reload this page, you will get a new quote.
Last edited by Highway of Life on 22 Feb 2009, 11:33, edited 1 time in total.
Reason: Updated code.
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: Changing text

Postby Synaptic Anarchy » 25 Jul 2007, 06:33

Heh.

I wonder how hard that'd be to make available to any member of a site.
It's winter.
User avatar
Synaptic Anarchy    
Lieutenant Commander
Lieutenant Commander
 
Posts: 351
Joined: 02 Jul 2006, 02:39
Favorite Team: Starfleet Design :P
Gender: Male

Re: Changing text

Postby Synaptic Anarchy » 25 Jul 2007, 06:39

BBCode:
Code: Select all
[signature]{NUMBER}[/signature]

HTML:
Code: Select all
<script type="text/javascript" src="./path/to/scripts/{U}/{NUMBER}_signature.php"></script>


and give each user their own directory and a UCP module that allows them to enter lines in a textfield that writes to the file on submission...
It's winter.
User avatar
Synaptic Anarchy    
Lieutenant Commander
Lieutenant Commander
 
Posts: 351
Joined: 02 Jul 2006, 02:39
Favorite Team: Starfleet Design :P
Gender: Male

Re: Changing text

Postby zver » 26 Jul 2007, 04:06

Isn't working :-(

I did as you said, but instead of text I got blank textarea. Nothing was there.
zver
Crewman
Crewman
 
Posts: 7
Joined: 13 Jul 2007, 01:39
Gender: Male

Re: Changing text

Postby A_Jelly_Doughnut » 26 Jul 2007, 09:58

[quote]$quotes = "quotes must
be enclosed in double quotes.
If they are not,
explode(\"\n\", \$quotes) will
fail."[/code]
A_Jelly_Doughnut
phpBB Team Member
phpBB Team Member
 
Posts: 543
Joined: 10 Feb 2007, 14:58
Location: 1- 800 - In - The - USA
Gender: Male

Re: Changing text

Postby zver » 26 Jul 2007, 23:50

Hi,

That's what I have:
forum root/1_signature.php
Spoiler:
$quotes =
"try"
"test";
$split_array = explode("\n", $quotes);
$rand_keys = array_rand($split_array, 1);

header("content-type: application/x-javascript");
echo "<!--\n
document.write('{$split_array[$rand_keys]}');\n
//-->";


BBcode
Code: Select all
[signature]{NUMBER}[/signature]

Code: Select all
<script type="text/javascript" src="./{NUMBER}_signature.php"></script>
zver
Crewman
Crewman
 
Posts: 7
Joined: 13 Jul 2007, 01:39
Gender: Male

Re: Changing text

Postby A_Jelly_Doughnut » 27 Jul 2007, 13:28

Code: Select all
$message =
"try
test";


You should have gotten a PHP parse error with the previous script...
A_Jelly_Doughnut
phpBB Team Member
phpBB Team Member
 
Posts: 543
Joined: 10 Feb 2007, 14:58
Location: 1- 800 - In - The - USA
Gender: Male

Re: Changing text

Postby kingmob » 28 Jul 2007, 00:59

In 7_signature.php place a <?php in the begin of the file and ?> in the end :)

@Highway
It's possible to add smilies in the signature? Or tags like [im g], [url ]? :P

EDIT: find it. they work with
Code: Select all
<img src=""> & <a href="link">Name</a>
tags :)

Edit 2: For quote in two lines place a <br>
Sorry for my bad english
User avatar
kingmob    
Translator
Translator
 
Posts: 144
Joined: 05 May 2007, 00:14
Location: Greece
Gender: Male

Re: Changing text

Postby King Cobra » 04 Jan 2008, 20:06

Highway of Life wrote:Its a random changing signature.

Here is how I do it.
I create a new PHP file, and I place a bunch of quotes in it, each quote is on a newline.
I then split it line-by-line, and randomly pick one of the lines.
I send the content type to be javascript, and print the result of the random quote.
Code: Select all
$quotes 'lots of quotes
on multiple lines'
;
$split_array explode("\n"$quotes);
$rand_keys array_rand($split_array1);

header("content-type: application/x-javascript");
echo 
"<!--\n
document.write('{$split_array[$rand_keys]}');\n
//-->"
;    


I save the file as a PHP file with the name: 7_signature.php, and place it anywhere in my webroot directory.
Then I created a new BBCode:
BBCode:
Code: Select all
[signature]{NUMBER}[/signature]

HTML:
Code: Select all
<script type="text/javascript" src="./path/to/scripts/{NUMBER}_signature.php"></script>


And then in my signature, I use:
Code: Select all
[signature]7[/signature]

Thats it!!
And I get:
Now everytime you reload this page, you will get a new quote.

I would love to use this on my forum but the problem I have is that my web host told me this about your script, when I tried it & got an error message
Forbidden! You don't have permission to access /adm/index.php on this server.
The problem here is that by removing the offending rule, any user could use that BBCode to inject malicious code.
Is there a work around or another way to do this so that I can have random quotes in my signature?
Image
User avatar
King Cobra    
Crewman
Crewman
 
Posts: 7
Joined: 30 Dec 2007, 20:19
Gender: Male

Next

Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: No registered users and 16 guests