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
MrEnigma
Aug 30, 2004

Moo!

functional posted:

This isn't always working like it should. I have a special link on my pages that will take you to loggingout.php. It uses a token to verify that you actually clicked the link (and didn't have anyone IM you a fake logout link). Stripping away the logic what it really does is this, which should log you out and redirect you to the index:

php:
<?
LOGGINGOUT.PHP

setcookie('blargh','',time()-$tenyears,myCookiePath(),myCookieDomain());
header('Location: [url]http://website.com/theindexpage.php[/url]');
?>
Once every few times it takes me to the index page without erasing the cookie. I can tell because the index page does stuff that it would only do if you were logged in properly.

What's the deal?

caching probably, browser still you were cached, try adding some no cache headers and it should fix it.

Adbot
ADBOT LOVES YOU

gibbed
Apr 10, 2006

mcbuttbutt posted:

I'm trying to implement a simple URL hiding script that retrieves a zip file from the server filesystem. It's pretty basic and could surely be much better. Something like this...
php:
<?
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " .(string)(filesize($file_path)) );

$file = @fopen($file_path,"rb");
if ($file) {
  while(!feof($file)) {
    print(fread($file, 1024*8));
    flush();
  }
  @fclose($file);
}

?>
It works for smaller files, but larger files (>50 megs) are always incomplete. Any idea why this is happening? Thanks!
Why? WHY? :argh:

Don't do silly things like this. Use readfile().

Also, I don't know if that is only a snippet of the code, but please:
  • Verify the input filename is a valid one (that is, it's a file that you want allowed to be downloaded). If this is the complete script, hello exploits!
  • Don't depend on register_globals.

gibbed fucked around with this message at 06:49 on Jun 12, 2008

Finite
Jan 9, 2003

What do you mean mullets aren't fashionable?!?
I'm teaching myself how to use mySQLi and prepared statements. I'm having difficulty finding out how to insert a varied amount of rows in one statement, and Google isn't helping. I used to do something like this:

code:
INSERT INTO
x	(a, b)
VALUES	(1, 'one'),
	(2, 'two'),
	(3, 'three');
But with a prepared statement I don't see how to do this, as the code below (shamelessly stolen from PHPs docs) doesn't allow for more that one group of values:

php:
<?
$stmt = $mysqli->prepare("INSERT INTO test VALUES (?, ?)");
$stmt->bind_param('ds', $number, $text);

$number = 1;
$text = 'one';

$stmt->execute();
$stmt->close();
?>
As much as I could rewrite this for 2 or 3 rows, anything more than that just gets daft. How should I be going about this?

if wishes were knishes
Mar 5, 2006

Hi I'm Buddy-dot-gif
Preface: I'm using WordPress for blogging, an as-of-yet unknown forum system and hand-coding the main site. WP and Forums are on subdomains.

How would I go about having a unified user login system across those three unique databases?

My thought was to replicate user information between all three by way of a small bit of php at each sites user creation (checking for duplicates and sanitizing).

or

Something else?

Am I on the right track, is there a much easier way to do this?

Lamb-Blaster 4000
Sep 20, 2007

maybe create the variable in the session that each system uses. And have a unified registration form that calls both user creation functions from WP and the forum.

That could take a bit, because you'll have to tinker with the innards of the forum and WP to figure out how to do that.

if wishes were knishes
Mar 5, 2006

Hi I'm Buddy-dot-gif
I'm at work, so I can't really check out the source at the moment, but it looks as though http://www.wp-united.com/ will handle the unification work between WP and PHPbb.

Maybe I could use that and find a way to integate it into the main site.

I was trying to shy away from phpbb however. Unless they've changed a good amount of phpbb since I last used it (version 2.something).

Lamb-Blaster 4000
Sep 20, 2007

I hear tell that v2 is gonna be "really awesome" Personally I use https://www.simplemachines.org for all forums for clients or personal.

functional
Feb 12, 2008

MrEnigma posted:

caching probably, browser still you were cached, try adding some no cache headers and it should fix it.

Do you mean to add no-caching headers to the page that looks like you're still logged in? There's a lot of different caching stuff you can do. Can you elaborate? Maybe post some source to get me started?

mcbuttbutt
Jul 1, 2004

gibbed posted:

Why? WHY? :argh:

Don't do silly things like this. Use readfile().

Also, I don't know if that is only a snippet of the code, but please:
  • Verify the input filename is a valid one (that is, it's a file that you want allowed to be downloaded). If this is the complete script, hello exploits!
  • Don't depend on register_globals.

Easy now, that's just a snippet. And thanks, but readfile() didn't work either... still a partial download. I've increased the memory_limit variable in my php.ini to 80M and that did nothing as well. Stumped!

mcbuttbutt fucked around with this message at 20:40 on Jun 12, 2008

MrEnigma
Aug 30, 2004

Moo!

functional posted:

Do you mean to add no-caching headers to the page that looks like you're still logged in? There's a lot of different caching stuff you can do. Can you elaborate? Maybe post some source to get me started?

Yeah, to the page that looks like you're still logged in. It's your browser caching that page on you I'm guessing, there are a bunch of them you can find from a google search. But setting the header expiration in php, the meta expire stuff in html, and maybe there are a few more, but that should do it.

Stephen
Feb 6, 2004

Stoned

duz posted:

Frameworks They can make life easier
CakePHP, but after looking through the source code, I can't recommend it.

Just out of curiousity, what did you find with CakePHP that disgusts you so much? I've used it before, and there's a lot of things that piss me off about it, but there's a few things I really enjoy too. Is it a security risk or just poorly programmed?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Stephen posted:

Just out of curiousity, what did you find with CakePHP that disgusts you so much? I've used it before, and there's a lot of things that piss me off about it, but there's a few things I really enjoy too. Is it a security risk or just poorly programmed?

Stuff like the data sanitization, especially for databases, was effectively non-existent. By being PHP4 compatible it made the source more convoluted and therefore error prone then it had to be. This was a year or so ago so they hopefully have cleaned it up in the latest builds.
It was nice to use, and had some nice features, but for the project we were looking to use it for, the code just wasn't up to snuff.

gibbed
Apr 10, 2006

mcbuttbutt posted:

Easy now, that's just a snippet. And thanks, but readfile() didn't work either... still a partial download. I've increased the memory_limit variable in my php.ini to 80M and that did nothing as well. Stumped!
Is the file completely uploaded on the system you're downloading it from?

There is no reason why readfile() should fail unless the file is damaged somehow.

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

:dukedog:

I saw a thread about this a long time ago but I can't find it anymore so...

How do you do the authentication system like they have on AwfulYearbook.

If you don't know what I'm talking about, it's where a website checks to see if you have a specific line of text written onto a certain page.

I hope that made sense.

Zorilla
Mar 23, 2005

GOING APE SPIT

drcru posted:

How do you do the authentication system like they have on AwfulYearbook.

Probably include an activation token in the table of users. A random MD5 ought to do the job.

Once you have that, compare it to member.php for that particular user by using the DOMDocument object (or some other method for gathering information from HTML/XML) to scour each element's child text for that value.

Zorilla fucked around with this message at 06:32 on Jun 13, 2008

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

:dukedog:

Zorilla posted:

Probably include an activation token in the table of users. A random MD5 ought to do the job.

I was wondering more on how they did the actual checking of the website.

Zorilla
Mar 23, 2005

GOING APE SPIT

drcru posted:

I was wondering more on how they did the actual checking of the website.

Just realized that after I posted. Check the first reply again. DOMDocument is great if you're already familiar with manipulating web pages with DOM in Javascript.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

drcru posted:

I saw a thread about this a long time ago but I can't find it anymore so...

How do you do the authentication system like they have on AwfulYearbook.

If you don't know what I'm talking about, it's where a website checks to see if you have a specific line of text written onto a certain page.

I hope that made sense.

Use something shorter than an MD5 hash, as some of the profile fields don't let you put in 32 chars, causing people problems.

Use cURL to fetch the profile page. You will need to use cookies and your own bbuserid and bbpassword (find these by going through your cookies in firefox). Once you have the page loaded, just do a preg_match('/'.$code.'/', $page) and it will return true or false if $code is found in $page or not. Replace &userid=x to &username=x to search for a username.

php:
<?
   $ch = curl_init(EXTERNAL_PROFILE_USERID_URL.urlencode($id));
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_COOKIE, EXTERNAL_FORUM_COOKIE);
   $result = curl_exec($ch);
   curl_close($ch);
   return preg_match('/'.$code.'/', $result);
?>
I hope once genericadmin is done with the new search stuff we can get some sort of SA API to use, that would be awesome.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss
How do I get dreamweaver to fully preview my PHP files?

I followed the setting up process for HostMonster:
http://helpdesk.hostmonster.com/kb/index.php?mod_id=2&id=155&kb_rating=no

But when I make the PHP page, all that I see is:


So How do I make it so the actual, full page will show in the preview pane (it works on the actual web page though)

Only registered members can see post attachments!

Munky_Magic
Jul 3, 2004
I have just started work on a project which I hope will increase my knowledge of PHP. For reference, I have a lot of programming experience in other languages (I'm a CS major), but only just started really getting into PHP (took a really good web development class at Uni this quarter).

Basically I am working on a CMS, and was wondering what the best way to store things like website parameters is? By website parameters I mean, for example, say that the admin doesn't want a certain section to be visible (eg. the top menu). I want to make it so that he/she can just check a box and the content will not show up. However, I want to store the preferences somewhere, and a SQL DB (which I will be using a lot for the backend of the site) doesn't seem appropriate. In fact, it's the type of thing where you would use an .ini file to save an applications preferences, for a normal application. But obviously since it's on the web, I want it to be secure.

Any suggestions?

noonches
Dec 5, 2005

It represents my lifestyle and stratus as a street savy irreverent youth, who lives large, and yet hungers for the next level in life.

cannibustacap posted:

How do I get dreamweaver to fully preview my PHP files?

Wouldn't it be easier to set up a testing server on your localhost?

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

noonches posted:

Wouldn't it be easier to set up a testing server on your localhost?

Nah I want to use the servers of HostMonster so that way I know what I am previewing is what will be shown online.

Do you know how to set it up?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

cannibustacap posted:

Nah I want to use the servers of HostMonster so that way I know what I am previewing is what will be shown online.

Do you know how to set it up?

Use Editplus and edit it directly on the server

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

fletcher posted:

Use Editplus and edit it directly on the server

I like the preview feature of dreamweaver.

I know there is a way to do it through dreamweaver, does anyone know how?

Anveo
Mar 23, 2002

cannibustacap posted:

How do I get dreamweaver to fully preview my PHP files?

Dreamweaver is not a PHP interpreter. If you want to view a page with the PHP executed, you need to view it through a browser. Dreamweaver will not show any more than that.

Zorilla
Mar 23, 2005

GOING APE SPIT

Munky_Magic posted:

Basically I am working on a CMS, and was wondering what the best way to store things like website parameters is?

If you don't mind the settings being lost if the user clears their browser cache, use cookies. Otherwise, use the MySQL database. I would use cookies for petty things like which menus get shown on each page.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

Anveo posted:

Dreamweaver is not a PHP interpreter. If you want to view a page with the PHP executed, you need to view it through a browser. Dreamweaver will not show any more than that.

Then why would they offer a PHP features?

MrEnigma
Aug 30, 2004

Moo!

cannibustacap posted:

Then why would they offer a PHP features?

I think the feature is that it can do code foldering and syntax highlighting for PHP. If you think there is more, hit up your manual.

nbv4
Aug 21, 2002

by Duchess Gummybuns
I want to add a feature on my site that outputs that data into a PDF file, so when the user print, it looks consistent and paged correctly. Anyone know of a good library or something that will do this?

MrEnigma
Aug 30, 2004

Moo!

nbv4 posted:

I want to add a feature on my site that outputs that data into a PDF file, so when the user print, it looks consistent and paged correctly. Anyone know of a good library or something that will do this?

PDFLib is the one you want, it's not easy at all to do things though...well anything besides just a block of text.

http://pecl.php.net/package/pdflib

It's free for non-commercial use (or at least there is a free alternative for non-commercial use).

Edit: Also check out http://us3.php.net/manual/en/book.pdf.php (and the comments).

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe
I just moved my stuff over to new hosting and I came across and issue with some of my previously functional code.

I've been using time() in one of my scripts to generate ids for items placed into a database. Then later when they are displayed I used the following to get the month and the day:

$day = date("d", $id);
$month = date("M", $id);

I get anything from February 23 1997 to October 02 2019

What's wrong here?

Edit: It appears to be working now, I guess because it was just setup the dates were messed up somehow?

clockwork automaton fucked around with this message at 20:26 on Jun 15, 2008

bt_escm
Jan 10, 2001

MrEnigma posted:

PDFLib is the one you want, it's not easy at all to do things though...well anything besides just a block of text.

http://pecl.php.net/package/pdflib

It's free for non-commercial use (or at least there is a free alternative for non-commercial use).

Edit: Also check out http://us3.php.net/manual/en/book.pdf.php (and the comments).

take a look at http://www.digitaljunkies.ca/dompdf/

It will convert html + css2.1 to a pdf document and is a crap load easier than directly using PDFLib.

MrEnigma
Aug 30, 2004

Moo!

bt_escm posted:

take a look at http://www.digitaljunkies.ca/dompdf/

It will convert html + css2.1 to a pdf document and is a crap load easier than directly using PDFLib.

That's awesome, although I don't see a usage license on there...but apparently it's "free" for all.

Tap
Apr 12, 2003

Note to self: Do not shove foreign objects in mouth.
I'm writing a script to validate URLs, and one part of the script validation is a check to see if the document exists (i.e. seeing if there's a response). Is there a faster function to use than get_headers? For me, get_headers is extremely slow and I'm going to be validating thousands of URLs.

iamstinky
Feb 4, 2004

This is not as easy as it looks.
I am trying to implement a reversible sort a 2d array by an arbitrary key in the second level function.

So I used an insertion sort (or it's based on an insertion sort rather):

php:
<?
function sort_list($array,$index="person_id",$direction) {
//$array[0] = "person_id"=> 1223523,"class"=>"Shakespeare","type"=>"Final",etc...
$max = count($array);

  if ( $direction == "asc" ) {
 
    for($j=1; $j < $max; $j++){
      $temp = $array[$j];
      $i = $j;
    
      while(!empty($array[$i-1]) && ($i >= 0) && ($array[$i-1][$index] > $temp[$index])){
         $array[$i] = $array[$i-1];
         $i--;
      }
      
      $array[$i] = $temp;
      
    }

  } else if ( $direction == "desc" ) {
    
    for($j=1; $j < $max; $j++){
      $temp = $array[$j];
      $i = $j;
    
      while( !empty($array[$i-1]) && ($i >= 0) && ($array[$i-1][$index] < $temp[$index])){
         $array[$i] = $array[$i-1];
         $i--;
      }
      
      $array[$i] = $temp;
      
    }
  }  
  
  return $array;
}
?>
Is there a better way to do this if I need to be able to sort on class or person_id etc? $array size won't ever be more than a couple thousand elements.

bt_escm
Jan 10, 2001

iamstinky posted:

I am trying to implement a reversible sort a 2d array by an arbitrary key in the second level function.

So I used an insertion sort (or it's based on an insertion sort rather):


Is there a better way to do this if I need to be able to sort on class or person_id etc? $array size won't ever be more than a couple thousand elements.

I have to question where you're getting the data from that you would need to sort it in php?

minato
Jun 7, 2004

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

iamstinky posted:

I am trying to implement a reversible sort a 2d array by an arbitrary key in the second level function.

Is there a better way to do this if I need to be able to sort on class or person_id etc? $array size won't ever be more than a couple thousand elements.
You mean like this?
php:
<?
    /**
     * sortMultiArray
     *
     * Input: a 2-dimensional array, where the all the 2nd-dimension elements have a common field name (e.g. 'name')
     * It will sort the array based on a specific field name.
     * E.g. if the array contains many arrays like ('name'=>..., 'address'=>...)
     * then calling sortMultiArray($arr, 'name') will return the array sorted by name.
     * The key of the main array is not retained.
     *
     * @param array $arr - Array to sort
     * @param string $field - field name to sort on
     * @param boolean $reverse - Reverse sort order. false (default) - ascending, true - descending
     * @param string $function - name of the sorting function. (strnatcasecmp is default). To pass in a static class
     *      method (a non-static class method is not permitted), use the form 'StaticClass::methodname'.
     * @return array - the sorted array.
     */
    function sortMultiArray($arr, $field, $reverse=false, $function=null) {
        $rev = '';
        if($reverse) {
            $rev = '-';
        }
        if(!$function) {
            $function = 'strnatcasecmp';
        }
        $function_def = 'return '.$rev.$function.'($a[\''.$field.'\'],$b[\''.$field.'\']);';
        $function = create_function('&$a,&$b',$function_def);
        usort($arr, $function);
        return $arr;
    }
?>

dancavallaro
Sep 10, 2006
My title sucks
Can someone recommend a good library/script for generating captchas? I'm using a comment module for Joomla that I like, but has a really simple captcha generator and I'm starting to get a lot of spam. It would be really easy to just replace the captcha generation script, so that's what I'm gonna do. Any recommendations?

willjo3
Mar 5, 2004
superfluous asshole
I'm having a problem using the php mail() function. I've been googling and experimenting for two days trying to figure it out to no avail.

Basically, I'm unable to send an email using the mail() function. The interesting part is that our company website (which we bought from a third party) uses the function and it works just fine. To make matters even more fun, my code works on another webserver. I've checked the php.ini sections on mail, and there dont seem to be any relevant differences.

Here is the relevant part of the company website that works:
code:
while(list($SID, $Email) = mysql_fetch_array($sql2)) {
				$unsubscribe_link = "<a href='$siteurl/obituaries.php?op=unsubscribe&Email=$Email'>here</a>";
				if(ereg("\[Unsubscribe_Link\]", $mailbody)) $mailbody = ereg_replace("\[Unsubscribe_Link\]", $unsubscribe_link, $mailbody);
					if((@mail($Email, $subject, $mailbody, $mailheader))) {
						//echo "<font color=green>Emailed to $Email</font><br>";
					} else {
						//echo "<font color=red>Email failed to $Email</font><br>";
					}
				}
			}
And here is the code that won't work:
code:
<?php

$to = "myemailaddress";
$subject = "hello this is a test";
$message = "this is a test email";
$from = "myemailaddress";
$headers = "From: $from";
@mail($to,$subject,$message,$headers);
echo "Mail Sent.";

?>
Any suggestions?

Adbot
ADBOT LOVES YOU

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


dancavallaro posted:

Can someone recommend a good library/script for generating captchas? I'm using a comment module for Joomla that I like, but has a really simple captcha generator and I'm starting to get a lot of spam. It would be really easy to just replace the captcha generation script, so that's what I'm gonna do. Any recommendations?

Anything you roll on your own will likely be easy to defeat, use reCAPTCHA instead. They provide sample code and libraries to help integrate it.

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