1. PHP magazines & blog suggestions

    Date: 05/29/07     Keywords: php, programming

    Part of my morning ritual is to run through the following php and related sites:


    Anything else out there thats educational/useful?

    Source: http://community.livejournal.com/php/568391.html

  2. AJAX Issue

    Date: 05/26/07     Keywords: html, java

    Clicking on the generated button basically refreshes the page. No POST, GET or even REQUEST data is sent/available. This is pissing me off.

    Please help or else I might just stab myself in my heart with a JS pointer.

    HTML (Smarty) Code




















    Javascript

    Source: http://community.livejournal.com/php/568145.html

  3. permissions problem

    Date: 05/23/07     Keywords: database, linux, apache

    Have all these pdfs on a linux server here at work. They are associated by id numbers in a database. Sometimes the pdfs are assigned a wrong number so I have a script that changes where they are stored and what number they have in the database. Everytime I try to do it though I get an error on rename (which I'm also using to move files). Says permission denied.The files are owned by the "tech" user and the user trying to rename them is "apache". But I the pdfs are set to 777 so I don't understand why it doesn't have permission. Any suggestions?

    *edit*
    Used a perl script instead. Problem solved.

    Source: http://community.livejournal.com/php/567585.html

  4. Splitting up a very long 'word' in a string

    Date: 05/21/07     Keywords: no keywords

    I'm familiar with wordwrap, but is there a similar function which will limit the size of a 'word'?   In other words, is there a built-in function which will turn this:

    asdfasdfasdfasdfsafsadfasdfasdfsadfasfsafsadfsadfsadfasfsafsafsafsafsadfsadfsadfsadfasfasfsdsdafsadfsadf

    into this:

    asdfasdfsafdsafdsafdsadfsdaf
    asdfasdfsadfsadfsadfsadfsdaf
    asdfasdfsadfsafsadfasfsadfsda
    saddfsadfsafsafsafsafsdfsadf

    Source: http://community.livejournal.com/php/567439.html

  5. PHP or Python?

    Date: 05/19/07     Keywords: php, browser

    Hey guys. Looking for the right solution on something I'm developing. I figured a way to do what I want to do with PHP but I'm wondering if maybe Python or C might be the better solution. Perhaps someone with experience in this realm can give me some advice.

    I've been developing a turn based game in Flash but all of my data retrieval and storage happens with LAMP. The game allows the player to either play vs. AI that I've developed within the Flash app, but I'm wanting to add a pvp element. As of now, the player makes a turn(s) and it then passes the data for storage and goes into the queue for the other player to make his (a lot like itsyourturn.com, etc)

    I'm wanting to create I guess what you'd call a relay server that would allow two players who were on the site to not have to refresh the browser or reload the app to check if its their turn, etc. Obviously the app would have either a consistent connection or periodic calls to the server/script for both listening and broadcasting events.

    I could code such a beast in PHP but I'm wondering about performance since each call to PHP would be a new call (say every second or so). Has anyone ever done anything like this with PHP before or should I be safe and develop a Python or C program to do what I'm wanting to do?

    Just looking for some insight before I make my decision. Thanks!

    Source: http://community.livejournal.com/php/567291.html

  6. Distance Calculator?

    Date: 05/16/07     Keywords: php, google

    Does anyone here use a PHP-based distance calculator to divine the approximate distance between two zip codes? I can Google up a couple of programs that purport to do this (one of them flat-out broken - boo!), but if there's anything that anyone's used themselves and can recommend, that would be awesome.

    (EDIT: Paid is okay, but obviously free is better. *G*)

    Source: http://community.livejournal.com/php/566621.html

  7. Sigh

    Date: 05/14/07     Keywords: php, mysql, html, sql

    At the end of a very long and tedious php/html/mysql job...

    echo "\n\n\n\n\n";

    I'm just glad it's over actually.

    Source: http://community.livejournal.com/php/566489.html

  8. word(press themes)

    Date: 05/13/07     Keywords: web

    i've started work on a wordpress theme for my personal website. any suggestions or ideas to make this as smooth as possible?

    Source: http://community.livejournal.com/php/566090.html

  9. Komodo Edit

    Date: 05/12/07     Keywords: no keywords

    I was just giving a heads up to anybody that didn't know, ActiveState has a free version of Komodo out called Komodo Edit. You can get it here. It's not as feature-full as the Komodo IDE, but it's a nice editor with good code coloring features, project management, and ftp built-in. Plus, it's free :D

    Source: http://community.livejournal.com/php/565830.html

  10. Problem: opendir

    Date: 05/12/07     Keywords: php

    Using a simple script that list the files in a folder
    (found here:  http://us2.php.net/manual/en/function.readdir.php)

    It works great, except for opendir

    The php file (script.php) exists in:  /my/site/folder

    The files I want to list exists here: /my/site/folder/files

     
    I can’t get opendir to read anything outside of /my/site/folder

    I’ve done this kind of pathing before with other functions, but I can’t figure it out.

    The error ALWAYS indicates there is no such file or directory in: /my/site/folder/script.php

    The fact that the error shows the script file has got to be a clue--but not one I'm tapped into.

    Any Ideas?

    Source: http://community.livejournal.com/php/565645.html

  11. Function problems

    Date: 05/11/07     Keywords: no keywords

    Hi all!

    I am having some problems with a function that I have created for myself. I cannot figure out why it is not working because there are two other functions that are coded the exact same way and they work just fine.

    edited to add: If I hard code the case into the function call it works properly. So for whatever reason it isn't getting the correct information from $user while the others are. Can anyone suggest why this would be happening?

    edited again to note that the problem is now resolved. thanks for the help!

    function determineDownloads($a) {
    	switch ($a) {
    		case "canbus":
    			$bronze = 500;
    			$silver = 1000;
    			$gold = 2000;
    			break;
    		case "canman":
    			$bronze = 2000;
    			$silver = 2000;
    			$gold = 2000;
    			break;
    		case "amman":
    			$bronze = 5000;
    			$silver = 5000;
    			$gold = 5000;
    			break;
    		case "namrep":
    			$bronze = 2000;
    			$silver = 2000;
    			$gold = 2000;
    			break;
    	}
    
    	echo "Bronze Package downloads: ".$bronze."  records<*br>\n";
    	echo "Silver Package downloads: ".$silver." records<*br>\n";
    	echo "Gold Package downloads: ".$gold." records\n";
    
    }


    When I call this function (determineDownloads($user)) all it puts out is:

    Bronze Package downloads: records
    Silver Package downloads: records
    Gold Package downloads: records

    without the actual record count. The function below works properly and displays the correct information and I can't find or figure out why it works but the above doesn't. That is, the below function gets the correct value for $user but the above doesn't. The value doesn't change and is retrieved when the page is first loaded. It doesn't make sense that one function would get the correct value and another wouldn't. At least not that I can see. Any help would be greatly appreciated.

    Working function:
    function determineResults($a) {
    	switch ($a) {
    		case "canbus":
    			$bronzeresults = 500;
    			$silverresults = 500;
    			$goldresults = 500;
    			break;
    		default:
    			$bronzeresults = 500;
    			$silverresults = 1000;
    			$goldresults = 2000;
    			break;
    	}
    
    	echo "Bronze Package search results: ".$bronzeresults."<*br>\n";
    	echo "Silver Package search results: ".$silverresults."<*br>\n";
    	echo "Gold Package search results: ".$goldresults."\n";
    }


    (Please ignore the * in the br tags, for whatever reason it was displaying those as line breaks instead of the actual code)

    Source: http://community.livejournal.com/php/565481.html

  12. Using something other then preg_match?

    Date: 05/11/07     Keywords: php

    Hey all, I am trying to parse large amounts of text into easier to read (and deal with) bits. The problem I am having is the text is repeating and I need to keep track of what belongs to what. An example might explain better as I am up later then normal beating my head against the keyboard. The text would be something like the following:

    Name: Person1 at Number: Number1
    Spouse: Spouse1
    Address: Address1


    Name Person2 at Number: Number2
    Address: Address2

    So I need to keep track that Spouse1 belongs to Person1 and so on. And sometimes there might not be a Spouse field so I can't just do a large match including the multiple lines. Also if it matters the person is cut/pasting this info into a text area and posting it back to the same php, but I have that part worked out with a simple code below, if you have any better ideas on it as well fill free to share.

    
    
    

    Source: http://community.livejournal.com/php/565099.html

  13. wow. just wow.

    Date: 05/08/07     Keywords: css, html, database

        I've run into a bit of a problem at work. I thought I'd share as a good example of what not to do. We generate these e-signature contracts for clients. No biggie right? HA. They get the values and slap em in a bigass table, then they take all that HTML and put it in the database. In case you don't already know, this is a really bad idea. Today they wanted me to change up some of the layout and I said sure and went looking for the css, only to find HTML generated by Frontpage 4.0 stuck in a database table. I can't do anything with it. All they had to do was save the values in the db and print it out in an html page. Sorry if I'm ranting, but I want to stress that this is really stupid and nobody should even consider doing something this way.

    Source: http://community.livejournal.com/php/564514.html

  14. PHP rule engine?

    Date: 05/05/07     Keywords: php, java

    Hey, is anyone here aware of a PHP business-rule engine? I've been searching for 2 days now, and can't seem to come up with anything. Ruby has "Ruleby", Java has more than should be mentioned here, .NET has several..

    it's hard to believe that a language as popular as PHP with its abundance of enterprise-targeted frameworks wouldn't have a single prolog-like rule inference engine.

    halp?:)

    Source: http://community.livejournal.com/php/564241.html

  15. Security Tips

    Date: 05/05/07     Keywords: php, database, sql, security

    When creating a PHP form that writes to a SQL database, what basic security steps should be implemented (coded)?

    I have my own ideas, but I would like to hear what you guys have to say. Maybe we could create a list to include in the user info and memories.

    Code samples are encouraged. :D

    Source: http://community.livejournal.com/php/564045.html

  16. Temp Passwords

    Date: 05/04/07     Keywords: web

    This is probably lame….If you think I’m going in the wrong direction, please shoot me your thoughts.

    I have some users I want to support but they always loose their passwords.


    The information is a little delicate, so I don’t want to store the passwords without encryption.
    …And I don’t want to always be resetting people’s password information.

    So I thought I’d write a little script.

    Entering your email address on a webpage verifies the user is in the DB and sends them a temporary password in email that would only work for maybe 10 minutes or so.

    Other than that, it would work like a typical secure site, except that I would check the (time) expiration of the password regularly.

    (And I thought I might occasionally setup a CRON JOB (?) to wipe the DB of long-gone passwords.-----but I’ve never written a cron job so I’m not sure what might be entailed.)

    Is this wildly stupid?

    Source: http://community.livejournal.com/php/563886.html

  17. Coding Practice

    Date: 05/04/07     Keywords: php

    Let's say I want to see if $_REQUEST['id'] is set give variable '$a' that value, and if not give it a default value. The way I would write it is this:

    if (isset($_REQUEST['id'])) {
    $a = $_REQUEST['id'];
    } else {
    $a = "default value";
    }

    My friend would write it like this:

    $a = !empty($_REQUEST['a']) ? $_REQUEST['a'] : 'default value';

    ... his way seems pretty well, better. The variable "$a" is already there, and the conditions for what value to use are being set inside it (as I read it) rather than my way, which checks to see if this other variable exists first; and then sets $a appropriately.

    My question is where can I read up on this practice of writing PHP rather than what I now consider my old, clunky style.

    Source: http://community.livejournal.com/php/563673.html

  18. Firefox double counter problem

    Date: 05/01/07     Keywords: browser, database

    Hello again, everyone.

    I'm implementing a very simple 'self-configuring' counter script that essentially creates a counter for every page it's used on with the option to update the counter or not and to return or display the page's counter. It interfaces to a simple, one-table database with only two columns.


    define("NOTSET",-1024);
    $server = "server";
    $user = "user";
    $password = "password";
    $db = "db";
    $link = mysql_connect($server,$user,$password) or die("Cannot establish connection with counter server");
    mysql_select_db($db) or die("Cannot select database");

    //returns the CID (table col) hash according to $id
    //  (id should be the SCRIPT_FILENAME of the requesting page)
    function counterHash($id) {
      $md5 = md5($id); // md5 is relatively surjective
      return substr($md5,0,10);
      }
    function getCount($hash) {
      global $link;
      $safe = mysql_real_escape_string($hash);
      $query = "SELECT `count` FROM `counters` WHERE `CID`='".$safe."'";
      $result = mysql_query($query);
      if ( ! is_resource($result) ) { print("notset!"); return NOTSET; }
      $row = mysql_fetch_array($result,MYSQL_ASSOC);
      return $row['count'];
      }

    // If there isn't a row for $hash in the db, then one is
    // created and false is returned.
    // Otherwise, returns true.
    function createRowForHashIfNotExists($hash) {
      global $link;
      $safe = mysql_real_escape_string($hash);
      $q = "SELECT `count` FROM `counters` WHERE `CID`='$safe'";
      $result = mysql_query($q) or die("Cannot get status because ".mysql_error() );
      $n = mysql_num_rows($result);
      if ( $n === 0 ) { // no rows for our hash
        $q = "INSERT INTO `counters` (`CID`,`count`) VALUES('$safe','0')";
        mysql_query($q) or die("cannot create new counter because ".mysql_error() );
        return false;
        }
      }

    //sets the `count` col of $hash's row to $count
    function setCount($hash,$count) {
      global $link;
      createRowForHashIfNotExists($hash);
      $safehash = mysql_real_escape_string($hash);
      $safecount = (int)mysql_real_escape_string( (int)$count );
      if ( ! is_int($safecount) ) { die('setcount(hash,INTEGER)'); }
      $query = "UPDATE `counters` SET `count` ='".$safecount."' WHERE `CID` = '".$hash."' LIMIT 1";
      mysql_query($query) or die("Cannot update counter because " . mysql_error() );
      }
      
    $id = $_SERVER['SCRIPT_FILENAME'];
    $hash = counterHash($id);
    createRowForHashIfNotExists($hash);
    $visitorCounter = getCount($hash);

    function visitorCounter( $update=true, $show=true ) {
      global $link, $visitorCounter, $hash;
      if ( $update ) {
        setCount($hash,++$visitorCounter);
        }
      if ( $show ) {
        echo '
    '.$visitorCounter.' Visitors
    '
    ."\n";
        } else { // don't show so return
          return $visitorCounter;
          }
        return true;
      }

    ?>

    Everything works just fine in Safari (i.e. the page is visited and the counter increments only once), but in Firefox, the counter increments twice for no apparent reason. I figured this out only after wasting like three hours tracing through the program and reconstructing everything from scratch.

    Is anybody familiar with what might be causing this? Is there a glaring problem with my code? Or, perhaps, most importantly, do you happen to see a fix or workaround? I could just do a browser detection and then not increment if firefox, but that's really more like a bad hack than an effective workaround...

    Thanks in advance!

    Source: http://community.livejournal.com/php/563403.html

  19. text areas

    Date: 04/29/07     Keywords: no keywords

    When I store the data from my text areas, the data doesn't have line breaks.

    How do I fix that?

    Source: http://community.livejournal.com/php/563036.html

  20. PHP equivalent to eval { die(); } ; if ($@) { }

    Date: 04/27/07     Keywords: php, xml

    Is there a nice way in PHP can one can run a bit of code (in this case, a call to Smarty to render an XML document) and basically catch it if throws an error. My understanding is that eval in PHP only turns strings into executable code but doesn't catch dies/exits in the same way as Perl.

    The only way that I can think of doing it is by using a less than ellegant error handler hack:

    set_error_handler('empty_handler', E_ALL);
    $output = $smarty->fetch('xml.tmpl');
    restore_error_handler();
    
    if (isset($GLOBALS['errno']) && !empty($GLOBALS['errno'])) {
      // Do some backing out stuff here
    
      // Now pass over to the normal (and restored) error handler
      trigger_error($GLOBALS['errmsg'], $GLOBALS['errno']);
    }
    
    function empty_handler($errno, $errmsg, $filename, $linenum, $vars) {
      // Look out, nasty globals being used to feed back the data
      $GLOBALS['errno'] = $errno;
      $GLOBALS['errmsg'] = $errmsg;
    }
    

    There's got to be a nicer way to do this, right?

    P.S. I'm using Smarty as an example of any third party code that you might want to run that either has a trigger_error() burried in it that you might not have control over when calling.

    Source: http://community.livejournal.com/php/562933.html

Previous page  ||  Next page


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home