Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

php:
<?
        try
        {
            $rs = $this->db->CacheExecute($sql, $username);
            $this->user = $rs->FetchRow();
        }
        catch(Exception $e)
        {
            $this->user = array();
        }

        return $rs == true;
?>
Will this evaluate the last statement?

Adbot
ADBOT LOVES YOU

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Nope. And IP addresses shouldn't really tell you what timezone someone is in unless you try and lookup where it's coming from. But even then, you'd probably get the wrong timezone because the internet is like that.



Do I need to unset any class variables in __destruct() or does it do that by itself?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

CSS AND PHP would work if you want. Just change the style for that one link and add some sort of check to see where you are on the site.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

If this is Apache you can enable mod_expires.

I have an htaccess with something like this:

code:
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType application/x-javascript "access plus 172800 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType video/x-flv "access plus 2 seconds"
</IfModule>
Put it in the folder you want cached.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

S is for a session key. Since you're logged in, you shouldn't see a session key.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

What would be the best way to setup a bunch of obfuscated links like ?action=150jsZ that work only once and or expire after a few minutes?

I was thinking sessions but I want something more reliable. Maybe storing them onto MySQL or something but I don't want to eat up all my RAM.

Ideas?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Supervillin posted:

Base it on the current timestamp (or some hash of the time if you want it to be less obvious to the end user), then compare the time in your target script.

How do I measure the differences in time for the hash?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Whats a good way to encrypt and decrypt a variable with a specific salt?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Begby posted:

Do you want to encrypt some text and store it and decode it with a password or keyphrase later? Or are you trying to encrypt a password for storing in a db?

This. I want to be able to encrypt and store in the DB and later decrypt it. Any easy ways of doing this?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

They probably have terrible pings since you're likely somewhere in North America and they're XX hours away by plane.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Is this kind of memory usage too high? I have 1GB of RAM.

final: 607.7265625kB peak: 860.96484375kB
took 0.010162115097 seconds

edit: I'm doing three sql queries and processing the table data of one of the result sets in this page.

Acer Pilot fucked around with this message at 03:56 on May 21, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

supster posted:

lol no

Thank god. What would be too high for three sql queries? I haven't seen anything go over 1 megabyte.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Thanks, I've stopped worrying about it now.

Here's another one, what do you guys use for templating your pages? Other than Smarty that is. Do you roll your own systems or just put the HTML in with your code? I've been using Smarty personally but it seems a little too much for what I need to do.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Do any of these have anything in common? I saw someone making two way hashes like this and I'd like to try and do the same:

2ed3cbd5
11e1d49a
478c139d
d72d0f17

They look like they're hexadecimal and from what I see it's supposed to be related to the number 1073. Is there something in mcrypt that encodes variables like this?

edit: it looks like it has something to do with pack() and unpack()

Acer Pilot fucked around with this message at 01:39 on May 25, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

It'll be a bit trickier if they're uploading MS Word docs and various other text formats but if you're somehow storing the resumes in a textfield, you can use fulltext search in MySQL most likely.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Are there any reasons as to why this function gets occasionally slow?

php:
<?
    public function show_map($sector, $galaxy, $distance = 2)
    {
        $start_sector    = $this->galaxies[$galaxy]['start_sector'];
        $width            = $this->galaxies[$galaxy]['width'];
        $end_sector        = $start_sector + ( ($width * $this->galaxies[$galaxy]['height']) - 1 );
        $min            = $distance * -1;
        $tile            = 0;

        $map = array();

        for($l = $min; $l <= $distance; $l++)
        {
            $mid_of_line = ($sector + ($width * $l));

            if( ($mid_of_line < $start_sector) || ($mid_of_line > $end_sector))
                $mid_of_line = -1;

            $line = ceil(($mid_of_line - $start_sector + 1) / $width);
             $start_of_line = $width * ($line - 1) + $start_sector;
            $end_of_line = $start_of_line + $width;

            for($s = $min; $s <= $distance; $s++)
            {
                $current = $mid_of_line + $s;

                if( ($current < $start_of_line) || ($current >= $end_of_line) || ($current > $end_sector) )
                    $current = -1;

                if($current > 0)
                {
                    $map[$tile] = $this->info[$current];
                    $map[$tile]['sector'] = $current;
                    $css = "sector";
                    if($current == $sector)
                        $css .= " current";
                    if( in_array($current, $this->get_exits($sector)) )
                    {
                        $css .= " linked";
                        $map[$tile]['link'] = "./move.php?sector=$current";
                    }
                }
                else
                    $css = "explored sector";

                $map[$tile]['css'] = $css;

                $tile++;
            }
        }

        return $map;
    }?>
Could the fact that $sector is different on every page load as it is updated in MySQL have anything to do with it?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Sorry about the lack of comments. Here's a picture of what this actually does.



In this example $sector = 288 and $galaxy = 1. The green circle is where we are and the yellow boxes are where we can go.

$galaxy is not important right now and I've commented the code below to include their values.

php:
<?
giant wall of code?>
Whenever someone "moves" their $sector is updated in the MySQL database and then show_map() is called again. Reloading the page without moving seems to cause lag sometimes.

$this->get_exits($sector) gets an array of sectors that the sector links to. A list of all sectors and their links is gathered at the beginning of the page through MySQL and is stored in $this->info. get_exits() just gets the row $sector from the result array. It shouldn't be calling any new queries.

I appreciate any attempts at even reading this. Thanks!

Acer Pilot fucked around with this message at 08:37 on Jun 12, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Thanks, I've moved the $this->get_exits($sector) out of the loop and put it at the start of the function in a variable called $exits.

Was there something wrong with my loop: for($s = $min; $s <= $distance; $s++) ?

I think I set the value of $min and $distance at the start properly.

edit: Maybe I'll add a count for the exit checking so it won't do an in_array check after there are for exits.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Thanks for the advice. Now if only my VPS were online...

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

I'm storing a list of integers in a comma separated textfield on MySQL and then explodin them into an array. I then check through a list of 25 integers and see if they are on the original list. Is there a better way to do this?

php:
<?
$galaxy = "144,145,119,118,117,92,93,68,69,70,91,116";

$explored = explode(",", $galaxy);

// this is done in a loop up to 25 times
if( in_array($current, $explored) )
{
echo "blah";
}
?>

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

You're using two different character encodings.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

How come it won't let me overload this function with time()? I seem to be able to do it with array()...

php:
<?
public function get_foo_bar( $cutoff = time() )
{
//
}?>
"Parse error: syntax error, unexpected '(', expecting ')' in "

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Cool, thanks for the explanations.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

I'm currently using ADODB to handle MySQL abstraction on my website but I recently updated to PHP5 and thought it might be a better idea to use something like mysqli or PDO.

Which of the two should I use to handle all my MySQL transactions?

If it matters, I use "update" a lot.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Hmmm. Binding parameters one by one is a little troublesome, but then again I only need to bind three or four at max...

If using adodb seems to be "slow" would that be an issue with adodb or MySQL?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

It takes a few seconds every once and awhile but not always.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Is there anyway to do the following with PDO?

Original
Array ( [0] => Array ( [map_id] => 1 [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [1] => Array ( [map_id] => 2 [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) )

Array Index is map_id
Array ( [1] => Array ( [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [2] => Array ( [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) )

I'm using fetchAll(PDO::FETCH_ASSOC) right now.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Begby posted:

I don't believe so. But it is pretty easy to create a function that will take your array from pdo and spit out your new fancy array. Like

code:
$newArray = ReKeyArray('map_id', $resultArray);

Thanks, I did something like that instead. Is there a nicer way to do this?

php:
<?
    function rekey($array)
    {
        $out = array();
        $max = count($array);

        for($i = 0; $i < $max; $i++)
        {
            $keys = array_values($array[$i]);
            if(is_numeric($keys[0]))
            {
                array_shift($array[$i]);
                $out[$keys[0]] = $array[$i];
            }
        }
        return $out;
    }
?>

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Right now I've got a try-catch in every function I have. Should I keep doing this or just have my functions throw exceptions and catch them all in the script that's calling them?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Hm. No replies in almost 3 days. I've gotten rid of most of the try catch statements in my functions and now have them throwing exceptions if it doesn't meet a requirement. Not sure if that's how I should be handling errors though.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Is it an exception you want to show the user? Or do you want them to see a generic "there is a problem with this page" type of thing?

I use set_exception_handler and don't have a single try/catch in my whole app. The exception handler function logs the exception so I can take a look at it later (as well as information used to help recreate it). Using the get_class function I look at the type of exception to determine what I display to the user. If it's a PublicException, I dislay the error message to the user. If it's anything else (PDOException, etc) I just display a generic error message or error page, depending on if it was a GET or POST that caused the exception.

Thanks, I was looking into set_exception_handler but didn't know how to use it properly :smith:.

Can you use an object in there?

Like set_exception_handler($e->handler)

It doesn't look like you can and I'd like to try and keep the logging, etc in a separate file.

ninja edit

Acer Pilot fucked around with this message at 23:04 on Aug 4, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Ah, thanks. I've never really looked into autoload. Got some reading to do!

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

How would I go about making sure something happens 75% or n% of the time?

If that didn't make sense, how can I make a random event happen n% of the time whenever a page is loaded.

I tried this but this doesn't seem right.

php:
<?
$r = rand(1,100);
if($r <= 75)
    echo "hit";
else
    echo "miss";?>
Thoughts?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

What's a good way to obfuscate my links without giant overhead/killing MySQL?

Right now I have links like move.php?sector=42 and would prefer something a bot can't easily read like action.php?whatever=HASH_GOES_HERE

The hashes should change whenever a player uses one...

Any ideas?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Can you describe the problem you are trying to solve a bit more?

It sounds like you should be using a POST instead of a GET to do whatever those links are doing, based on how you have named them. Either way it should be validating the "move" you are making server side. I should be able to tell it to do every move, but the only ones it actually does are the valid ones.

Right now, I have plain html links like this:
<a href="./move.php?sector=42">#42</a>

I want them to be something like this:
<a href="./action.php?cmd=HASHED_VALUE">#42</a>

move.php right now basically is this:
$sector = intval(stripslashes($_REQUEST['sector']));

rt4 posted:

Maybe you could make those links come out on the page as md5($sectorID), and then
SELECT * FROM Sectors
WHERE md5(sectorID) LIKE ?

That would obscure the actual sector IDs and would prevent users from guessing them. Of course, a bot playing your game could still scrape them off the page and play the game, but maybe it would prevent guessing.

Don't take this advice verbatim; it's not perfect. You'd at least want to salt those hashes, for starters.

Something like this could work since we already have a hash stored for the current session but that might not be enough if we want a new hash every move, right? Don't exactly want to update the session table every time we move though so hmm.

edit: Also thanks for the replies guys.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

What exactly does this solve though? Are you trying to prevent them from just changing the link to sector=43?

That's basically it.

Right now I'm trying to make a hash like this:

code:
$sector = 999;
$hash = base_convert($sector, 10, 36);
echo intval($hash, 36) . '<br />';
This works but when I run it with $sector = log10(999) it doesn't return the right answer. Seems like a math error on my part but I can't think anymore :(.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Check out the php crypt/mcrypt stuff.

Still though, what is bad about them changing it to sector=43? What makes this an invalid "move"? When they try to feed it sector=43, why can't the server determine that is not a valid move and just not perform it?

I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Short of a good CAPTCHA, a bot will be able to do pretty much anything a human could do on your site. Doesn't really matter if you use anchors or js. Also, a bot can click on a link to move.php?sector=42 just as easily as action.php?sector=SOMESCARYHASH so that really does nothing.

True, hm. I guess I'll just deal with the bot issue if this thing ever gets popular enough for someone to want to use a bot.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

So I'm trying to come up with a way to get players to cat with each other while playing a game. I looked up some of those PHP/ajax/json scripts that are out for free but they all look like they'd kill my server if there were too many clients on.

Any suggestions for a lightweight chat system? And I likely don't want to use IRC because my host doesn't allow that and I need to force players to keep their assigned name in chat.

Adbot
ADBOT LOVES YOU

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

epswing posted:

Or as a university prof of mine put it, "'all the elephants in the room are pink' is a true statement".

Was this in a MACM class and was he Russian and awesome? I think I know who you're talking about.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply