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
Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
Oh, I'm not worried about that, I've got a pretty solid idea of what my site needs to do, and every component that the framework uses is optional. The framework merely gives me the ability to do things quickly that I would have to code otherwise.


Anywho, is there a function to encode an array to a string/binary thing (like json_encode, but native/really fast) - I want to save an array to a database, but encoded.

Cheers.

Rat Supremacy fucked around with this message at 19:27 on Aug 13, 2009

Adbot
ADBOT LOVES YOU

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I like that, a lot. I'm trying to think of how I'd convert my current data records to that kind of system and am coming up short, though. Basically, it looks like any datapoint that you have that can be manipulated at all - even just converting between decimal and lb/oz - is a separate object. Thus, making each object only handle one kind of thing. Which I suppose is the essence of single responsibility.

All the database stuff is in shipments? So when you want to change an address, the database code is in Shipments but manipulates the Address object?

jasonbar
Apr 30, 2005
Apr 29, 2005

haywire posted:

Oh, I'm not worried about that, I've got a pretty solid idea of what my site needs to do, and every component that the framework uses is optional. The framework merely gives me the ability to do things quickly that I would have to code otherwise.


Anywho, is there a function to encode an array to a string/binary thing (like json_encode, but native) - I want to save an array to a database, but encoded.

Cheers.

http://www.php.net/serialize

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums

Ah thanks, I knew this existed, I just couldn't remember the name.

How does it rate performance wise with json_encode?

Edit, turns out json_encode is faster. However, it lacks features that serialize gives you. I'll try and see if I can make do with json_encode, but move to serialize if it doesn't work out.

Rat Supremacy fucked around with this message at 19:33 on Aug 13, 2009

Begby
Apr 7, 2005

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

Golbez posted:

I like that, a lot. I'm trying to think of how I'd convert my current data records to that kind of system and am coming up short, though. Basically, it looks like any datapoint that you have that can be manipulated at all - even just converting between decimal and lb/oz - is a separate object. Thus, making each object only handle one kind of thing. Which I suppose is the essence of single responsibility.

All the database stuff is in shipments? So when you want to change an address, the database code is in Shipments but manipulates the Address object?

Not everthing has to be an object. For instance a shipment has a plain old ID field, some reference fields which are just plain old strings, etc. You only need to use an object where it makes sense.

Basically the Weight would work like this in PHP (there is a lot more functionality in C#)
code:
$weight = new Weight(4.5);
echo $weight->Pounds();  // displays 4
echo $weight->Ounces(); // displays 8
echo $weight->AsDouble(); // displays 4.5
echo $weight; // Displays "4lb 8oz" due to overloaded __ToString()
Yeah, its all in shipments. In this case all the code I write that uses shipments acts as if a shipment is a single entity. If I wanted to update an address, I would do something like this (C#)

code:
MyShipment.To.Address = "Some Address";

ShipmentService shipments = new ShipmentService(connString);
shipments.Update(MyShipment);
Or something like that, then the shipments service would update the address record and anything else that changed. For what I am dealing with the shipments never change except that they get voided. But that is how I would set it up if I had to modify a shipment. In other cases you might want to make it so you can update addresses individually, it all depends on your needs.

Begby fucked around with this message at 20:01 on Aug 13, 2009

Spaceguns
Aug 28, 2007

KuruMonkey posted:

If it works in one browser and not another then the issue has to be in the rendered html of the form. It can't be in your form handling/emailing code as thats not run in the browser.

Thanks man. Turns out I just needed to walk away for a bit.

Got home, noticed an errant /p after the form, removed it, and somehow it works. Not sure if that did it or something just "clicked" during a copy/past into a test page.

KuruMonkey
Jul 23, 2004
Many of my most intractable coding troubles have resolved themselves while I waited for the kettle to boil :)

LP0 ON FIRE
Jan 25, 2006

beep boop
Why can't I get this simple script to work? All I want to do is take an image from a URL and store it to a folder on my server. The folder has the correct permissions and I've tried a manual image uploader to that same folder and it works.

I've also wrote $fp as open('http://www.majoroutput.com/sonicCircus/images/', 'w'); (without the filename).

php:
<?php
$contents 'http://www.majoroutput.com/sonicCircus/test.jpg';

echo "<img src='".$contents."'>";

$fp fopen('http://www.majoroutput.com/sonicCircus/images/test.jpg''w');
fwrite($fp$contents);
fclose($fp);
?>
edit: I've also tried $contents = file_get_contents('http://www.majoroutput.com/sonicCircus/test.jpg');

LP0 ON FIRE fucked around with this message at 23:26 on Aug 14, 2009

Mr Viper
Jun 21, 2005

Derezzed...
So I finally realized what was causing so many problems for me with my site: The MySQL databases were all set to version 4.0, not 5.0. Gah.

Question is, does the upgrade to 5.0 really change anything? Is it worth the hassle of figuring out what exactly is different and what isn't? I may have to go over the ENTIRE SITE and check EVERY mysql line to make sure it works in 5.0, and I really don't want to have to do that id I don't need to.

waffle iron
Jan 16, 2004

awdio posted:

Why can't I get this simple script to work? All I want to do is take an image from a URL and store it to a folder on my server. The folder has the correct permissions and I've tried a manual image uploader to that same folder and it works.

I've also wrote $fp as open('http://www.majoroutput.com/sonicCircus/images/', 'w'); (without the filename).

php:
<?php
$contents 'http://www.majoroutput.com/sonicCircus/test.jpg';

echo "<img src='".$contents."'>";

$fp fopen('http://www.majoroutput.com/sonicCircus/images/test.jpg''w');
fwrite($fp$contents);
fclose($fp);
?>
edit: I've also tried $contents = file_get_contents('http://www.majoroutput.com/sonicCircus/test.jpg');
Are you trying to use the http file io wrappers to write? If all these files are on your webhost, why don't you just use copy? It also looks like you're passing the wrong arguments to fwrite.

http://php.net/fwrite

LP0 ON FIRE
Jan 25, 2006

beep boop

waffle iron posted:

Are you trying to use the http file io wrappers to write? If all these files are on your webhost, why don't you just use copy? It also looks like you're passing the wrong arguments to fwrite.

http://php.net/fwrite

I'm just using files on the same host as a test. I've tried off the site too.

I've seen multiple people mention using fwrite to get offsite images and save them to your host, including:

http://www.webmasterworld.com/forum88/374.htm

jasonbar
Apr 30, 2005
Apr 29, 2005

awdio posted:

I'm just using files on the same host as a test. I've tried off the site too.

I've seen multiple people mention using fwrite to get offsite images and save them to your host, including:

http://www.webmasterworld.com/forum88/374.htm

Do your fopen, etc... functions have access to the URL wrappers?

http://us.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Additionally, $fp = fopen('path/to/local/file/not/remote/image.jpg', 'w');

You would want something like:

php:
<?
$contents = file_get_contents($the_url);
$fp = fopen('/my/images/dir/filename.file_ext', 'w');
fwrite($fp, $contents);
fclose($fp);
?>
In your original code you are trying to write the contents (which was just a string url) to the remote image file.

Edit: nvm, I don't know if the comment I had here would work, and if it did work it would be a terrible idea anyway.

jasonbar fucked around with this message at 04:59 on Aug 15, 2009

LP0 ON FIRE
Jan 25, 2006

beep boop
I'm doing what you wrote: defining $contents with file_get_contents and putting the URL into a variable, if that does anything. Doesn't work. :(

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



You could try curl:
php:
<?
function tryGetURL($url, $dest)
{
    global $errOpen,$errClose;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $reply = curl_exec($ch);
    $status = curl_getinfo($ch);
    if($status['http_code'] == 200)
    {
        if(($file = fopen($dest, 'wb', false)) !== false)
        {
            fwrite($file, $reply);
            fclose($file);
        }
        else die("Found the file but couldn't copy it to '$dest'");
    }
    
    return ($status['http_code'] == 200);
}
?>
That ought to work if your host is set up right

LP0 ON FIRE
Jan 25, 2006

beep boop
Sorry for making this go on so long, but it seems like I cannot get any methods to work. The only things that are disabled php-wise are Virtual Directory Support and Thread Safety. I double checked with my host 1&1 to see if anything with their settings would prevent this and they claimed that it wouldn't.

Munkeymon - the curl script up above with the url and dest defined is returning a blank page without the message "Found the file but couldn't copy it to '$dest'". There's nothing in my images folder. The url for images work whether it's on or offsite. The destination folder to the images is correct. The permissions to the folder are correct. I've tried deleting the folder and creating one again and set the permissions again.

edit:

I even tried using ftp code. It prints 'Could not create the file'.

php:
<?

$ftp_user   = 'user'; 
$ftp_pass   = 'pass'; 
$ftp_server = 'myserver'; 
$ftph       = ftp_connect($ftp_server); 
$path       = '/'; 
$ftpc       = ftp_connect($ftp_server) or die('Could not connect to FTP server'); 
$jpg        = file_get_contents('http://www.siteWhereJPGLives.com/image.jpg') or die('Could not grab the file'); 

ftp_login($ftpc, $ftp_user, $ftp_pass) or die('Could not log into FTP'); 
ftp_site($ftpc, 'CHMOD 777 ' . $path) or die ('Could not CHMOD the directory'); 

$fp         = fopen('http://www.mySite.com/imagePath/test.jpg', 'w+') or die('Could not create the file'); 

fputs($fp, $jpg) or die('Could not write to the file'); 
fclose($fp); 
unset($jpg); 
ftp_site($ftpc, 'CHMOD 777 ' . $path) or die ('Could not CHMOD the directory'); 
ftp_close($ftpc); 

?>

LP0 ON FIRE fucked around with this message at 20:04 on Aug 17, 2009

Alex007
Jul 8, 2004

You can't use fopen to WRITE to a url.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



awdio posted:

Munkeymon - the curl script up above with the url and dest defined is returning a blank page without the message "Found the file but couldn't copy it to '$dest'". There's nothing in my images folder. The url for images work whether it's on or offsite. The destination folder to the images is correct. The permissions to the folder are correct. I've tried deleting the folder and creating one again and set the permissions again.

You would have to check the returned value from the function. If it's false, the remote server returned something other than a 200 (success) like maybe a 404 (file not found). You can always just change the function to var_dump($status) to see what happened.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
Dear PHP devs, what in the logic is removing the <?= shortcut along with the the <? shorttag? The <?= will not be confused with <?xml, and it is very useful for using php to template.

Which mailing list should I start a campaign on to have it reinstated?

McGlockenshire
Dec 16, 2005

GOLLOCKS!
None, because It's Not The PHP Way.

Get out while you still can.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



haywire posted:

Dear PHP devs, what in the logic is removing the <?= shortcut along with the the <? shorttag? The <?= will not be confused with <?xml, and it is very useful for using php to template.

Which mailing list should I start a campaign on to have it reinstated?

HAHAha, gently caress. Why isn't an XML parser operating on a PHP file pretty much always a logic error that the language designers shouldn't care about?

McGlockenshire posted:

Get out while you still can.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

McGlockenshire posted:

None, because It's Not The PHP Way.

Get out while you still can.
:smug:

Pimpsolo
Jun 6, 2004

This is probably a fairly simple/beginner question that I should know the answer to but I'm dealing with a php form that isn't mine, specifically:

http://www.registrar.usf.edu/ssearch/staff/staff.php

and I'd only like to give a value to one variable "P_REF" which refers to the text box input for "Course Reference Number".

What I'd like to do is, instead of manually typing in the course reference number, I'd like to state it in the url and automatically submit it if possible.

For instance, it's probably impossible to do something like "http://www.registrar.usf.edu/ssearch/staff/staff.php?P_REF=11962&Search" or something like that unless it was originally written in the server side code to query the URL?

Now I am aware that the following may sound very stupid BUT: if that's an impossibility, is it possible for me to create my own php page (hosted on my own server) where I would set P_REF = 11962 then point my form action toward http://www.registrar.usf.edu/ssearch/staff/staff.php to create the same effect with one mouse button?

Basically you can see that I would like to automate filling out this form so that with a single click I get the results of my query. So if either of my methods are impossible and there's an alternate, I'm open to another method. Thanks in advance for any help.

gibbed
Apr 10, 2006

haywire posted:

Dear PHP devs, what in the logic is removing the <?= shortcut along with the the <? shorttag? The <?= will not be confused with <?xml, and it is very useful for using php to template.

Which mailing list should I start a campaign on to have it reinstated?
I don't know (or care) about the echo tag, but I always disliked the short tag because it was a toggleable option to have it enabled or not.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Pimpsolo posted:

Basically you can see that I would like to automate filling out this form so that with a single click I get the results of my query. So if either of my methods are impossible and there's an alternate, I'm open to another method. Thanks in advance for any help.
You might try grabbing the form source and substituting <input type="hidden" name="the_same_name" value="whatever" /> for the fields you want to pre-fill. This isn't guaranteed to work if the server does any sort of valid-token stuff but it usually works (if there is any token stuff, you might have to scrape the form on the server side first).

KuruMonkey
Jul 23, 2004

gibbed posted:

I don't know (or care) about the echo tag, but I always disliked the short tag because it was a toggleable option to have it enabled or not.

Indeed; its all about portability. Some installs will have short tags enabled, and some not, so code using short tags will fail to run on some systems. All PHP installs will handle long tags, so anyone who cared about other people being able to use their code without having to reconfigure their server already only used long tags.

Also some of the servers configured without short tags are ye olde shared hosting, making it difficult to do that reconfiguration.

tldr; short tags were a silly idea, no one with any common sense will be sad to see them go.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.

haywire posted:

Dear PHP devs, what in the logic is removing the <?= shortcut along with the the <? shorttag? The <?= will not be confused with <?xml, and it is very useful for using php to template.

Which mailing list should I start a campaign on to have it reinstated?

i always enjoyed writing <<??>?xml

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

KuruMonkey posted:

tldr; short tags were a silly idea, no one with any common sense will be sad to see them go.

No it loving wasn't, making them an option was. But then again this is one in a long line of not-quite-right solutions to not-quite-right problems php has, so any php dev has seen some of their favorite parts go to waste.

Yeah so I love short tags, so shoot me.

sonic bed head
Dec 18, 2003

this is naturual, baby!
I would like to know what the best procedure to authenticate between a Java and PHP application would be. There is a php webapp at php.example.com that uses PHP sessions and there is a java webapp at java.example.com. I would like to be able to log in to the php site and then pass that authentication on to the java site. I'm thinking something like add an extra cookie from the php site set to example.com and then use a web service to authenticate to some DB that the PHP session gets stored in.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums

Murodese posted:

i always enjoyed writing <<??>?xml

<? isn't important.

<?= is kind of loving neat, though.

SmirkingJack
Nov 27, 2002
I was digging through some Kohana code and came across this syntax, which I have never seen before:

php:
<?
($field === TRUE) and $field = $this->any_field;?>
What does this do? The context is:

php:
<?
public function add_rules($field, $rules)
{
    // Handle "any field" filters
    ($field === TRUE) and $field = $this->any_field;

    // Get the rules
    $rules = func_get_args();
    $rules = array_slice($rules, 1);

        ...
?>

gibbed
Apr 10, 2006

It's the equivilent of:
php:
<?
if ($field === TRUE)
{
    $field = $this->any_field;
}
?>
They're being jerks about the verbosity of their code basically.

Standish
May 21, 2001

SmirkingJack posted:

I was digging through some Kohana code and came across this syntax, which I have never seen before:

php:
<?
($field === TRUE) and $field = $this->any_field;?>
What does this do?
this is called "short-circuiting".
http://en.wikipedia.org/wiki/Short-circuit_evaluation

doing it in the context of
php:
<?
some_func() or die("some_func() returned an error!");
?>
is a very common idiom but using it for assignment like in the example you gave is a bit obfuscated.

SmirkingJack
Nov 27, 2002

gibbed posted:

It's the equivilent of:
php:
<?
if ($field === TRUE)
{
    $field = $this->any_field;
}
?>
They're being jerks about the verbosity of their code basically.

Standish posted:

this is called "short-circuiting".
http://en.wikipedia.org/wiki/Short-circuit_evaluation

doing it in the context of
php:
<?
some_func() or die("some_func() returned an error!");
?>
is a very common idiom but using it for assignment like in the example you gave is a bit obfuscated.

Ah, I see. Thanks for teaching me something new!

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

gibbed posted:

It's the equivilent of:
php:
<?
if ($field === TRUE)
{
    $field = $this->any_field;
}
?>
They're being jerks about the verbosity of their code basically.
It's not even less verbose than just using if.
php:
<?
if ($field == TRUE) $field = $this->any_field;
($field === TRUE) and $field = $this->any_field;
?>

Oddish
Jul 11, 2009
I'm using the below function to replace certain words with a html formatted version of the same word. The html formatting is actually just surrounding the word with a span tag that I use with jQuery to pop up a description of the word.

Basically this:
code:
amet, Consectetuer adipiscing
... becomes this:
code:
amet, <span class="dicWord" title="Consectetuer|Lorem ipsum 
dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque 
volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse 
urna nibh, viverra non, semper suscipit, posuere a, pede.">
Consectetuer</span> adipiscing
The problem is that the function will nest these span tags when a word in the dictionary occurs within another word's description.

Lets say the dictionary contains two words: "Consectetuer" and "Quisque". First the function will put a span tag around "Consectetuer" but then it will also put a span tag around "Quisque" which occurs within the description (that was just added by the previous "iteration" of preg_replace) for "Consectetuer" and gently caress everything up.

I'll end up with this:
code:
amet, <span class="dicWord" title="Consectetuer|Lorem ipsum 
dolor sit amet, consectetuer adipiscing elit. Donec odio. 
<span class="dicWord" title="Quisque|Lorem ipsum dolor sit amet, 
consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis 
eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, 
viverra non, semper suscipit, posuere a, pede.">Quisque</span> 
volutpat
Basically I want preg_replace to replace the words, but NOT replace these words within the specified replacement texts. Any ideas?

php:
<?
function dictionaryTest($s) {

    $resDic = query("SELECT * FROM dictionary WHERE groupid = ".ACTIVE_GROUP." ORDER BY word");

    if (mysql_num_rows($resDic)) {

        while ($dicWord = mysql_fetch_assoc($resDic)) {
            
            $arrPatterns[] = '/\b('.$dicWord['word'].')\b/U';
            $arrReplacements[] = '<span class="dicWord" title="'.htmlspecialchars($dicWord['word']).'|'.htmlspecialchars($dicWord['descr']).'">$1</span>';
        }

        return preg_replace($arrPatterns, $arrReplacements, html_entity_decode($s,ENT_NOQUOTES,'UTF-8'),1);

    } else {
        return $s;
    }
}
?>

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Dump the word replacement list to an associative array ('word' => 'explanation'), explode the output text on space, go through the array of output text and see if each entry appears in the replacement array and if it does, replace the entry in the output array with the tags and whatnot then implode the output array to get the whole text again.

I imagine one of the mysql_ functions would make dumping the text into a PHP array easy (possibly a one-liner?) but I don't know because we use our own horrible custom middleware here at work so I never use them.

Also, you know there's an acronym tag? http://www.w3schools.com/tags/tag_acronym.asp

argz
May 20, 2005

The hand says it all.

KuruMonkey posted:

tldr; short tags were a silly idea, no one with any common sense will be sad to see them go.

what?


<?=$my_var?>

is so much cleaner than

<?php echo $my_var?>


Do you like writing '<?php echo' 40 times in a file?

Lord Purple
Mar 7, 2006

Remove your eyes...
I have a client that wants some control over his databases for his site (viewing, creating, and modifying data in tables etc.) without any knowledge of SQL. I did the site in MySQL. Is there was a premade script for this kind of thing or do I have to start from scratch?

jasonbar
Apr 30, 2005
Apr 29, 2005

scrabbleship posted:

I have a client that wants some control over his databases for his site (viewing, creating, and modifying data in tables etc.) without any knowledge of SQL. I did the site in MySQL. Is there was a premade script for this kind of thing or do I have to start from scratch?

Would http://www.phpmyadmin.net/home_page/index.php work?

Adbot
ADBOT LOVES YOU

Lord Purple
Mar 7, 2006

Remove your eyes...

jasonbar posted:

Would http://www.phpmyadmin.net/home_page/index.php work?

It might but it is probably a bit overkill for what my client wants. This would probably overwhelm him. He just wants something he can see the entries in the table with and modify/delete faulty ones with; nothing to fancy. Thanks for the suggestion nonetheless.

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