Page 2 of 2
PHP Snippets
Posted: Thu Jul 29, 2004 3:30 pm
by to@ds
Nice one. Im sure I'll get them from cnet or something.
PHP Snippets
Posted: Sat Jul 31, 2004 12:16 am
by to@ds
[url=\"http://www.easyphp.org/\"]http://www.easyphp.org/[/url] incase anyone wanted to know.
PHP Snippets
Posted: Sat Oct 30, 2004 10:01 pm
by RuffRyders
A simple way you could ban a user.
[code]<?php
$ip = getenv("REMOTE_ADDR");
if ($ip =="12.345.678.9")
{
echo "You're banned from this site :)";
exit();
}
?>[/code]
PHP Snippets
Posted: Sat Oct 30, 2004 10:14 pm
by RuffRyders
A simple way to echo text for those whom are new to php.
[code]<?php
echo "Your text here.";
?>[/code]
PHP Snippets
Posted: Sat Oct 30, 2004 11:49 pm
by RuffRyders
A Quick log in to Invision based forums for your site.
[code]<form style="display:inline" action="http://forums.killagraphix.com/index.php?act=Login&CODE=01&CookieDate=1" method="post">
<input type="text" size="10" name="UserName" onfocus="this.value=''" value="User Name">
<input type="password" size="10" name="PassWord" onfocus="this.value=''" value="ibfrules">
<input type="submit" value="Go">
</form>[/code]
Credit to Lightsup55.
If you wish to use this code on your site, for your forums be sure to replace forums.killagraphix.com with your boards url for eg. yourdomain.com/forum/
I know this isn't a php script but I thought I'd paste it here any how.
PHP Snippets
Posted: Thu Nov 04, 2004 9:58 pm
by RuffRyders
[color=\"red\"]Seeing how a lot of you use phpbb forums I thought I'd post this:[/color]
Let's take a look at the phpBB table phpBB_users; you'll see a list
of fields. The fields we need are:
-> username
-> user_posts
What we are going to do is:
-> Get username & user's post count from the database
-> Get the next username & user's post count
-> Compare them
-> If the second user's post count is bigger, get put username & post count
into a variable and compare it with the next record.
[code]<?php
$username = 'username';
$password = 'password';
$host = 'localhost';
$connection = mysql_connect ($username, $password, $host); //Create a MySQL
connection
$query = 'SELECT * from phpbb_users'; //Create the query
$result = mysql_db_query ($db, $query, $connection); //Run the query on
the database
$user1_posts = $row['0']; //Create 2 empty variables to compare
$user1_name = $row['0']; //the usernames & post counts
while ($row = mysql_fetch_array($result)) { //Fetch the results from var
$result
$user2_posts = $row['user_posts']; //Put the username & post count into
an temporary variable
$user2_name = $row['username']; //
if ($user2_posts > $user1_posts) { //Compare the post counts
$user1_posts = $row['user_posts']; //If the new one is bigger, replace
the old one with the new one
$user1_name = $row['username'];
}
}
print ('Top poster: ' . $user1_name . ' with ' . $user1_posts . '.');
?>[/code]
That's it!
For questions about this script you can email me at
rein3000@hotmail.com
or surf to
www.rynusrein.nl.tt.
Taken from: [url=\"
http://www.phpcafe.net/index.php/pg/tut ... E/02/id/15\"]Here[/url]
PHP Snippets
Posted: Sun Nov 14, 2004 2:33 am
by RuffRyders
[b]Browser Redirect:[/b]
Alright, this is a simple little script which will take you to one page if you're using Internet Explorer, and another page if you're using some other browser. Lets decide what this is going to do in English:
If the browser is MicroSoft Internet Explorer (MSIE), then go to spoono.com
If the browser isn't MSIE, then redirect to yahoo.com.
The most essential part of this is that this code has to be sent out before any output to the HTML page. Make sure it is the first line of code on your PHP page. With that said, here is the PHP:
<?
//if its MSIE then
if ($name = strstr ($HTTP_USER_AGENT, "MSIE"))
{
//go to Spoono
Header ("Location: [url=\"http://www.spoono.com/");\"]http://www.spoono.com/");[/url]
}
else
{
//else go to Yahoo
Header ("Location: [url=\"http://www.yahoo.com/");\"]http://www.yahoo.com/");[/url]
}
?>
Tutorial courtesy of [url=\"http://www.spoono.com\"]Spoono[/url].
PHP Snippets
Posted: Sun Nov 14, 2004 4:05 am
by RuffRyders
Use this as a gateway to detect a users accepted language and for example redirect him/her to the right page.
[code]<?php
function lixlpixel_get_env_var($Var)
{
if(empty($GLOBALS[$Var]))
{
$GLOBALS[$Var]=(!empty($GLOBALS['_SERVER'][$Var]))?
$GLOBALS['_SERVER'][$Var]:
(!empty($GLOBALS['HTTP_SERVER_VARS'][$Var]))?
$GLOBALS['HTTP_SERVER_VARS'][$Var]:'';
}
}
function lixlpixel_detect_lang()
{
// Detect HTTP_ACCEPT_LANGUAGE & HTTP_USER_AGENT.
lixlpixel_get_env_var('HTTP_ACCEPT_LANGUAGE');
lixlpixel_get_env_var('HTTP_USER_AGENT');
$_AL=strtolower($GLOBALS['HTTP_ACCEPT_LANGUAGE']);
$_UA=strtolower($GLOBALS['HTTP_USER_AGENT']);
// Try to detect Primary language if several languages are accepted.
foreach($GLOBALS['_LANG'] as $K)
{
if(strpos($_AL, $K)===0)
return $K;
}
// Try to detect any language if not yet detected.
foreach($GLOBALS['_LANG'] as $K)
{
if(strpos($_AL, $K)!==false)
return $K;
}
foreach($GLOBALS['_LANG'] as $K)
{
if(preg_match("/[\[\( ]{$K}[;,_\-\)]/",$_UA))
return $K;
}
// Return default language if language is not yet detected.
return $GLOBALS['_DLANG'];
}
// Define default language.
$GLOBALS['_DLANG']='en';
// Define all available languages.
// WARNING: uncomment all available languages
$GLOBALS['_LANG'] = array(
'af', // afrikaans.
'ar', // arabic.
'bg', // bulgarian.
'ca', // catalan.
'cs', // czech.
'da', // danish.
'de', // german.
'el', // greek.
'en', // english.
'es', // spanish.
'et', // estonian.
'fi', // finnish.
'fr', // french.
'gl', // galician.
'he', // hebrew.
'hi', // hindi.
'hr', // croatian.
'hu', // hungarian.
'id', // indonesian.
'it', // italian.
'ja', // japanese.
'ko', // korean.
'ka', // georgian.
'lt', // lithuanian.
'lv', // latvian.
'ms', // malay.
'nl', // dutch.
'no', // norwegian.
'pl', // polish.
'pt', // portuguese.
'ro', // romanian.
'ru', // russian.
'sk', // slovak.
'sl', // slovenian.
'sq', // albanian.
'sr', // serbian.
'sv', // swedish.
'th', // thai.
'tr', // turkish.
'uk', // ukrainian.
'zh' // chinese.
);
// Redirect to the correct location.
//header('location: http://www.your_site.com/index_'.lixlpixel_detect_lang().'.php'); // Example Implementation
echo 'The Language detected is: '.lixlpixel_detect_lang(); // For Demonstration
?>[/code]
Credit to [email=phparadise@gmail.com]lixlpixel[/email].