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
duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Wrote yourself a fancy image uploading script and want us to point out the problems? Can't figure out how to get rid of the mysterious slashes in the data from your form? Don't know why the slashes should probably be there? Need help writing OOP in PHP5? This thread will be for all that and any other PHP related issue. It does not have to be web related to be asked in here.
The official site has extremely useful documentation.



itskage has written up a handy guide to getting a useful dev environment setup on windows. If you're a *nix user, you should know which steps to skip.

itskage posted:

This has become less of a "copy the guide from these mark down files" and more of a "Retype the jist of stuff into a forums post". Sorry but there's more company specific stuff in them than I remembered, and it was quite long and I was fighting with the lack of md formatting, so I cut it down a lot, and now it is like a text dump, but hopefully it's useful to someone.

To be clear this is for windows.

Install NGINX
  1. Download the NGINX/Windows binaries http://nginx.org/en/download.html
  2. Make a folder for nginx and unzip there E.g.: C:\nginx\
  3. Run nginx.exe to start. You can verify installation by going to http://localhost/ and you should get the nginx welcome page.

Some notes:
If you have something else listening on 80 (XAMPP IIS Express) then you need to stop it or configure NGINX to listen on another port.
To stop NGINX after running it this way you have to taskkill it.

Install PHP
  1. Download the PHP binaries for windows. http://php.net/downloads.php
  2. Extract them to a folder. E.g.: C:\php\
  3. Start PHP and listen on 9000 `c:\PHP\php-cgi.exe -b 127.0.0.1:9000

Test PHP
In nginx's folder /conf/nginx.conf un-comment the php location, and alter the SCRIPT_FILENAME per below.
code:
     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

     location ~ \.php$ {
       root           html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params;
     }
- This is telling NGINX that any requests ending in .php should be forwarded to PHP and for PHP to execute the file at $document_root + relative path to the file.
- Add a test phpfile to the nginx root E.g.: nginx/html/phpinfo.php with
code:
<?php phpinfo();
- Restart the nginx process to load the changes.
- Now you should see php info when you navigate to http://localhost/phpinfo.php

Tweaking configs
Now I have a bunch of poo poo about tweaking nginx.conf, sites-available/yourside.conf and php.ini for our CMS and whatnot, that I won't touch here. NGINX is like apache with sites-availabe and sites-enabled and with that above snippet getting phpinfo working you should be able to figure it out, otherwise just ask.

Some stuff I will mention:
- Setup your SSL and hostnames if you are developing with https (which I don't know why you wouldn't in tyool 2018)
- Change your the root for your site in NGINX unless you plan to workout of C:\nginx\html or wherever you installed it.
- in php.ini be sure to uncomment any extensions you need (and ensure you have the .dlls for them in php\ext\) so like if you need curl just uncomment extension=php_curl.dll in the ini.
- Xdebug will be needed to debug in VSCode (does any IDE not need this?): dump your phpinfo() output into https://xdebug.org/wizard.php and it should result in you downloading a dll that you put in php\ext\ and then referencing in php.ini (zend_extension = php_xdebug-2.5.4-7.0-vc14-x86_64.dll)
- Confgure Xdebug in PHP ini. You can google a bunch of the options but minimum I do this for local development:

xDebug v3
code:
; Start in debug mode
xdebug.mode=debug
; Specify host if not using autodetect 
xdebug.client_host=127.0.0.1
xdebug.client_port=9003 
; Set to yes to always start instead of when triggered
;xdebug.start_with_request=yes 
; I don't know if this is actually needed
xdebug.idekey = VSCODE 
xDebug v2
code:
[debug]
; Always xdebug
xdebug.remote_autostart=1 
; Enable...
xdebug.remote_enable=1
; Debug at the start of every request
xdebug.remote_mode=req
; What host to send debugging info to (your local)
xdebug.remote_host=127.0.0.1
; Port to connect to VSCode on... be sure this is not your PHP port!
xdebug.remote_port=9003
; Auto start can be disabled and this can be enabled if you want to use a browser extension to enable/disable debugging, (from any machine even) but since it's local I don't see the point.
xdebug.remote_connect_back=0
Working files
Next I have directions about git cloning our projects down. It should be the same. Clone yours to where you set your NGINX site's root, (I'll just use C:\nginx\html\ for this). Once done or if starting from scratch you can open a workspace in vscode there. (ctrl+k ctrl+o). VSCode also has bulit in terminal (ctrl+`) so you can just run git commands there, or use the built in commands (F1 to open the command pallet, type git clone, follow prompts).

At this point if you have your site in the folder and all of your site's configs and any database connections or anything configured then your site should run under localhost (or if you need a hostname to serve multiple sites from one CMS like I do you can overwrite your hosts file).

Last thing is unless you want to run NGINX and PHP locally as a service (I don't) you will want something to start and stop them, so here's a bat file that kills any running nginx and php processes and then restarts them (and leaves the window open).
code:
@ECHO OFF

taskkill /f /IM nginx.exe
cd c:\nginx
start nginx

taskkill /f /IM php-cgi.exe
cd c:\php

Echo running php...
c:\php\php-cgi.exe -b 127.0.0.1:9000
You can add a task in vscode if you'd rather run that from the IDE.

Anyway that's the most rudimentary way to run NGINX and PHP locally on windows.


VS Code part:
Basic PHP support:
You still need PHP downloaded even if not running it locally because you will need to point your extensions at the .exe.
Microsoft will recommend you the: https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-pack which includes the debugger and IntelliSense, but I wasn't big on the intelliSense. Fortunatley you can get them seperately, so for me I just grab the debugger. https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
Then instead I use Intelephense: https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
Now you have to add some user/workspace settings (ctrl+,). I recommend putting these php specific things into workspace so they aren't trying to phpmd my node.js projects or dotnet core.
code:
    "php.suggest.basic": true, (disabling this will stop the double suggestions from the native VSCode's and the intelephens/IntelliSense)
    "php.validate.enable": true,
    "php.validate.run": "onSave", (I haven't tryied onType, but I'm constantly hitting ctrl+s from years of doing this so...)
    "php.validate.executablePath": "C:\\php\\php.exe", (or wherever you installed)
VS Code is pretty good and will autocomplete options and what not if you want to play with the settings.

Debugging:
This should work now, so open the debugging pane (ctrl+shift+d) then up at the top you have some profiles. Click the gear to get started and edit some:
Here's the most basic:
code:
 
     {
            "name": "Local",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "C:/nginx/html/" : "${workspaceRoot}"
            }
        },
Listens on port 9003 for xdebug. Just set a break point in your index.php or wherever is easy to test, hit F5 to start debugging the current profile, and then open that page in a browser and it should halt on your breakpoint.

I keep four profiles: local, remote (to debug a test server), tests (to halt on exceptions when running a bunch of tests), and current file (which I think is built in and is quite useless to me since we use a CMS with a dispatcher).

Composer:
https://getcomposer.org/download/ (recommend just using the EXE)
There is a VS Code extension. You don't need it, but it adds composer commands to the command pallet, and will validate your composer.json so I recommend it: https://marketplace.visualstudio.com/items?itemName=ikappas.composer
Back to workspace settings (crtl+,):
code:
    "composer.enabled": true,
    "composer.executablePath": "C:\\ProgramData\\ComposerSetup\\bin\\composer.bat",
If you have a composer.json in your project. You should be able to run composer install now (ctrl+` composer install to do it from the command line, or F1 composer install to do it from the command pallet). If not you will need to make one (and the necessary git/vcs exclusions).

Anyway add and run composer install/update and it should install PHPMD, PHPCS, and PHPUnit with a Code coverage plugin.
code:
    "require-dev": {
        "phpmd/phpmd" : "@stable",
        "squizlabs/php_codesniffer": "3.*",
        "phpunit/phpunit": "@stable",
        "phpunit/php-code-coverage": "@stable"
    },
You can generate xml for PHPMD and PHPCS rules easily here with this:
http://edorian.github.io/php-coding-standard-generator/#phpcs
You can even paste your XML back in later if you need to make adjustments

PHPCS: https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs
This is the less finicky of the two linters.
Workspace settings:
Where to find the rules to enforce, and where the cs script is. You're SUPPOSED to be able to go to vendor/bin/phpcs for this instead of the full path but that never worked for some reason.
code:
    "phpcs.standard": ".\\phpcs.xml",
    "phpcs.executablePath": "vendor/squizlabs/php_codesniffer/bin/phpcs",
PHPMD: https://marketplace.visualstudio.com/items?itemName=ecodes.vscode-phpmd
There's a couple of these. As of about August of last year that one was the best one, but PHPMD still tends to jam up sometimes on large projects/files espcially when the debugger is running.
If you notice this, just restart the debugger. You can also see at the bottom stuff like "PHP is linting document..." with a spinner and it hangs. Usually restart the debugger fixes that too.
What I think is the process to lint is getting locked behind an actual request you want to debug for some reason, and even though you finish in the GUI, VSCode debugger isn't communicating that back, and it just gets stuck. If someone knows better, by all means, please share.
code:
    "phpmd.verbose": true,
    "phpmd.rules": ".\\phpmd.xml",
If you don't use verbose then it doesn't tell you what rule the line is violating.

Once you get those setup you can see what horrors are lurking in the code base you've inherited:
The function getConfigJSONResponse() has an NPath complexity of 1773066240. The configured NPath complexity threshold is 200.
The function getConfigJSONResponse() has a Cyclomatic Complexity of 74. The configured cyclomatic complexity threshold is 10.
:allears:

PHP Unit: https://marketplace.visualstudio.com/items?itemName=emallin.phpunit
Only needed if you want to run tests in VSCode while developing.
code:
    "phpunit.execPath": ".\\vendor\\bin\\phpunit.bat",
    "phpunit.args": [
        "--configuration", ".\\Tests\\phpunit.xml",
        "--coverage-text=.\\Tests\build\\coverage.txt"
    ],
    "phpunit.preferRunClassTestOverQuickPickWindow": false, // Default false
Not going to cover the phpunit.xml and setup of tests unless someone needs it.

To run tests in VS Code hit F1 and type PHPUnit Test with nothing open or selected will run all tests in the listed configuration.
With a test file/case open and selected hit F1 and type PHPUnit Test to run all tests for that file.
To run a specific test, double clock the function to highlight it, then do the F1 type PHPUnit Test (this autocompletes after the first time) and then it will just run that single test.


Webpack:
Be sure you've installed node and npm. I'm assuming you know what this is and how it works outside of VSCode. If not, ask but don't just add it because it's here.
Then open a terminal and npm install webpack, or I recommend using a package.json for your project:
code:
{
    "name": "",
    "version": "",
    "description": "",
    "dependencies": {
        "webpack": "3.10.0"
    }
}
Then just npm install.

Now you just make a webpack.config like any other webpack project, and the cool thing is you can just make some tasks to run this for you:
Under Tasks -> Configure Tasks...
You can add these:
code:
        {
            "label": "webpak build",
            "type": "shell",
            "command": "${workspaceRoot}/node_modules/.bin/webpack",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "args": [
                "--colors",
                "--progress"
            ]
        },
        {
            "label": "webpak watch",
            "type": "shell",
            "command": "${workspaceRoot}/node_modules/.bin/webpack",
            "args": [
                "--colors",
                "--progress",
                "--watch"
            ]
        }
First one just runs a build. But you can have that set as default so it auto builds whenever you run a build task which you can even have it do when you start the debugger.
2nd one adds --watch so it will auto update with any changes you make.

Probably would be better breaking it down into multiple posts (it's 3 different guides in our private github) but there you go.

Summary
Anyway it's a bit janky for PHP, but it works fine when you know the quirks. I think NGINX+php-fpm is better than apache-php and VS Code is the best IDE in general. So if this helps some people try it out then great.

If you're like me and jump between dotnet core and node as well as PHP (and frontend js) then it's nice just being in one IDE. It's not perfect (sometimes even for dotnet core I have to open VS2017), but I like it.

Finally one last thing is you can now write the js for your PHP site in here with ts which has fantastic vs code support.

duz fucked around with this message at 15:09 on Jan 18, 2021

Adbot
ADBOT LOVES YOU

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


fletcher posted:

Can you combine a function call that returns an array with the array index you want like:
$something = $this->arrayReturningMethod()[0];
I tried it and it didn't work. Am I doing it wrong or can you not do this in PHP? Are there languages where this does work?

Naw, can't do that in PHP. Javascript can do what you want, don't know off hand what else could.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Kaluza-Klein posted:

I want to parse an html file. For example, say I want to know what is contained inside an <h1> tag. I can do this with strstr and substr but it is ugly.

You can use a combination of HTMLTidy to clean up the HTML and SimpleXML to search the document.

php:
<?
$config = array(
 'indent'         => true,
 'output-xhtml'   => true,
 'wrap'           => 200);
$tidy = new tidy;
$url = 'http://www.example.com/index.html';
$tidy->parseFile($url, $config);
$tidy->cleanRepair();
$doc = new DOMDocument();
$doc->loadHTML($tidy);
$html = simplexml_import_dom($doc);
$h1 = $html->xpath('//h1[@id="main"]');
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Daddy Fantastic posted:

Are there any benefits to using MDB2, assuming I'm already using mysqli prepared statements, won't be switching away from mySQL, and I'm not already using PEAR?

If you're already using prepared statements, then probably not.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Daddy Fantastic posted:

Is there a fancy one line PHP trick that could replace this foreach loop?

code:
$b = array( 'dookie', 'poop', 'gook', 'poon' );
$password = //randomly generated phoenetic password
		
foreach ( $b as $word )
{
	  if ( strpos( $password, $word ) !== false )
	  	  $password = //try again from scratch...
}

php:
<?
if (in_array($password, $b))
{
  // whatever
}
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Daddy Fantastic posted:

I'm not sure that will work though, since $password could be any length-- in other words, I'd like it to match words that include the banned words, but may contain other letters (like dookieq).

In that case no, the only other way I can think to do it would be to use a callback function with something like array_filter but that would take about the same amount of lines.
Edit: Or you could collapse the array to a single string but that could introduce false positives.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Kaluza-Klein posted:

Should you not escape the forward slash in the closing tag?

Yes, you should. However the forums like to eat escaping slashes.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


bt_escm posted:

With the way php currently handles objects there's no difference. However removing public or even not declaring the variables is just plain bad practice and could possibly break in future versions of php.

Correct. In PHP5, if a scope isn't declared it's assumed to be public because there was no scope in PHP4.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Finite posted:

:words:

It looks like you're using a database abstraction layer. Use its built in prepared query functions instead of string concatenations.
It also looks like you're using PEAR::DB, any chance you can upgrade to MDB2?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Uh, you're outputting text instead of an image. Get rid of that html nonsense.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


MrEnigma posted:

or move the header right before it. One other piece of advice, usually you want your functions to always return data, instead of printing it out. And then do a print/echo/whatever on on the function on your page.

You can't send headers after outputting content.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


That's because you're still outputting text instead of the image your header is telling the browser to expect.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


fletcher posted:

Which has corrected the malformed html. Is this a bad solution?

You could probably also use HTMLTidy to clean it up.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


drcru posted:

What kind of timestamps are these?

12314
12345
12356
12367
12378
12456
12859

The roll-your-own kind. Good luck figuring out that system!

duck monster posted:

Another tip, not really php, is hunt down an old javascript library called 'fvalidate' for the javascript side of it. But remember NEVER rely on javascript validation. fvalidate is neat however, since it just involves setting alt tags on input fields. Setting the alt tags is kind of neat, since it validates, and normally alt tags have no real role on input fields, so they are handy for hijacking for metadata.

Alt tags on inputs are for screen readers. jQuery has a nice form validation plugin that uses class names or you can use JSON to build you validation requirements.

Treytor posted:

Without using curl, but fopen instead?

Edit: fopen is GET only, not POST, sorry. vv Learn something new all the time, that might come in handy.

duz fucked around with this message at 03:50 on Apr 1, 2008

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Treytor posted:

:words:

Instead of using explode and what not, look up fgetcsv and fputcsv.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


I helped him out with what he needed to do to access a DB and wrote the SQL query needed. I'm guessing everything worked out.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


omgwtfnoway posted:

I'm trying to use exec() in a php script to add and commit some files to SVN.

Install the SVN PECL extension then do it natively.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


OlSpazzy posted:

Also, the evals are necessary, without them unp_printTemplate('comments_list_commentbit') returns, for example:

eval is never necessary. Especially not when all you're doing is string replacement.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Finite posted:

I do it in a few places to do things like...
code:
$colour = $data['colour'];
$string = "The lazy $colour fox jumps over the I can't remember the rest of this."
But I decided that was a little stupid the other day and I'm trying to use sprintf instead.

You're supposed to use braces when you want the contents of a variable.

php:
<?
$string = "The quick {$data['colour']} fox jumps over the lazy dogs."
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


admiraldennis posted:

Thats the only way one should include variables within a double-quoted string, in my opinion. Either that or with a concatenation. It's borderline ambiguous otherwise and hurts readability.

And braces allows you to do crazy things like:
php:
<?
$variable = 'something';
$obj->a = 'variable';
echo ${$obj->a};
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Scarboy posted:

I disagree. If you're going to be outputting this, and it's data from the user then I would use sprintf and wrap the variable in htmlentities() (I don't write PHP much, is this the correct function to use?) to not allow html/js injection.

Ideally you'd have already sanitized it by the time you output it.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Zorilla posted:

Right, I was just trying to prevent users from embedding HTML into pages.

One of the things I've noticed is that the query string is already escaped for you (PHP 5.2.0) and attempting to use mysql_real_escape_string() will end up escaping your string twice.

I'm guessing my hosting has magic_quotes_gpc turned on. What's the proper way to handle things whether this is on or off? Detect whether magic_quotes_gpc is turned off and only escape the query string manually then?

If you haven't guessed, I'm a total beginner and suck at programming anyway.

For stuff that's to run on servers I can't control, I put this at the start of my script(s)
php:
<?
if (get_magic_quotes_gpc())
{
    if (!function_exists(stripslashes_array))
    {
        function stripslashes_array($array)
        {
            return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
        }
    }
    $_GET = stripslashes_array($_GET);
    $_POST = stripslashes_array($_POST);
    $_REQUEST = stripslashes_array($_REQUEST);
}
?>
so I don't have to worry about magic_quotes.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


You can have constructors run the parent's constructors or you can have your queries just use the last used connection.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Safety Shaun posted:

Any help or pointer towards this would be appreciated.

Try using mod_rewrite instead. Much easier and less server load.
http://isnoop.net/dev/mod_rewrite.php

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


You probably want to do a Natural Sort.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


awdio posted:

php:
<?php
natsort($files);
foreach (array_reverse($files) as $file)
echo "<img src=".$file.">";

?>


It's slow because you're reversing the array each time you loop.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


awdio posted:

Yeah I see that, but even if I put the array_reverse($files) after natsort, it won't permanently do anything because its not resorting the array. Also putting rsort after the natsort will do away with the natsort.

It doesn't seem too bad now, and maybe it was just my connection, but is there a better way I should do this?

Read the docs. array_reverse returns the reversed array. You'll need to do $files = array_reverse($files);.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


LastCaress posted:

As I said, my coding experience is null. I can run the server in php4 and the code has no problem, and when I put it in php5 there are problems, so obviously the problem is there.

The "problem" is that PHP5 has increased security and since the code is poorly written, it's getting tripped up.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Zorilla posted:

The variable you're checking for is $_POST["instance"] (or $_GET["instance"] depending on the form action) and its value is probably true if checked and false if not. I'm not 100% on this

Checkboxes will not appear in _GET/_POST if they are not checked. If they are checked, they will contain the contents of the value attribute. I don't know what they contain if there is no value attribute.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Possym posted:

It includes toc.php every time! I'm not experienced with sessions at all, did I do something to mess it up on accident?

Are you running session_start(); before you start messing with sessions or outputting anything?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Snozzberry Smoothie posted:

I need to generate XML with a PHP script, but I'm unsure of the best method from a performance perspective. Can anyone give me some advice or point me at a resource that I can read more on the topic?

EDIT: Is the most common way to just foreach and echo XML tags?

Use SimpleXML. It makes it so easy.

Zorilla posted:

Ok, I was trying using $_COOKIE in conjunction with $_SESSION without adjusting the default timeout value of "0" before giving up the first time, then only using $_SESSION when I tried setting cookie timeout the next time, so you can see why things didn't work. Looks like I've got a bit of modifications to do.


If the cookie data is nothing but a hash, how does it carry information about who is logged in between browser sessions? Or are you saying you store this in addition to a username and password cookie?

Sessions expire when the browser closes or after 24 minutes of inactivity. What you want are cookies. The cookie will store a unique ID/hash that points to an entry in your database with the session information.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Zorilla posted:

Ok, so this sounds like I actually have to create a MySQL table whose purpose is to store hashes that coordinate with remote users' cookies. Am I way off here?

Unless you want to store sensitive information in a cookie that's readable by anyone.
The table could consist of just two columns, a session id and the serialized session data. It's really up to you how you want to do it.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Grigori Rasputin posted:

Oh, another quick one that's more of a general *AMP/database question. Should I store timestamps in the format generated by PHP's mkdate() or MySQL's native date format?

Storing them as the databases' native date format has the advantage that you know it's a date because it says so and not because the program uses it as one.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Don't forget post_max_size as well as any database size limits.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Zorilla posted:

Shouldn't referrer handling be done though .htaccess?

Ideally.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Why not just use absolute paths?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


If it's static you can just do

php:
<?
readfile('footer.html');
?>
If it's dynamic then just do

php:
<?
include('footer.php');
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Atom posted:

If this is a serious issue for you, you can use memcache or (harder to write, more optimized) write php that generates php code based on the contents of the db. The risk of somebody rewriting the .html files isn't any more than the risk of someone rewriting the code that includes it in a properly secured system.

Or just use readfile which doesn't execute anything.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


I use PEAR:Mail

Adbot
ADBOT LOVES YOU

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Kaluza-Klein posted:

I would use empty() and a do-while loop, but I don't have any formal training at all.

Don't even have to do that much, array_search() should take care of it with one line.

Edit: They probably call it sloppy because you shouldn't be breaking out of a for loop. If you arn't sure you'll go until the end, you are supposed to use a while or something like that. Is that specific case it doesn't matter that much but other times it shows poor planning.

duz fucked around with this message at 03:38 on May 9, 2008

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