Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. Tested and works:

     

    <?php
    $dirty = array(
    'rude word',
    'another rude phrase',
    'etc'
    );
    
    $text = "This is a RUDE word, while this is another ruDe pHraSe, etc";
    
    foreach($dirty AS $bad_word){
    $text = preg_replace("/$bad_word/i","****", $text);
    }
    
    echo $text;
    ?>
    

     

    Will output:

     

    This is a ****, while this is ****, ****

  2. You're crazy for actually echoing echo individual option well, individually.

     

    # days
    for($i=1;$i<=31;$i++){
    echo "<option value=\"$i\">$i</option>\n";
    }
    
    # months {
    for($j=1;$j<=12;$j++){
    echo "<option value=\"$j\">$j</option>\n";
    }
    
    # years {
    for($k=2007;$k>=1900;$k--){
    echo "<option value=\"$k\">$k</option>\n";
    }
    

     

    If anything, you have bad HTML.

  3. Could do something like:

     

    $sql = "SELECT * FROM `users_groups` WHERE `user_id`='1234'";
    $res = mysql_query($sql) or die(mysql_error());
    $num = mysql_num_rows($res);
    
    $x=1;
    while($row = mysql_fetch_assoc($res)){
       if($x == $num){
       $c = "";
       }else {
       $c = ",";
       }
    $group .= "'" . $row['group_id'] . "'" . $c;
    }
    
    $sql2 = "SELECT * FROM `news` WHERE `group` IN($group)";
    $res2 = mysql_query($sql2) or die(mysql_error());
    

  4. $file = file_get_contents("thatfile.txt");
    
    $f2 = explode("\n", $file);
    
    foreach($f2 AS $ex){
    $ex2 = explode("  ", $ex);
       foreach($ex2 AS $ex3){
       $ex4 = explode(" ", $ex3[0]);
          foreach($ex4 AS $ex5){
          echo $ex5[1] . " " . $ex4[2] . ",";
          }
       }
    }
    

     

    try that.

  5. I cleared all my cookies.

     

    CODE:

     

    global.php [included on every page]

     

    <?php
    session_set_cookie_params(10800,'/','.mysite.com', false);
    session_start();
    #session_destroy();
    
    
    //---------------MAIN DATABASE---------------//
    $db	= array();
    $db['user'] = "us_***";
    $db['pass'] = "*******";
    $db['host'] = "localhost";
    $db['base'] = "us_***";
    $connect = 1;
    
    if($connect > 0){
    $c = mysql_connect($db['host'], $db['user'], $db['pass']) or die("Error connecting to mySQL Database: " . mysql_error());
    $d = mysql_select_db($db['base'], $c);
    }
    //-------------------------------------------//
    
    
    
    //--------------INCLUDES---------------------//
    
    #-------FUNCTIONS
    if(file_exists( "/home2/us/public_html/includes/functions.php" )){
    	include "/home2/us/public_html/includes/functions.php";
    }
    
    #-------LANGUAGES
    if(file_exists( "/home2/us/public_html/includes/languages.php" )){
    	include "/home2/us/public_html/includes/languages.php";
    }
    
    
    //------------------------------------------//
    # CHECK LANGUAGE
    #checkLang($_COOKIE['ln']);
    //-----------------------------------------//
    
    ?>
    

     

    login.mysite.com/index.php

    <?php
    include "/home2/us/public_html/global.php";
    $page = $lang[$ln]['login_title'];
    
    layout('header');
    
    if(!$_SESSION['uid']){
    
    if(!$_POST['submit']){
    echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
    echo "<form method=\"post\" action=\"http://login.mysite.com\">\n";
    echo "<tr><td>{$lang[$ln]['login_username']}</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
    echo "<tr><td>{$lang[$ln]['login_password']}</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
    echo "<input type=\"hidden\" name=\"submit\" value=\"1\">\n";
    echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"image\" src=\"{$src['input_submit']}\"></td></tr>\n";
    echo "</form></table>\n";
    }else {
    $username = protect($_POST['username']);
    $password = protect($_POST['password']);
    $errors = array();
    
    	if(!$username){ $errors[] = "You did not supply a username"; }
    	if(!$password){ $errors[] = "You did not supply a password"; }
    
    	if($username && $password){
    
    		$sql = "SELECT * FROM `users` WHERE `username`='$username'";
    		$res = mysql_query($sql) or die(mysql_error());
    
    		if(mysql_num_rows($res) == 0){ $errors[] = "Invalid username"; }else {
    			$pass = md5(sha1($password));
    			$sql2 = "SELECT * FROM `users` WHERE `username`='$username' AND `password`='$pass'";
    			$res2 = mysql_query($sql2) or die(mysql_error());
    				if(mysql_num_rows($res2) == 0){ $errors[] ="Invalid username and password combination"; }
    		}
    	}
    
    	if(count($errors) > 0){
    		foreach($errors AS $error){
    		echo $error . "<br>\n";
    		}
    	}else {
    	$pass2 = md5(sha1($password));
    	$sql3 = "SELECT * FROM `users` WHERE `username`='$username' AND `password`='$pass2'";
    	$res3 = mysql_query($sql3) or die(mysql_error());
    	$row = mysql_fetch_assoc($res3);
    	$_SESSION['uid'] = $row['id'];
    	echo "You have successfully logged in!";
    	}
    }
    }else {
    echo "You are already logged in!";
    }
    
    layout('footer');
    ?>
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.