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
bt_escm
Jan 10, 2001

Zorilla posted:

I've got a client we're doing a web page redesign for and it turns out he would like to be able to edit basically anything that might need changing on the site on his own. Normally, I would just set up some system like Website Baker or CMS Made Simple, but this site in particular has quite a bit of markup I don't want the client to disturb. Plus, the site has some dynamic content with a backend I wrote a month or so ago to edit its contents.

I'm pretty sure cmsms has a user management system in it that you can use to prevent users from editing certain pages and content blocks. Actually I think most content management systems have that now. You could take a look at http://www.opensourcecms.com/ and look over some of the more popular ones.

Adbot
ADBOT LOVES YOU

bt_escm
Jan 10, 2001

the talent deficit posted:

Is this the right place for Zend questions? I hope so.

I've got an IndexController with four actions. indexAction works fine, the other three give me 404 errors. (I have views setup for all four). Is this because mod_rewrite isn't setup properly? Or my .htaccess is badly written?

It's one of two things
1) mod_rewrite is not enabled
2) your htaccess file is messed up

If it was setup correctly then all requests should be going to the index.php file in the webroot. The framework handles all requests form there.

admiraldennis
Jul 22, 2003

I am the stone that builder refused
I am the visual
The inspiration
That made lady sing the blues

genericadmin posted:

Or, if you want to be flexible...

preg_match_all("#<br(?: /)>#", $string, $m)

Don't you mean:

preg_match_all("#<br(?: /)?>#", $string, $m)

edit: can't quote your &lt;

admiraldennis fucked around with this message at 12:08 on Apr 9, 2008

Jewish Bear
Jul 28, 2007

admiraldennis posted:

Don't you mean:

preg_match_all("#<br(?: /)?>#", $string, $m)

edit: can't quote your &lt;

correct :eng101:

onionradish
Jul 6, 2006

That's spicy.

Zorilla posted:

markup I don't want the client to disturb

bt_escm posted:

I'm pretty sure cmsms has a user management system in it that you can use to prevent users from editing certain pages and content blocks.
CMSMS does have content access restrictions. You can lock them entirely out of page templates/css, and permit editing only on certain pages/content blocks by individual user.

Further, you can limit them through the WYSIWYG editor. Turn off the buttons for all but important formatting, or create classes that show up as styles for them to use when they want something formatted differently so it's consistent and controlled through CSS. For even more control, you can limit the types of HTML tags and attributes permitted in the content: if they're not on the approved list, they're filtered out.

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

:dukedog:

e: php4

I've got a $variable filled with a large amount of text separated by new lines (\n).

I want to split the $variable into two giant chunks after a certain amount of lines, is that possible?

I thought about using split() but that would just make a new array value for every sentence and that might not be an effective way of doing it.

Thanks

bt_escm
Jan 10, 2001

drcru posted:

e: php4

I've got a $variable filled with a large amount of text separated by new lines (\n).

I want to split the $variable into two giant chunks after a certain amount of lines, is that possible?

I thought about using split() but that would just make a new array value for every sentence and that might not be an effective way of doing it.

Thanks

You could use strpos to find the nth line break and then substr to grab the first and then second half of the string. I'm sure there's a way to do this with regular expressions too.

x1o
Aug 5, 2005

My focus is UNPARALLELED!
I'm writing another small PHP script to amuse myself, and this time I'd like to move away from having SQL sitting in my code. Are there any articles on how to go about this? I'm not looking for a full blown framework as that's just overkill for this but a simple DB class or something would be nice.

Frameworks are a few projects down the track...

bt_escm
Jan 10, 2001

TheHeadSage posted:

I'm writing another small PHP script to amuse myself, and this time I'd like to move away from having SQL sitting in my code. Are there any articles on how to go about this? I'm not looking for a full blown framework as that's just overkill for this but a simple DB class or something would be nice.

Frameworks are a few projects down the track...

Here's an ORM http://propel.phpdb.org/trac/
And here's a tutorial http://codepoets.co.uk/propel_php5_framework_quickstart_howto_guide

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

bt_escm posted:

Here's an ORM http://propel.phpdb.org/trac/

I don't really understand what that helps with. Isn't it more beneficial to just learn/practice SQL?

x1o
Aug 5, 2005

My focus is UNPARALLELED!

fletcher posted:

I don't really understand what that helps with. Isn't it more beneficial to just learn/practice SQL?

I already know SQL. I'd like to move away from having SQL statements littered all throughout my projects where it's hard coded in. Which leads to maintaining multiple versions because my home system runs MySQL and my sever runs PostgreSQL and for added fun a friend uses my scripts and he's got Oracle.

So, it's getting to the point where I need database abstraction.

I'll have a look at this ORM stuff.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
If you don't like ORM then PEAR::MDB2 might be worth having a look at.

Actually an ORM layer is far better suited to your needs.

Inquisitus fucked around with this message at 09:51 on Apr 10, 2008

bt_escm
Jan 10, 2001

fletcher posted:

I don't really understand what that helps with. Isn't it more beneficial to just learn/practice SQL?

They're not mutually exclusive. This explains it way better than I could http://en.wikipedia.org/wiki/Object-relational_mapping

bt_escm
Jan 10, 2001

TheHeadSage posted:

I already know SQL. I'd like to move away from having SQL statements littered all throughout my projects where it's hard coded in. Which leads to maintaining multiple versions because my home system runs MySQL and my sever runs PostgreSQL and for added fun a friend uses my scripts and he's got Oracle.

So, it's getting to the point where I need database abstraction.

I'll have a look at this ORM stuff.

What do you mean by hard coded? Technically if you have sql anywhere in your code it could be considered hard coded since sql is frequently tied to the specific database server you are using. If you just want to be able to execute sql statements using the same set of commands across multiple script regardless of the database then pear's mdb2 would be better suited for that.

If you want code to dynamically know the structure of your tables and handle all of the basic manipulations for you then propel would be ideal for that.

stack
Nov 28, 2000
Is there a way to catch 'Ctrl-C' in a PHP CLI script running in Windows? PCNTL isn't available for Windows so I can't easily use it to catch the signal for it. Google only turns up one post on php.net where a guy made a custom build of PHP to include PCTNL and that won't work for my situation.

Sewer Adventure
Aug 25, 2004

Is Propel better than Doctrine? (I'm currently shopping around for ORMs)

Sewer Adventure
Aug 25, 2004

fletcher posted:

I don't really understand what that helps with. Isn't it more beneficial to just learn/practice SQL?

If you use raw SQL then you will have to escape strings every time you input them and then remember to stripslashes every time you output them, you will have to build big rear end queries by concating strings and it eventually gets very ugly. If you use an ORM you can treat individual records as instances of an object and it's very pretty, all the escaping bullshit is managed for you (you will be much better protected from injection), and you can change the database schema with a migration and have all your code handle the change automatically (without having to do a big search replace of your entire codebase).

, etc.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Sewer Adventure posted:

If you use raw SQL then you will have to escape strings every time you input them and then remember to stripslashes every time you output them, you will have to build big rear end queries by concating strings and it eventually gets very ugly.

That's not true at all. I used PDO and didn't use a single string concatenation for SQL or have to worry about escaping ANY input throughout my entire application. Don't use addslashes, stripslashes, magic quotes, concatenation, or any of that other crap, that's the wrong way to do it.

gibbed
Apr 10, 2006

stack posted:

Is there a way to catch 'Ctrl-C' in a PHP CLI script running in Windows? PCNTL isn't available for Windows so I can't easily use it to catch the signal for it. Google only turns up one post on php.net where a guy made a custom build of PHP to include PCTNL and that won't work for my situation.
Aside from making another extension like PCNTL, no.

Sewer Adventure
Aug 25, 2004

fletcher posted:

That's not true at all. I used PDO and didn't use a single string concatenation for SQL or have to worry about escaping ANY input throughout my entire application. Don't use addslashes, stripslashes, magic quotes, concatenation, or any of that other crap, that's the wrong way to do it.

Sewer Adventure posted:

If you use raw SQL

Sewer Adventure
Aug 25, 2004
Either way, not using an ORM is just making more work for yourself.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Sewer Adventure posted:

Either way, not using an ORM is just making more work for yourself.

I have tried plenty of ORM's, they often turn out to be more work. Its often much much easier to just use an SQL join instead of setting up a bunch of objects to do a join. It also makes it a lot easier to optimize SQL statements if they are staring right at you instead of trying to figure out what SQL statements the ORM is making up and how to make them run faster.

A good bridge is something like PDO or Zend_DB with prepared statements. It is pretty close to database generic (although swapping out drivers would probably require a little bit of work) and will let you write SQL without having to escape everything. Zend_DB includes a lot of handy methods that help with simple queries.

If the app is well written, and you have some wrappers so that your SQL ends up all in a clearly defined set of classes, then not using an ORM can be a very robust maintainable solution.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I've been playing around with this s3 script and can't seem to figure out how to list more than 1,000 objects in a bucket.

Amazon mentions this here as the expected behavior and what you need to do.

In s3.php:
php:
<?
public function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null)
?>
So it looks like I should be able to, I just don't know what to pass into $marker. Any ideas?

edit: this seems to work

php:
<?
    $pictures = array();
    $done = false;
    $marker = null;
    while (!$done) {
        $set = $s3->getBucket(S3_BUCKET_PICTURES, null, $marker, null);
        if (sizeof($set) > 0) {
            $pictures = array_merge($pictures, $set);
            $marker = end(array_keys($pictures));
        } else
            $done = true;
    }
?>

fletcher fucked around with this message at 23:06 on Apr 12, 2008

Jahuran
Jul 9, 2001
Perhaps you guys can give me some advice on the following system I want to build. I'm not really looking for coding advice just your thoughts on what approach to take. I'm building everything on a PHP5 & MySQL5 platform. So sprocs are an option and I have experience with them.

I want to make a small community website where each individual user can can have their own personal page. The users can edit their own personal page to their liking with some javascript colorpicking scripts.

I figured I could do it in a few ways:
  • 1.Store a file on the filesystem per user with their colorpicks in it and load these into a session whenever they return to the website.
  • 2.Store a file on the filesystem per user and load it everytime a user loads up a page.
  • 3.Store the colorsettings in a database table and load them into a session when the user returns to the website.
  • 4.Store the colorsettings in a database table and load them everytime a user loads up a page.

Options 1 and 2 create a heavier load in terms of disk i/o.
Options 3 and 4 create more constant database queries (disk i/o and processing)

Options 3 and 4 seem the most viable to me. I'm expecting around 250 concurrent users daily during normal business hours. When people navigate to eachothers pages the colorpicks of the page they are visiting need to be loaded not their own!

So what method would you guys pick? Is there another way of going about this?
Recommendations are very welcome!

Sewer Adventure
Aug 25, 2004

Jahuran posted:

flat files

Use a database, we just had this nonsense on the last page. Also use something like memcached to speed up the database stuff.

Standish
May 21, 2001

Jahuran posted:

I figured I could do it in a few ways:
  • 1.Store a file on the filesystem per user with their colorpicks in it and load these into a session whenever they return to the website.
  • 2.Store a file on the filesystem per user and load it everytime a user loads up a page.
  • 3.Store the colorsettings in a database table and load them into a session when the user returns to the website.
  • 4.Store the colorsettings in a database table and load them everytime a user loads up a page.

Options 1 and 2 create a heavier load in terms of disk i/o.
Options 3 and 4 create more constant database queries (disk i/o and processing)

Options 3 and 4 seem the most viable to me. I'm expecting around 250 concurrent users daily during normal business hours. When people navigate to eachothers pages the colorpicks of the page they are visiting need to be loaded not their own!

So what method would you guys pick? Is there another way of going about this?
Recommendations are very welcome!
PHP by default stores session data in a file on disk so 1, 2 and 3 are actually the same thing from a performance point of view, just with different interfaces. Use a database like the guy said, it's going to be orders of magnitude faster to query an indexed database table containing a million user records than to open a file in a directory containing a million user settings files.

Standish fucked around with this message at 11:56 on Apr 13, 2008

Jahuran
Jul 9, 2001

Standish posted:

Stuff

Sewer Adventure posted:

Stuff

Thanks guys

A Flaming Chicken
Feb 4, 2007

Sewer Adventure posted:

Either way, not using an ORM is just making more work for yourself.

How do these ORMs work on master-slave setups? We need to get a new version of our site up quick, and ORMs enable us to do it.

nbv4
Aug 21, 2002

by Duchess Gummybuns
Does anyone here have have experience using jpGraph? I'm having trouble with a graph of mine. It seems whenever you try to display the values of an accumulated bar graph rotated at 90 degrees, the labels get printed a few pixels higher than they are supposed to be.

here is an example: http://xs226.xs.to/xs226/08156/list_graph473.png

Here is the code for that particular graph:

code:
// Create a bar pot
	$bplot1 = new BarPlot($data1);
	$bplot1->SetFillColor($bar_color);
	$bplot1->SetValuePos("center");
	$bplot1->value-> Show();
	$bplot1->SetLegend($time_title2);
	
	###############################################
	
	// Create another bar pot
	$bplot2 = new BarPlot($data2);
	$bplot2->SetFillColor($bar_color2);
	$bplot2->SetValuePos("center");
	$bplot2->value-> Show();
	$bplot2->SetLegend($time_title1);
	
	###############################################
	
	$bplot  = new AccBarPlot (array($bplot1 ,$bplot2));
	$bplot->SetAbsWidth(10);
	$bplot->value-> Show();
        $bplot->value->SetMargin(10); 
		
###############################################################

$graph = new Graph($width,$height,'auto');
$graph->SetScale("textlin", 0, $maximum + (0.08 * $maximum));
$graph->yaxis->HideTicks(true,true);
$graph->xaxis->HideTicks(true,true);
$graph->xgrid->SetWeight(0); 
$graph->ygrid->SetWeight(0);
$graph->yaxis->Hide();

$top = 30;
$bottom = 30;
$left = 180;
$right = 30;

$graph->Set90AndMargin($left,$right,$top,$bottom);
$graph->SetShadow();
$graph->xaxis->SetTickLabels($title);
$graph->xaxis->SetLabelAlign('right','center','right');
$graph->yaxis->SetLabelAlign('center','bottom');
$graph->title->Set("$time_title by $type_title");
$graph->Add($bplot);
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->SetPos(0.7,0.90,'center','center'); 
$graph->Stroke();
If I comment out the line that rotates the graph 90 degrees, it displays fine. Anyone know if theres a way to fix this, or is it just a bug?

Safety Shaun
Oct 20, 2004
the INTERNET!!!1
I'm looking to stop image leeching on my server by using a fancypants URL hiding script.

I have images on a few different image servers and I am looking to hide the URL of them by doing something like the SA's attachment.php image output script where showimage.php outputs the image data and showimage.php checks whether it's pulling the file from one of my scripts, if it's true - it outputs the image data.

[index.php]

<img src="showimage.php?server=2&filename=sweet.jpg">

[/index.php]


Any help or pointer towards this would be appreciated.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Safety Shaun posted:

I'm looking to stop image leeching on my server by using a fancypants URL hiding script.

You will need to know how to set the header of a document to let it know you will be outputting image data. You will need to pass something into the script, maybe a md5sum of a salted filename, like:

http://domain.com?script.php?id=9e107d9d372bb6826bd81d3542a419d6

script.php gets that id input using $_GET['id']. Using that, do whatever you need to do in the script to get back to a filename. Set the header and output the appropriate file.

fletcher fucked around with this message at 04:25 on Apr 14, 2008

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

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender

Safety Shaun posted:

I'm looking to stop image leeching on my server by using a fancypants URL hiding script.
You have a couple of solutions at hand.

The easiest is just to check the Referrer header with mod_rewrite and redirect the user to a 404 page if it's not your site. However some browsers/proxy servers don't send the Referrer header 100% of the time so its presence or absence alone is not enough - the best and easiest thing to do here is to only let the image be displayed if the Referrer header is present and points at your site, OR isn't present at all. I believe this is what Waffleimages does.

A more accurate solution would be to set a cookie when someone visits your site, and then check for the presence of that cookie when serving the images. Anyone leeching won't have the cookie and thus won't get the image. This can probably be done with mod_rewrite (but I don't know for sure). If not then use a PHP script to check for it. If the cookie is present, then just do:
php:
<?
header('Content-type: image/jpeg');
$path_to_file = $_GET['file_name'];
... //validate and sanitize $path_to_file here
http_send_file($path_to_file);
exit;
?>

Safety Shaun
Oct 20, 2004
the INTERNET!!!1
How do I get the data of say, http://55.55.55.55/image.jpg or http://myimageserver.com/image.jpg into $imagedata?

php:
<?php
ob_start();
$imagedata how_do_i_get_data("http://blah.com/image.jpg");
$length strlen($imagedata);
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$length);
header('Content-Type: image/jpeg');
print($imagedata);
ob_end_flush();
?>

Standish
May 21, 2001

Safety Shaun posted:

How do I get the data of say, http://55.55.55.55/image.jpg or http://myimageserver.com/image.jpg into $imagedata?
Use the cURL http library:
php:
<?php

$ch curl_init("http://myimageserver.com/image.jpg");

curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
$imagedata curl_exec($ch);
curl_close($ch);
?>

Jewish Bear
Jul 28, 2007

Standish posted:

Use the cURL http library:
php:
<?php

$ch curl_init("http://myimageserver.com/image.jpg");

curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
$imagedata curl_exec($ch);
curl_close($ch);
?>

if cURL isn't enabled, use file_get_contents:
php:
<?php
$file file_get_contents'http://path/.jpg' );
header'Content-Type: image/jpeg' ); 
echo $file;
?>

Safety Shaun
Oct 20, 2004
the INTERNET!!!1

LOL AND OATES posted:

if cURL isn't enabled, use file_get_contents:
php:
<?php
$file file_get_contents'http://path/.jpg' );
header'Content-Type: image/jpeg' ); 
echo $file;
?>


Thank you. For my purposes and level of PHP, this works perfect.

I am now streaming images from my site from multiple servers seamlessly, whilst hiding the IP of the servers.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

LOL AND OATES posted:

if cURL isn't enabled, use file_get_contents:
php:
<?php
$file file_get_contents'http://path/.jpg' );
header'Content-Type: image/jpeg' ); 
echo $file;
?>


Or just readfile it:

code:
<?php
header("Content-Type: image/jpeg\r\n"); 
readfile('http://path/.jpg');
?>

gibbed
Apr 10, 2006

Inquisitus posted:

Or just readfile it:

code:
<?php
header("Content-Type: image/jpeg\r\n"); 
readfile('http://path/.jpg');
?>
Drop the trailing ?> too, there is no need for it in this script.

code:
<?php
header('Content-Type: image/jpeg');
readfile('http://path/.jpg');
Edit: wait why the hell did you put a \r\n in the header() call?

Adbot
ADBOT LOVES YOU

Zorilla
Mar 23, 2005

GOING APE SPIT

gibbed posted:

Edit: wait why the hell did you put a \r\n in the header() call?

Looks like a force of habit from Perl

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