MyBB Community Forums

Full Version: PHP Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi, I am not shure if this is a PHP or a Java question well can some one help me code the following.....

-Upon registration each member gets 12 Credits he can use thous credits to download Anime Episodes, Movies and Manga... when member runs out of 12 Credits he has to wait tell the next day when the credit system will be refreshed back to defult 12. If member has no used his credits the system will still refresh and the member will still have 12 credits. And when member runs out of credits he can not download ^^.... Not shure is this possible but i seen it on dgemu.com .....

-and second script i think is PHP i need something like here on MyBB in Ideas where people can post comments....

Thank You...
Both of those should be PHP. The first one would need a database to hold members, their number of credits remaining and the last timestamp their credits were refreshed. You would then decrement the number of credits from the database when they downloaded something, and every time they visited, check to see if the timestamp in the database was 24 hours old, and if so, set their number of credits in the database back to 12.

The second one would also need a database to hold members, ideas and comments.

If this is for adding to MyBB, you can use the MyBB database's user information to handle the user part, and then just add new tables for anything extra you need. If this isn't for MyBB, this isn't the place to ask.
First things first, Yes it is a MyBB Forum

And can you explain that some way easyer? Kind of a PHP Noobie here ^^

If you can provide code then HORAYeee
Neither of what you have asked for are simple tasks, if you really are new to PHP, then I suggest you try something simpler first.

You can find some documentation on the MyBB plugin API below which should help with the database side of things.
[Wiki: Plugins] (Broken link, head over to docs.mybb.com instead)
[Wiki: Database_Methods] (Broken link, head over to docs.mybb.com instead)
Hmm... butch of little codes.... hmm is that the code?
<?php

$dbhost = 'localhost'
// Database Data
$dbusername = 'user'
$dbpasswd = 'password'
$database_name = 'SQL'

// Script Start
$connection = mysql_connect(" $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd") 

    or die ("Couldn't connect to server."); 


$db = mysql_select_db("$database_name", $connection) 

    or die("Couldn't select database."); 


include('check.php');


?>

Now SQL

CREATE TABLE ponits (
id int(10) NOT NULL auto_increment, 
username varchar(40),
time_string varchar(80)
credit varchar(12)
last_login varchar(20),
PRIMARY KEY(id))

Now rest....

<?php
require('db_connect.php');    // database connect script.
?>

<html>
<head>
<title>Register an Account</title>
</head>
<body>

<?php

if (isset($_POST['submit'])) { // if form has been submitted

    if (!$_POST['uname'] || !$_POST['passwd'] ||
        !$_POST['passwd_again'] || !$_POST['email']) {
        die('You did not fill in a required field.');
    }

    // check if username exists in database.

    if (!get_magic_quotes_gpc()) {
        $_POST['uname'] = addslashes($_POST['uname']);
    }

    $qry = "SELECT username FROM users WHERE username = '".$_POST['uname']."'";
                $sqlmembers = mysql_query($qry);
                $name_check = mysql_fetch_array ($sqlmembers); 
                $name_checkk = mysql_num_rows ($sqlmembers);
    
    if ($name_checkk != 0) {
        die('Sorry, the username: <strong>'.$_POST['uname'].'</strong>'
          . ' is already taken, please pick another one.');
    }

    // check passwords match

    if ($_POST['passwd'] != $_POST['passwd_again']) {
        die('Passwords did not match.');
    }

    // check e-mail format

    if (!preg_match("/.*@.*..*/", $_POST['email']) ||
         preg_match("/(<|>)/", $_POST['email'])) {
        die('Invalid e-mail address.');
    }

    // no HTML tags in username, website, location, password

    $_POST['uname'] = strip_tags($_POST['uname']);
    $_POST['passwd'] = strip_tags($_POST['passwd']);
    $_POST['website'] = strip_tags($_POST['website']);
    $_POST['location'] = strip_tags($_POST['location']);

    // check show_email data

    if ($_POST['show_email'] != 0 & $_POST['show_email'] != 1) {
        die('Nope');
    }

    if ($_POST['website'] != '' & !preg_match("/^(http|ftp):///", $_POST['website'])) {
        $_POST['website'] = 'http://'.$_POST['website'];
    }

    // now we can add them to the database.
    // encrypt password

    $_POST['passwd'] = md5($_POST['passwd']);

    if (!get_magic_quotes_gpc()) {
        $_POST['passwd'] = addslashes($_POST['passwd']);
        $_POST['email'] = addslashes($_POST['email']);
        $_POST['website'] = addslashes($_POST['website']);
        $_POST['location'] = addslashes($_POST['location']);
    }

    $regdate = date('m d, Y');

    $insert = "INSERT INTO users (
            username,
            time_string,
            credits, 
            password, 
            regdate, 
            email, 
            website, 
            location, 
            show_email, 
            last_login) 
            VALUES (
            '".$_POST['uname']."', 
            '".$_POST['passwd']."', 
            '$regdate', 
            '".$_POST['email']."', 
            '".$_POST['website']."', 
            '".$_POST['location']."', 
            '".$_POST['show_email']."', 
            'Never')";

    $sqlmembers = mysql_query($insert);
?>

<h1>Registered</h1>

<p>Thank you, your information has been added to the database, 
you may now <a href="login.php" title="Login">log in</a>.</p>

<?php

} else {    // if form hasn't been submitted

?>
<h1>Register</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>Username*:</td><td>
<input type="text" name="uname" maxlength="40">
</td></tr>
<tr><td>Password*:</td><td>
<input type="password" name="passwd" maxlength="50">
</td></tr>
<tr><td>Confirm Password*:</td><td>
<input type="password" name="passwd_again" maxlength="50">
</td></tr>
<tr><td>E-Mail*:</td><td>
<input type="text" name="email" maxlength="100">
</td></tr>
<tr><td>Website:</td><td>
<input type="text" name="website" maxlength="150">
</td></tr>
<tr><td>Location</td><td>
<input type="text" name="location" maxlength="150">
</td></tr>
<tr><td>Show E-Mail?</td><td>
<select name="show_email">
<option value="1" selected="selected">Yes</option>
<option value="0">No</option></select>
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Sign Up">
</td></tr>
</table>
</form>

<?php

}

?>
</body>
</html>

And this should be the last line of code i think....

<?php

session_start();

if (!isset($_SESSION['username']) || !isset($_SESSION['password'])) {
    $logged_in = 0;
    return;
} else {

    if(!get_magic_quotes_gpc()) {
        $_SESSION['username'] = addslashes($_SESSION['username']);
    }

    $qry = "SELECT password FROM users WHERE username = '".$_SESSION['username']."'";
    $sqlmembers = mysql_query($qry);
    $pass =  mysql_num_rows($sqlmembers);

    if($pass != 1) {
        $logged_in = 0;
        unset($_SESSION['username']);
        unset($_SESSION['password']);
        // kill incorrect session variables.
    }

    $db_pass =  mysql_fetch_array ($sqlmembers);


    //$db_pass['password'], stripslashes() just incase:

    $db_pass['password'] = stripslashes($db_pass['password']);
    $_SESSION['password'] = stripslashes($_SESSION['password']);

    if($_SESSION['password'] == $db_pass['password']) { 
        // valid password for username
        $logged_in = 1; // they have correct info
                    // in session variables.
    } else {
        $logged_in = 0;
        unset($_SESSION['username']);
        unset($_SESSION['password']);
        // kill incorrect session variables.
    }
}
if ($time ! = 24) {
  echo "Credit Refreshed"
}
else ($time ! =<24) {
  echo "We are sorry the system has not refreshed the credits yet!"
}
unset($db_pass['password']);

$_SESSION['username'] = stripslashes($_SESSION['username']);

?>
That looks like some generic user code, if you were going to do this with MyBB, it would manage the database connection itself. Be it via a plugin, or a page which just includes the MyBB core into it so it can use MyBB functions.

A list of plugin hooks can be found here:
[Wiki: MyBB_Plugin_Hooks] (Broken link, head over to docs.mybb.com instead)

You could include the MyBB core into an external page using something like this:
define("IN_MYBB", 1);
require('./global.php');
I am sorry MrD. but you are looking at 100% NOOB here which is failing to get his Anime Website up T_T all I need is a code like MegaUpload or RapidShare use which allowe's an IP to download say 6 file daily.. and I need some way to make shure when member tryes to bypass this by doing something like....

http://mysiteurl.com/anime/bleach/ep45.zip <- so if they do that they will be send to

http://mysiteurl.com/anime/error <-error page which will show the following message...

<-- MESSAGE -->

!---- IMPORTANT ----!
This IP has reached its download limit for a day!
Please come back in 24 hours <?php echo"['username']" ?>

Thank You the AnimeFrost Team!
!---- IMPORTANT ----!

<-- MESSAGE -->

and they can not download until they come back tomorrow.... ^^
i think i can try to include
define("IN_MYBB", 1);
require('./global.php'); 

Which can check is the member register or not and if member is not register they will be forced before they can access the anime download sections...
Where are these downloads stored, are they stored in posts?
no they are stored in

/www/anime/ <- on the server it self in ANIME folder

-root folder I guess..
In essence then, anyone who knew the location of the episode would be able to just go straight there and download it, regardless of what system you had set-up in PHP. You could use a download script which gave the files a random filename to stop people being able to work out the filename, but then that would be something else that would need integrating into, or growing from, MyBB.
Pages: 1 2