Jump to content

Lamez

Members
  • Posts

    1,686
  • Joined

  • Last visited

    Never

Posts posted by Lamez

  1. See I did that, and it did not turn out the way I wanted, but maybe it is my code structure.

     

    What I am doing is making a login script to force users to login to use my internet via HTTP requests. I think I am going to rewrite it for the third time :)

     

    here is what I have so far:

    <?php
    include('gatewayLogin.php');
    ob_start();
    session_start();
    echo '<title>My Internets</title>';
    function checkHost($host){
    	$q = mysql_query("SELECT * FROM allowed_host WHERE hostname = '$host'");
    	$n = mysql_num_rows($q);
    	if($n > 0){
    		if(justDay <= (justDay()+5)){
    			return true;
    		}else{
    			removeHost($host);
    			return false;
    		}
    	}else{
    		return false;
    	}
    }
    function allowHost($host){
    	if(!checkHost($host)){
    		$date = justDay();
    		$time = currentTime();
    		mysql_query("INSERT INTO allowed_host (hostname, date, time) VALUES ('$host', '$date', '$time')");
    		$_SESSION['allow'] = $host;
    	}
    }
    function removeHost($host){
    	if(checkHost($host)){
    		mysql_query("DELETE FROM allowed_host WHERE hostname = '$host'");
    	}
    }
    function getPassword(){
    	$q = mysql_query("SELECT password FROM password");
    	$n = mysql_num_rows($q);
    	if($n > 0){
    		$f = mysql_fetch_array($q);
    		return $f['password'];
    	}
    }
    function justDay(){
    	return date("j");
    }
    function currentDate(){
    	return date("M j Y");
    }
    function currentTime(){
    	return date("g:i a");
    }
    function logInfo($host, $value){
    	$date = currentDate();
    	$time = currentTime();
    	mysql_query("INSERT INTO logs (hostname, date, time, value) VALUES ('$host', '$date', '$time', '$value')");
    }
    $host = $_SERVER['REMOTE_ADDR'];
    if($_GET['cmd'] == "check"){
    	if(md5($_POST['password']) === md5(getPassword())){
    		allowHost($host);
    		header("Location: ?");
    	}else{
    		if(isset($_SESSION['failLimit']) && $_SESSION['failLimit'] >= 5){
    			logInfo($host, "Reached Fail Limit");
    			header("Location: ?cmd=limit");
    		}else if(isset($_SESSION['failLimit'])){
    			$_SESSION['failLimit']++;
    		}else{
    			$_SESSION['failLimit'] = 0;
    		}
    		logInfo($host, "Incorrect Password");
    		header("Location: ?show=fail");
    	}
    }else if($_GET['cmd'] == "limit"){
    	echo '<font color="red">You have reached the limit on incorrect passwords, try again later!</font>';
    }else if($_GET['cmd'] == 8675309){
    	unset($_SESSION['failLimit']);
    	unset($_SESSION['allow']);
    	header("Location: ?");
    }else{
    	if(isset($_SESSION['allow']) && $_SESSION['allow'] == $host){
    		header("Location: http://www.google.com");
    	}else{
    		if($_GET['show'] == "fail"){
    			echo '<font color="red">The password you entered is incorrect.</font>';
    		}
    		if(checkHost($host)){
    			if(isset($_GET['url'])){
    				header("Location: http//".$_GET['url']);
    			}else{
    				header("Location: http://www.google.com");
    			}
    		}else{
    			echo '
    			<form action="?cmd=check" method="post" />Enter Password: <input type="password"" name="password"  /><input type="submit" name="submit" value="Login" /></form>';
    		}
    	}
    }
    echo "<br /><i>".currentDate()."</i> - <i>".currentTime()."</i>";
    ?>
    

  2. Thanks for the (not needed) help, I guess I had a brainfart (again), here is how I fixed it:

     

    <?php
    function makeSportList($sportList, $name = ""){
    $list = '<select name="sport" id="sport">';
    $list .= '<option value="-1">All Sports</option>';
    for ($i=0;$i<=count($sportList);$i++){
    	if(md5(strtolower($name)) === md5(strtolower($sportList[$i]))){
    		$sel = "SELECTED";
    	}else{
    		$sel = "";
    	}
    	$list .= '<option value="'.$sportList[$i].'" '.$sel.'>'.$sportList[$i].'</option>';
    }
    return $list.'</select>';
    }
    echo makeSportList($sport_list);
    echo "<br />";
    echo makeSportList($sport_list, "football");
    ?>
    

  3. I am working on a function that makes a list out of an existing array, this website was pre-made, and I cannot locate the list for the life of me. How can I make a default value in function based off of a variable?

     

    <?php
    function makeSportList($name = "", $sportList = $sport_list){
    $list = '<select name="sport" id="sport">';
    $list .= '<option value="-1">All Sports</option>';
    for ($i=0;$i<=count($sportList);$i++){
    	if(md5(strtolower($name)) == md5(strtolower($sportList[$i]))){
    		$sel = "SELECTED";
    	}else{
    		$sel = "";
    	}
    	$list .= '<option value="'.$sportList[$i].'" '.$sel.'>'.$sportList[$i].'</option>';
    }
    return $list.'</select>';
    }
    ?>
    

     

    The manual says nothing of this. :/

     

    -thanks!

  4. You are trying to learn PHP and MySQL?

     

    Take a look here:

    http://www.tizag.com/phpT/

    http://www.tizag.com/mysqlTutorial/

     

    Reference:

    http://www.php.net

    http://www.php.net/manual/en/index.php

    http://www.php.net/docs.php

     

    These are the things that helped me the most, I am still learning. I am about to start learning classes. The biggest thing that helped me was trial and error. Oh and phpfreaks. Take a look at my posts in my profile, over half of them are php and mysql questions.

  5. Here is a XML write, I wrote for a ticker feed. It displayed scores and team names, along with the date and type of sport. Maybe you can edit it to suit your needs. Also remember to give it 0777 permission

     

    <?php
    //Re-Written to show only rows with ticker set = 1 or whatever is in manual_ticker
    $db_host = '?'; # The host of your server, normally localhost
    $db_user = '?'; # The user name you use to connect to the server
    $db_pass = '?'; # The password you use to connect
    $db_name = '?'; # The name of a database
    $fileName = "ticker/data.xml"; # The name of the XML file for the test2.swf
    $dbh = mysql_connect ($db_host, $db_user, $db_pass) or die (mysql_error());
    mysql_select_db ($db_name);	
    function findTeam($id){
    	$q = mysql_query("SELECT name FROM schools WHERE id = '$id'");
    	if(mysql_num_rows($q) > 0){
    		$f = mysql_fetch_array($q);
    		return checkName($f['name']);
    	}else{
    		return checkName("Unknown Name");
    	}
    }
    function checkName($name){
    	if(strlen($name) > 12){
    		return substr($name, 0, 12);
    	}else{
    		return $name;
    	}
    }
    function noGameInfo(){
    	$Info = "<item>\n";
    	$Info .= "<team1>None</team1>\n";
    	$Info .= "<team2>None</team2>\n";
    	$Info .= "<score1>NA</score1>\n";
    	$Info .= "<score2>NA</score2>\n";
    	$Info .= "<date>NA</date>\n";
    	$Info .= "<sport>No Games to Display.</sport>\n";
    	$Info .= "</item>\n";
    	return $Info;
    }
    function checkItem($item){
    	if(empty($item) || !isset($item) || $item == null || $item == NULL && $item != 0){
    		return "NA";
    	}else{
    		return $item;
    	}
    }
    $fileInfo = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" charset=\"us-ascii\" ?>";
    $fileInfo = "<images>\n";
    $q = mysql_query("SELECT * FROM games WHERE ticker = '1'");
    $n = mysql_num_rows($q);
    $q2 = mysql_query("SELECT * FROM manual_ticker");
    $n2 = mysql_num_rows($q2);
    if($n > 0 || $n2 > 0){
    	if($n > 0){
    		while($f = mysql_fetch_array($q)){
    			$fileInfo .= "<item>\n";
    			$fileInfo .= "<team1>".findTeam($f['hsid'])."</team1>\n";
    			$fileInfo .= "<team2>".findTeam($f['vsid'])."</team2>\n";
    			$fileInfo .= "<score1>".checkItem($f['homescore'])."</score1>\n";
    			$fileInfo .= "<score2>".checkItem($f['visitorscore'])."</score2>\n";
    			$fileInfo .= "<date>".checkItem($f['date'])."</date>\n";
    			$fileInfo .= "<sport>".checkItem($f['sport'])."</sport>\n";
    			$fileInfo .= "</item>\n";
    		}
    	}
    	if($n2 > 0){
    		while($f = mysql_fetch_array($q2)){
    			$fileInfo .= "<item>\n";
    			$fileInfo .= "<team1>".findTeam($f['team1'])."</team1>\n";
    			$fileInfo .= "<team2>".findTeam($f['team2'])."</team2>\n";
    			$fileInfo .= "<score1>".checkItem($f['score1'])."</score1>\n";
    			$fileInfo .= "<score2>".checkItem($f['score2'])."</score2>\n";
    			$fileInfo .= "<date>".checkItem($f['date'])."</date>\n";
    			$fileInfo .= "<sport>".checkItem($f['sport'])."</sport>\n";
    			$fileInfo .= "</item>\n";
    		}
    	}
    }else{
    	$fileInfo .= noGameInfo();
    }
    $fileInfo .= '</images>';
    $fileHandle = fopen($fileName, 'w') or die("Error Reading File: ".$fileName);
    fwrite($fileHandle, $fileInfo);
    fclose($fileHandle);
    ?>
    

  6. Back, again,

     

    So I have this function to check users if they are inactive for a certain length of time, then it marks them as offline, and vise-versa (did I spell that right?).

     

    The problem is it is marking everyone as offline! I checked the logic, and  the queries. It all checks out.

    I do not grasp the complete concept of the time() function, other than it produces some sorta time stamp.

     

    From my understanding, it is in seconds. So to get a 5 minuets ahead you would do:

    time()+(5*60);

    Right?

     

    Well any who, here is my function:

    <?php
    //Note: The echos are for debuggin' purposes
    function checkStaleUsers($checkInt, $idleTime){
    $time = time();
    if(!isset($_SESSION['~serverTimeCheck'])){
    	$_SESSION['~serverTimeCheck'] = time()+($checkInt*60);
    }
    if(time() >= $_SESSION['~serverTimeCheck']){
    	unset($_SESSION['~serverTimeCheck']);
    	$q = mysql_query("SELECT * FROM ".TBL_PEOPLE." WHERE timestamp > '0' AND activated = '1' AND ban = '0'");
    	$n = mysql_num_rows($q);
    	if($n > 0){
    		while($f = mysql_fetch_array($q)){
    			if($f['timestamp'] <= $time+($idleTime*60) && $f['online'] == 1){
    				mysql_query("UPDATE ".TBL_PEOPLE." SET online = '0' WHERE id = '".$f['id']."'");
    				echo "SET OFFLINE FOR: ".$f['email']."<BR>";
    			}else if($f['timestamp'] >= $time+($idleTime*60) && $f['online'] == 0){
    				mysql_query("UDPATE ".TBL_PEOPLE." SET online = '1' WHERE id = '".$f['id']."'");
    				echo "SET ONLINE FOR: ".$f['email']."<BR>";
    			}else{
    				echo $f['online'];
    				echo "<BR>";
    				echo $f['email'];
    				echo "<BR>";
    				echo $f['timestamp'];
    				echo "<BR>";
    				echo $time;
    				echo "<HR>";
    			}
    		}
    	}
    }
    }
    checkStaleUsers(5, 10); //Check every five minuets for users that are idle for ten minuets or more.
    ?>
    

     

    -Thanks, again.

  7. Thanks for your feedback.

     

    I tried to design game site that is simple and easy to use,

    I don't want my site to be bloated like many game sites I know.

     

    You can make a decent website without a lot of images. CSS allows a lot of really neat stuff. Take a look at my site (http://www.lamezz.com), I am not the best at making websites, but do you notice something? There is a total of 5 images on the index. The background, the logo, the user avatar, the site statistics icon and the newest member icon. I would try making your website more updated using Web 2.0 concepts.

     

    http://www.webdesignfromscratch.com/web-design/web-2.0-design-style-guide.php

     

    Hoped I helped. ;)

  8. okay so I did some updates. You can now resend confirmation emails and forgot password emails up to a limit of five times before getting a error. The website loads now in IE, the problem was due to a time check function that left it in a loop. I did some other subtle changes, but I have forgotten them.

     

    -Thanks!

×
×
  • 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.