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
DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

cka posted:

Also, I'm not too sure if it would matter or if it's just the OCD freak in me, but your math could use a quick fix here:

if ($now < ($subdata[1]+3600*$timeout) && $ip == $subdata[0])

should be

if ($now < ($subdata[1]+(3600*$timeout)) && ($ip == $subdata[0]))

in my mind, the first equation would be a loving huge number if your timeout was 2 hours because it would basically multiply the time + 1 hour by two...

They're equal in practice because the multiplication is performed before the addition.

Adbot
ADBOT LOVES YOU

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

MononcQc posted:

Well, if it's anything that can be confusing to someone else looking over your code, I'd say it's not a good idea. In this case, it's 99% sure to spark some confusion, so I'd go against it just because of that.

I disagree. One of the benefits of using classes is the ability to use simple, descriptive member names that won't collide with the same name in other contexts. If $obj->delete() is an appropriate name for what the function does, I'd use it. The fact that it's obviously an object member instead of a global function should eliminate any confusion.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
I agree that sanitizing should be the last step before output or very close to it, but that doesn't necessarily have anything to do with string concatenation syntax. In most of my applications, the process that outputs data retrieves all of its input from a store that sanitizes everything it receives.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Bonus posted:

what the hell

I'm trying to have a user upload an image and then I resize it with gd and save it. I'm using a mix of functions that I got from php.net and some other place. Thing is, it works for very small images, but if I try a bigger image (like 250k), I get this error message
code:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 7500 bytes) in 
F:\AppServ\www\klancar2\funcs.php on line 61
How the hell does it exhaust 16 megs of allowed memory size when trying to allocate 7500 bytes?

The error message is a little misleading. It means that PHP was already using its maximum memory size and tried to allocate an additional 7500 bytes over the limit.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

usingpond posted:

I've got a question that can probably be answered pretty easily. I'm more of a designer and Flash/Actionscript programmer, so I don't really have much knowledge about PHP other than obvious coding conventions.

Anyway, I'm trying to get a form to post to a CSV file for Excel output. After a few hours, I got everything to work right, except for some reason the data isn't added to the file, it just overwrites what was previously there.


It seems to me I'm just not putting in a simple argument somewhere, but any help is definitely appreciated.

You're probably opening a file handler for writing instead of appending, e.g.:

$f = fopen('file.txt', 'w');

The 'w' should be 'a' to append instead of overwrite.

$f = fopen('file.txt', 'a');

http://www.php.net/fopen

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Lankiveil posted:

I'm looking at implementing my own RSS feed generator, which will work off of a series of existing tables in my database. I had planned to simply write a PHP script that output the required XML straight to the client, but most of the tutorials that I've seen on the web do it by generating a flat text file at a regular interval and having that serve as the feed.

I had hoped to be able to do customisable feeds (ie: so the user can filter out particular contributors or topics and get a feed containing only that), but if I'm to generate flat files that will mean I'll need to do hundreds of them to cover every possibility. Is there some compelling reason why I can't just take a querystring (rewritten with mod_rewrite, of course) and spit the output directly to the user based upon the input parameters?

You should be fine. The most obvious reason off the top of my head is performance, but I wouldn't worry about it unless you anticipate enterprise-level traffic right off the bat.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

I'm having trouble understanding how you would extract information from elements lacking unique IDs or names with DOMDocument. There are a few things I have to grab by class or by a unique combination of tags wrapping around the data I need. Could you explain how you would use DOMDocument to grab that sort of info?

DOMXPath Class

XPath Tutorial

Example:
php:
<?
$dom = new DOMDocument::loadHTMLFile('example.html');
$xpath = new DOMXpath($dom);

// Get a list of all div elements where class = "foo"
$list1 = $xpath->query("//div[@class='foo']");

// Get a list of all a elements that are inside p elements
$list2 = $xpath->query("//p/a");
?>

DaTroof fucked around with this message at 07:44 on Jun 29, 2008

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

I can't figure out how to get wrappers working, so I'll just use CURL. Thanks for the tip.

I have another question, how do you get the value of an attribute via XPATH? I have an xml file that looks like this, and I'm trying to grab the ref[href] value (hello.php). Nothing I've tried doesn't seem to be working, and I can't find any good tutorials on it.
code:
<ASX Version="3">
<ENTRY>
<REF HREF="hello.php"/>
<MBLINK HREF="http://www.example.com" />
</ENTRY>
</ASX>

I don't think you can do that with XPath alone. Try pulling the node via XPath, then reading the attribute from the results. Example:

php:
<?
$nodes = $xpath->query('//REF');
foreach ($nodes as $n) {
    echo $n->getAttribute('HREF');
}
?>

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

The problem is, the site redirects urlencoded requests and curl can't follow the redirect. If I pass an urldecoded string to curl, it automatically tries to grab the urlencoded page. Unless there is some little-known parameter that makes curl ignore urldecoded URLs, I don't see a solution to grab a page with spaces in the URI when the host site requires it.

That doesn't make much sense. Like Zorilla said, it violates the standards. What happens when you put the URL with spaces in a browser's address bar? How about when you replace the spaces with + instead of %20?

Edit: By the way, you can tell cURL to follow redirects by setting the CURLOPT_FOLLOWLOCATION option to true.

DaTroof fucked around with this message at 20:09 on Jul 5, 2008

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

It's the actual path where the content is located. Properly encoded URLs are redirected to the standard-violating path.

That's what doesn't make sense to me. The browser should encode the URL before it gets sent. If the browser requests a URL with illegal characters, the server should respond with a bad request error. If it requests a URL with encoding, the server should unencode it before it tries to resolve it to a local file path, so you shouldn't need the redirect in the first place.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Bonus posted:

Yeah, foreach is basically the control flow construct for templates. It needs minimal logic and produces the desired behaviour. If you wanted to put foreach loops out of your templates, you'd probably have to generate all the HTML that requires looping in the controllers and then pass that off to the views ... :wtc:

the first and worst sin of home-grown template engines is usually that they suck at iteration, which usually means they suck loving period.

either you're using a foreach() in your templates, or you have some equivalent to a foreach() method in your template engine, or your template engine loving sucks. even trivial web sites usually need some way to loop through a collection, for chrissake

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Safety Shaun posted:

I'm learning. So gently caress off jerkbag.

This is a place for people to ask for help and some people are very helpful.

Come on, man. You're not even trying. Your previous post seems to indicate that you know how an array works, so how can you not be able to figure out what you want to do from the example you copied?

Here's a hint: $data is an array of the columns.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Stephen posted:

Is it possible to do a redirect with POST values in PHP? I've learned from Google that it's not possible with header(), but I haven't found any other way to do this.

Redirects don't POST. One workaround is to store the POST values in a session variable.

php:
<?
// form.php
session_start();
if ($_POST['submit'] == 'Submit') {
    $_SESSION['posted'] = $_POST;
    header('Location: redirect.php');
}
?>
<form action="" method="post">
    <input type="text" name="sometext" />
    <input type="submit" name="submit" value="Submit" />
</form>
php:
<?
// redirect.php
session_start();
print_r($_SESSION['posted']);
unset($_SESSION['posted']);
?>

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

functional posted:

Instead of having one nice sort that works, PHP has ten different sorts, none of which works. This is an easy problem in several other languages. It is not trivial in PHP. It is typical though of the kind of thing PHP programmers have to deal with, which is why I posted it here.

It's really not all that non-trivial. Here's a solution I hacked together in a few minutes.

php:
<?
class IntegerSet {
    var $value;
    var $count;
}
function _pokerSortCmp($a, $b) {
    if ($a->count > $b->count) {
        return -1;
    }
    if ($a->count < $b->count) {
        return 1;        
    }
    if ($a->value > $b->value) {
        return 1;
    }
    if ($a->value < $b->value) {
        return -1;
    }
    return 0;
}
function pokerSort($array) {
    $grouped = array();
    foreach($array as $i) {
        if (isset($grouped["{$i}"])) {
            $grouped["{$i}"]->count +=1;
        } else {
            $grouped["{$i}"] = new IntegerSet();
            $grouped["{$i}"]->value = $i;
            $grouped["{$i}"]->count = 1;
        }
    }
    usort($grouped, '_pokerSortCmp');
    $result = array();
    foreach ($grouped as $i) {
        for ($t = 0; $t < $i->count; $t++) {
            array_push($result, $i->value);
        }
    }
    return $result;
}

$integers = array(1, 3, 3, 4, 5);
$sorted = pokerSort($integers);
echo join(", ", $sorted) . "<br/>";

$integers = array(2, 2, 4, 4, 4, 4, 5, 6, 7, 7, 8, 9);
$sorted = pokerSort($integers);
echo join(", ", $sorted) . "<br/>";
?>
I'm sure it can be improved, but the problem isn't interesting enough for me to waste many more brain cycles on it.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

weekoldsushi posted:

Actually I kinda blew me load a little earlier than expected.
Still having problems with pathinfo().

If I do this:
code:
$file_filename = $_FILES['filename']['name'];
[b]$file_fileinfo = pathinfo($file_filename); // <-- Check your variable names[/b]

echo $file_info['extension'], "<p>";
echo $file_info['basename'], "<p>";
echo $file_info['filename'], "<p>";
It won't echo anything for some reason. Echoing $file_filename returns aux1.gif, but the array in pathinfo is completely empty. Unless I set $file_filename to the actual string 'aux1.gif' it won't fill the pathinfo array with anything. What's the deal with that?

$file_fileinfo should be $file_info?

If you're looking for the full path for the uploaded file on the remote machine, e.g. c:\My Documents\image.gif, that information doesn't get submitted. If you want the local path of the uploaded file on your server, check $_FILES['filename']['tmp_name'] instead.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Mine GO BOOM posted:

The submit button is its own field. Can look for $_POST['submit'] == 'Report' and skip the hidden variables.

Internet Explorer doesn't send the value of the submit button if the user submitted the form without clicking it, e.g. by pressing enter in a text field, so sometimes it can be useful to identify the action in a hidden value.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

duck monster posted:

I'd actually strongly discourage doing this, because its not nestable and thus its not scaleable.

If you find later down the track your output needs to be captured for some sort of nefarious cacheing type purpose or whatever, then your kinda hosed.

Not necessarily. PHP stacks output buffers. But it still won't work for nbv4's purpose, because you can't break to output in the class declaration either.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
Edit: Oops, question already answered.

DaTroof fucked around with this message at 05:47 on Oct 18, 2008

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

microwave casserole posted:

I'm thinking about writing a very simple content-management system that reads articles from an RSS file instead of a database. It would basically be a site-specific RSS reader, with manual editing of the RSS file instead of something where you log into the site to make new entries.

Is this a decent idea code-wise? I'm pretty new to PHP and programming for the internet, so I don't know if this would be horribly inefficient or have any other conceptual problems.

That sounds really impractical. RSS is an okay format for distributing data, but a terrible way to store and manage content.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

royallthefourth posted:

That sounds like a great prank, but I'm sure someone's done it in a real application. :psyduck:

I'm pretty sure it used to be common practice in PHP-Nuke.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
I'm using a framework that handles database queries with prepared statements. Lately I've been struggling with huge dynamic queries that need to swap joins and other clauses based on various conditions. It's a major headache to do it by manipulating strings. I've looked at ORM frameworks like Propel, but they seem like more trouble than they're worth for this project. All I really need is a library that helps me generate dynamic SQL without forcing me to append strings and fight over misplaced clauses and commas.

My current solution is a class that works something like this:

php:
<?
$select = new Select();
$select->table('customer');
$select->field('customer.name', 'customer.email');
$select->order('customer.name');
$select->where('customer.country = ?', 'US');
if ($user == $not_an_administrator) {
    // Add a join and a where clause to filter for customers that belong to
    // this user
    $select->innerJoin('representative', 'representative.id = customer.repid');
    $select->where('representative.id = ?', $userid);
}
?>
I'm sure I've seen this type of thing before, but I can't find a decent version of it. Google searches turn up stuff that's lamer than the version I slapped together in an hour. Does anyone know of a mature library for this type thing? I'd rather not spend a bunch of time developing my own, but I don't want a framework that requires a bunch of boilerplate, either.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

I'm looking for something to help me build dynamic SQL queries against arbitrary table definitions. An ORM framework isn't out of the question, but the actual object-relational mapping isn't the important feature to me. I've browsed the documentation for Doctrine and Propel, but

quote:

I don't want a framework that requires a bunch of boilerplate

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Golbez posted:

I've been reading through the thread and came upon this. I use PHPMailer, and a new version was just released last month (a month after this post was written); was it considered defunct because it's bad, or defunct because it'd been a while since the last update?

Do others agree that SwiftMailer really is the way to go?

I've been using PHPMailer for years, and I haven't had a reason to switch. The PHP 5 version works fine for me.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

fletcher posted:

I've been a big fan of EditPlus for awhile now for all my PHP needs. I really find myself wanting an object outline and some basic auto-completion sometimes. Are there any lightweight editors that do that for PHP on windows? I like Eclipse for Java but didn't really like it for PHP.

I'm in the middle of evaluating NuSphere PhpEd. It's not as lightweight as EditPlus, but I imagine that would be true of any IDE that can outline objects and complete code. It's nowhere near as heavyweight as Eclipse or Visual Studio, either.

So far I'm really impressed. I downloaded a massive project (around 10MB of source code) for local development. Frankly, I expected PhpEd to get a little confused about the class hierarchy. I opened a script and instantiated a derived class that depends on an autoload function for inclusion. The editor gave me all of its public members without a hiccup. It includes doc comments in the code completion if they exist (method and argument descriptions, etc.). And this is on an antiquated Thinkpad running XP Pro with 512MB of RAM.

Unfortunately, it's also not as cheap as EditPlus, but a free trial is available.

DaTroof fucked around with this message at 00:56 on Jan 5, 2009

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

scanlonman posted:

Does anybody know how to get the value of an array from an array? That sounds pretty confusing after reading it, so here's an example:
php:
<?
 $header = array("Home","Info"=>array("E-Mail","Other"));
 echo $header[0];
 echo $header[1]; //Line 3
?>
How would I get line 3 to output 'Info'? Right now it outputs nothing and it's confusing me.

You're trying to get the element's key, not its value. The confusing part is that you're mixing an indexed array with an associative array, since you didn't give the first element a key.

php:
<?
 $header = array("Home","Info"=>array("E-Mail","Other"));
 $keys = array_keys($header);
 echo $keys[0]; // Prints "0" because this element doesn't have a key
 echo $keys[1]; // Prints "Info"
?>

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

supster posted:

You really think that is less "messy" than "select whatever from tablename"?

SQL abstraction can be useful when applications need to insert clauses dynamically, assuming it's smart enough to let you define clauses in an arbitrary order.

php:
<?
// Select all invoices in the past thirty days if the user is an administrator,
// or select invoices on which the user is designated a manager otherwise
$select = new Select();
$select->fields("invoice.id, customer.name");
$select->from("invoice");
$select->innerJoin("customer", "invoice.customer = customer.id");
$select->where("invoice.datecreated > ?", $thirty_days_ago);
if ($user_is_not_administrator) {
    $select->innerJoin("invoice_manager", "invoice_manager.invoice = invoice.id");
    $select->where("invoice_manager.manager = ?", $user_id);
}
?>
You could build the same query as a string, but abstraction puts the focus on application logic over SQL syntax.

DaTroof fucked around with this message at 18:48 on Mar 8, 2009

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

eHacked posted:

That seems way too simple.

It's about that simple. I'd add a few more headers to make sure IE doesn't choke on it, among other things:

php:
<?
header('Pragma: public');
header('Cache-Control: max-age=0');
header('Content-Type: text/plain');
header('Content-Length: ' . strlen($fl));
header('Content-Disposition: attachment; filename="export.txt"');
echo $fl;
exit;
?>

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

drcru posted:

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?

Store the nonce (in your example, the action value is a nonce) in a MySQL table with a timestamp and delete records older than you want to allow. Delete the nonce when it's requested.

Storing them in MySQL is the exact opposite of eating up all your RAM.

Edit: Sorry, "exact opposite" is an exaggeration. My point was that an RDBMS is supposed to be a scalable datastore, and you might as well take advantage of it for as much as you can, which is a long-rear end way.

DaTroof fucked around with this message at 02:27 on Apr 29, 2009

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Zajako posted:

The problem here is, most of these links don't have a full url.

You can use parse_url() on relative paths. They have to be pretty goddamned malformed before it throws up on them.

php:
<?
$urls = array(
    'local://index.php?action=website-view&WebSiteID=366&WebPageID=9029/',
    '/index.php?action=website-view&WebPageID=20407&WebSiteID=366',
    '/index.php?action=website-view&WebPageID=20407',
    'index.php?action=website-view&WebPageID=20407',
    'local://index.php?action=website-view-item&WebSiteID=9&ItemID=1949/',
    'http://website.com/index.php?action=website-view-category&WebSiteID=9&CategoryID=509',
    'http://website.com/index.php?action=website-view-catalog&WebSiteID=9',
    '/index.php?action=website-view-item&WebSiteID=9&ItemID=1948',
    'local://index.php?action=website-view-item&WebSiteID=9&ItemID=1948/'
);
foreach ($urls as $u) {
    $parts = parse_url($u);
    if (isset($parts['query'])) {
        parse_str($parts['query'], $parts['variables']);
    }
    print_r($parts);
}
?>
Output:

code:
Array
(
    [scheme] => local
    [host] => index.php?action=website-view&WebSiteID=366&WebPageID=9029
    [path] => /
)
Array
(
    [path] => /index.php
    [query] => action=website-view&WebPageID=20407&WebSiteID=366
    [variables] => Array
        (
            [action] => website-view
            [WebPageID] => 20407
            [WebSiteID] => 366
        )

)
Array
(
    [path] => /index.php
    [query] => action=website-view&WebPageID=20407
    [variables] => Array
        (
            [action] => website-view
            [WebPageID] => 20407
        )

)
Array
(
    [path] => index.php
    [query] => action=website-view&WebPageID=20407
    [variables] => Array
        (
            [action] => website-view
            [WebPageID] => 20407
        )

)
Array
(
    [scheme] => local
    [host] => index.php?action=website-view-item&WebSiteID=9&ItemID=1949
    [path] => /
)
Array
(
    [scheme] => http
    [host] => website.com
    [path] => /index.php
    [query] => action=website-view-category&WebSiteID=9&CategoryID=509
    [variables] => Array
        (
            [action] => website-view-category
            [WebSiteID] => 9
            [CategoryID] => 509
        )

)
Array
(
    [scheme] => http
    [host] => website.com
    [path] => /index.php
    [query] => action=website-view-catalog&WebSiteID=9
    [variables] => Array
        (
            [action] => website-view-catalog
            [WebSiteID] => 9
        )

)
Array
(
    [path] => /index.php
    [query] => action=website-view-item&WebSiteID=9&ItemID=1948
    [variables] => Array
        (
            [action] => website-view-item
            [WebSiteID] => 9
            [ItemID] => 1948
        )

)
Array
(
    [scheme] => local
    [host] => index.php?action=website-view-item&WebSiteID=9&ItemID=1948
    [path] => /
)
Is there something else you need?

Edit: ah, I just noticed it doesn't like the URLs with a local scheme, but that should be trivial enough to detect.

DaTroof fucked around with this message at 17:35 on Jun 22, 2009

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

fletcher posted:

I am retarded and didn't even think of returning anything from the constructor. Thank you!

PHP does not let you return values from a constructor. It sounds like you should use a static function. You can make the constructor private so the only way to retrieve the object is through the static function.

php:
<?
class CachedObject {
    private function __construct($id) {
        // Code to create the object from the db (and save it to the cache)
    }
    public static function Get($id) {
        $obj = $cache->get($id);
        if ($obj != null) {
            return $obj;
        } else {
            return new CachedObject($id);
        }
    }
}

$x = new CachedObject('12345'); // This won't work

$y = CachedObject::Get('12345'); // This will
?>

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

frumpus posted:

It sure looks to me like this code should list the events AFTER the table header...

code:
<table width="325" border="0" cellpadding="0">
  <tr>
  <th width="325" class="tableHead" scope="col">Upcoming Events</th>
  </tr>
  <tr></tr>
  <?php
    While ($eventRow = mysql_fetch_array($rsUpcomingEvents))
     {
     ?><tr><strong><?php echo $eventRow['Day'] . ", " . $eventRow['Date'] . " " . $eventRow['Time']; ?></strong><br />
     <?php echo $eventRow['Game']; ?><br />
     <?php echo $eventRow['Details']; ?><br />
     </tr>
     <tr><img src="suits.png" /></tr><?php
     } ?>
</table>
...but instead it does this.



I'm used to working in ASP so I'm sorta clueless here. Can someone give me a clue please?

Your table is malformed. Your loop puts content directly in the <tr> element instead of a <td> element. The empty <tr></tr> right before the loop might be a problem, too.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Hammerite posted:

I find object oriented programming style difficult to understand, so I avoid using it in favour of what I understand to be called "procedural" programming. Plenty of things you see documented at the PHP online manual have examples of both procedural and OO style use. I figured this would hopefully be the case for prepared statements as well.


I would like to be able to say that object oriented notation appears precisely nowhere in my site's scripts, but I had to (grudgingly) use some in order to send emails using PEAR.

Cripes. You can use, for example, mysqli with nothing but procedural functions, but it still uses objects in the background. I strongly recommend that you familiarize yourself with OO concepts unless you intend to never work on projects that are non-trivial or involve other people. There's no way in hell I would staff a programmer who held this opinion.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Hammerite posted:

Oh dear, have I unwittingly stumbled into a part of these forums reserved for aspiring IT professionals?! :) If I decide to choose programming as a career path rather than a hobby, you can bet my attitude to this and other things would be different.

It shouldn't be surprising that the people who frequent a forum for programmers take programming seriously and care enough to encourage good practices. Even the hobbyists.

I only made that remark about staffing to show how strongly I felt about the subject. When you ask a question that implies a fundamental problem with your approach, people are going to point it out. And when your project starts with that kind of deficit, any questions you might ask later will be more complicated and difficult to answer.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
I'd recommend trying SimpleXMLElement first. It's easy to use and works great for most situations where you need to read XML.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Yossarko posted:

Why did they even add that functionality ?

Probably because Perl had it first. A few other languages have a similar mechanism. It's a great trick if you ever need to make your code as fragile and unfixable as possible in a big loving hurry.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Soks posted:

Edit: This one even works on IE 6.0, amazing. I actually know my way around Java code decently, just never used it for anything web based, so I'm pretty confident I can get the code here to do exactly what I want... with only a little help.

It's JavaScript, not Java. I'm sure you can still figure out how to work with it, but the difference is not trivial.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Little Brittle posted:

I'm familiar with CURL, but I don't have access to the remote server. It is ran by a vendor and all they offer is this text file that updates at 10 minute intervals. I just want to find a way to be sure I don't grab an incomplete file.

Is this a problem you've already experienced, or are you just worried about the possibility? If it's actually possible for you to download an incomplete version of the file while the provider's in the middle of writing it, the provider is doing something hilariously wrong.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Yossarko posted:

How do I chmod folders that have been uploaded to the server via FTP ?

I work in Windows and have a framework with lots of sub folders. When I upload a website to the internet, I have a "setup" script that I first run that sets lots of things up, and sets a bunch of folders that need to be written to (via administration, or log files) to 755 or I even tried 777 but it fails. I can make a directory and write files in a folder, but I can't CHMOD an existing folder (I'm guesssing it's owner is my FTP login).

How do I get around this ? I used to connect via FTP and ftp_chmod the folders but I'm trying to do this without FTP.

I can't be the only one who transfers his website via FTP and then wants to be able to CHMOD ?

One option is to use PHP's FTP extension. Another is to make one writable folder that holds all the others, since the new folders you create there should inherit permissions by default.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Hammerite posted:

If someone prefers a different way of doing things to the way advocated by prevailing opinion on an internet forum, they must be suffering from a syndrome? That's a dumb thing to imply.

Are you saying that advocacy of tried and tested libraries like PDO is unique to this forum? That's a downright ignorant thing to imply.

If you don't understand why you've been accused of NIH syndrome, refer back to this:

quote:

I don't have a good handle on what PDO "does". I have a good idea what my function does, though, as I wrote it myself!

It's totally your prerogative to write a custom solution for a problem that's already been solved. Just don't expect a lot of pats on the back for it. If you ever need to ask why a query isn't working, you'll need to post the function code along with it, and the first question you'll get back from anyone who's never seen it is "Why aren't you using a common library?"

Adbot
ADBOT LOVES YOU

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

IT Guy posted:

Wait, I'm not up to speed on why this is a bad thing.

Can someone inform me?

What about domain name registration, is that alright with GoDaddy? If not what's good?

In my experience, GoDaddy tends to use underpowered and overloaded servers running out-of-date software for shared hosting. Sometimes their server configurations require exceptional code for things that "just work" on most other hosts, which is annoying.

Their domain name registration, however, is top-notch.

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