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
duck monster
Dec 15, 2004

eHacked posted:

Hi, thanks, changing the constructor name seemed to work... would this have anything to do with the server I'm learning off of running php 4?

Ah yup. Php 4 is a pretty basic version of OO. You need to get your hands on something with Php 5 since 4 is pretty much redundant.

Adbot
ADBOT LOVES YOU

KuruMonkey
Jul 23, 2004
Yes, php4's OOP is essentially just convenience grouping of functions.

If you're learning, install something like wampserver so you can run php locally, it has php 5.2.9 at the moment, i believe.

I'll gloss over the probable quality of a tutorial that requires a specific version of PHP but doesn't bother to mention it... (or that uses "__construct" and "var $xyz" in the same class; thats 1/2 php5 and 1/2 php4)

Ooh; on some servers you can simply rename xyz.php to xyz.php5 and mystically be running under php5; try that.

If that does work, you can try:

AddHandler application/x-httpd-php5 .php

in a .htaccess file in your directory (this assumes you are using apache as your webserver)

gibbed
Apr 10, 2006

http://php.net/oop4 - PHP4
http://php.net/oop5 - PHP5

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

eHacked posted:

Hi, thanks, changing the constructor name seemed to work... would this have anything to do with the server I'm learning off of running php 4?

Yes. PHP4 doesn't do __constructor

Dolemite
Jun 30, 2005
I've been working on this script and it's near finished. I'm struggling with one last thing and I need help! This has been wracking my brain for the last few days!

My script does the following:
1. User selects a file to upload via a web form.
2. The script accepts the file upload, then FTPs it over to a different server.

All of the code is one page. The script posts to itself and then does its thing.

What I am trying to do is display a div while the script is FTPing the file over. I want to change the display to "block" while it uploads and back to "none" to hide it.

For some reason, the div never shows/hides itself. It's like the DIV is not even there! But what is strange is that the script is clearly uploading my file. The file makes it to the PHP server and the file does appear on the FTP sever as well. So why is my DIV not showing up?

Here's the page:

HTML form:
php:
<?php echo "<form enctype=\"multipart/form-data\" action='".$_SERVER['php_self']."' method='post'>"?>

<input type="hidden" name="do_upload" value="true" />

<p class="formtext">Choose a file to upload <span style="font-size:10px;">(20MB maximum allowed)</span></p> 

<input name="uploadedfile" type="file" class="inputs" style="width:205px;"/>

<input type="submit" value="Upload File" class="inputs" style="width:85px;" onclick="<?php $disp="block;" ?>" />

</form>
Once the user clicks upload, the script posts back to itself and uploads.

PHP code:
php:
<?
$disp="none;";    
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$dest_file = basename( $_FILES['uploadedfile']['name']);
    
//I want to show this div during FTP upload
echo "<div style=\"width:200px;margin:0px;padding:0px;display:".$disp."float:left;\">";
echo "File accepted. Uploading to public server - please wait.";
echo "<img src=\"spinner.gif\" alt=\"progress indicator\"></div>";        

    
function ftp_upload($target, $destination)
{
    //Upload the file to our public FTP server
    $t = $target; 
    $d = $destination;
    $ftp_server = "My FTP Server";
    $user = "username";
    $pass = "password";
    $conn_id = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
    $login_result = ftp_login($conn_id, $user, $pass);
    ftp_chdir($conn_id, "/directory/stuff/goes/here");
    ftp_put($conn_id,$d,$t,FTP_BINARY);            
    ftp_close($conn_id);    
}



if(isset($_POST['do_upload']) && $_POST['do_upload'] == "true")
{
    //check if user uploaded a file, then...
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
        {
            
            $disp="block;";    //set DIV to show up
            ftp_upload($target_path, $dest_file); //FTP file to public server
            $disp="none;"; //set DIV hidden again
            echo "<h4>Success</h4>";
            echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded.<br /><br />";            
            echo "Cut and paste the following link in your e-mail to link to your uploaded file:<br /><br />";
            echo "<a href=\"http://www.my-server.net/public/" . basename( $_FILES['uploadedfile']['name']) . "\">[url]http://www.my-server.net/public/[/url]".basename( $_FILES['uploadedfile']['name'])."</a><br /><br /><br />";
        }        
    else
    {
        echo "<h4>Warning</h4>";
        echo "There was an error uploading the file - Please try again!";            
    }    
}
?>
Any ideas why I can't make this div show up. I'm pulling my hair out here. I'd be finished already if it wasn't for this little snag!

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Dolemite posted:


For some reason, the div never shows/hides itself. It's like the DIV is not even there! But what is strange is that the script is clearly uploading my file. The file makes it to the PHP server and the file does appear on the FTP sever as well. So why is my DIV not showing up?

Any ideas why I can't make this div show up. I'm pulling my hair out here. I'd be finished already if it wasn't for this little snag!

Where is the javascript? If there is no javascript, well, there is your problem. I have no idea what you are trying to accomplish in that onclick, but it certainly isn't valid.

Dolemite
Jun 30, 2005

Lumpy posted:

Where is the javascript? If there is no javascript, well, there is your problem. I have no idea what you are trying to accomplish in that onclick, but it certainly isn't valid.

In the script I posted, I wasn't using javascript in the example I posted. The onclick got left in by accident when I posted. The onclick goes nowhere, it was from experimenting. I don't know javascript that well. :(

I did find a solution that solved my problem. Now when a user clicks on upload, the div appears and displays the way I want it too. Turns out I needed javascript to show the div.

Ideally, I was trying to use (read:find via Google) javascript to make a file upload progress meter (the meter would track the PHP ftp upload progress). This'll work for now though.

Corla Plankun
May 8, 2007

improve the lives of everyone
I am making a really ghetto shoutbox as we speak. It is basically the least sanitized code in history. All I intend to do with it is input something, save it to a text file, and echo it back on the same page. OBVIOUSLY this is about as secure as spreading my rear end cheeks apart with both hands, but is there any other reason why I shouldn't do this?

The page in question requires a log-in, and only four people are ever going to access it, so security is irrelevant. I'm only doing it this way because I can't figure out how to install premade shoutboxes, and php script by itself is really easy.

Zorilla
Mar 23, 2005

GOING APE SPIT

Corla Plankun posted:

I am making a really ghetto shoutbox as we speak. It is basically the least sanitized code in history. All I intend to do with it is input something, save it to a text file, and echo it back on the same page. OBVIOUSLY this is about as secure as spreading my rear end cheeks apart with both hands, but is there any other reason why I shouldn't do this?

It's probably not that bad. Here is my assessment:
  • If you read the file in by using include() or require(), the text file gets interpreted as code. Not good, as you can imagine. Using fopen(), fread(), etc. is fine.
  • You will need to use htmlspecialchars() when preparing output to prevent XSS attempts or users breaking HTML.
  • Since this has controlled access, you'll probably want to keep the text file from being served over the web by using an .htaccess rule

Zorilla fucked around with this message at 00:14 on Mar 25, 2009

Warbling Castrato
Sep 25, 2003

Is there any way that I can set a file's attributes to make it hidden on Windows after it is downloaded via PHP? I'm building an internal web app for our company, and I'd like to hide these 3 autorun related files (a .bat, .inf and .ico) when they're compiled into a ZIP.

indulgenthipster
Mar 16, 2004
Make that a pour over
What I have is one function that hits the database then outputs the result. However, when the function tries to output the result of another function, nothing happens (and no errors), for example:

php:
<?
database_stuff();

database_stuff() {
   //sql stuff here, pulls out $functionstuff from database result ( output_stuff(); )

   echo 'oh hey';
   //this outputs

   $functionstuff;
   //nothing outputs
}

output_stuff() {
   echo 'this should output right?';
   //this does not output
}
?>
What am I missing here?

indulgenthipster fucked around with this message at 14:53 on Mar 25, 2009

KuruMonkey
Jul 23, 2004

VerySolidSnake posted:

What I have...

What am I missing here?

Well, what you actually have is, in order:

A call to a function, then the definition of the function you just called.

Then the definition of a second function.

Your second function does nothing because you never call it.

Inside database_stuff()...

echo "oh hey"; outputs because of the echo

The $functionstuff; does nothing because it is simply a do-nothing statement of a variable name. (essentially that statement resolves to the value of that variable, but you've given no instruction of what to do with that value, so its just discarded)

echo $functionstuff; is what you want if you need to output the content of that variable.

You will need to check that the value in $functionstuff is not "nothing", or something that equates to "nothing" in a string context:

if($functionstuff === NULL || $functionstuff == '')
$functionstuff = 'oh feck it all';

indulgenthipster
Mar 16, 2004
Make that a pour over
When I echo $functionstuff, on the page it displays:

output_stuff();

It just echos it as plain text.

KuruMonkey
Jul 23, 2004

Corla Plankun posted:

OBVIOUSLY this is about as secure as spreading my rear end cheeks apart with both hands, but is there any other reason why I shouldn't do this?

As Zorilla said, its not that bad as long as you don't do dynamic includes and do run some simple sanitising, which is just one function call.

BUT that is dependant on the fact that you are just loading the content in and echoing it out again; don't ever go deciding that you can use something from that file as a key to a DB lookup etc.

Regarding not serving the text file to a browser; if you can, put the text file outside your document root. On plenty of shared servers I have seen this is not possible, if so the easiest way to get the same effect with .htaccess is to make a directory just for the text file, and have the .htaccess file simply read:

deny from all

KuruMonkey
Jul 23, 2004

VerySolidSnake posted:

When I echo $functionstuff, on the page it displays:

output_stuff();

It just echos it as plain text.


Riiiiiight.

I think I see what you're doing. (had completely the wrong end of the stick before)

So; your DB query is resulting in the string "output_stuff();" which is put into the variable $functionstuff?

If thats correct, then...well...don't do that; its bad. You are basically storing a function pointer in a DB, but doing it the bad way.

Rework it so that your query returns "output_stuff"; no brackets or semi-colon.

Then use:
php:
<?
$functionstuff= get_from_db_or_whatever(); // $functionstuff now = "output_stuff"
if(is_callable($functionstuff))
{
  $functionstuff();
}
else
{
  echo "well, poop";
}
?>
To do it with the string you have requires eval() and...well...NO!

indulgenthipster
Mar 16, 2004
Make that a pour over
Whew ok that is close to working, thanks!

Now one more issue...

php:
<?
database_stuff($connect) {
   //sql uses $connect function for mysqli connection information
   //it is declared in header as $connect=db_connect();

   output_stuff($connect);
}

output_stuff($connect) {
   echo 'this does output';

   //but sql spits out errors

  //I'm very positive that is in reference to $connect not passing properly
}
?>

indulgenthipster fucked around with this message at 17:00 on Mar 25, 2009

KuruMonkey
Jul 23, 2004
Is your code actually something along the lines of...

php:
<?
function database_stuff($connect)
{
  $functionstuff = get_from_db_or_whatever($connect); // and this uses DB OK?
  if(is_callable($functionstuff))
  {
    $functionstuff($connect); // and this cannot use DB OK?
  }
  else
  {
    echo "well, poop";
  }
}
?>
Because in your last example you just called output_stuff explicitly, which according to your other posts is not what you're actually doing.

Which is to say; I think there's something you are removing "for clarity" which is actually causing your problem. Because something like I have above here SHOULD work fine. (unless you have done something to $connect in between and not reproduced that in your example)

As an alternate to $functionstuff($connect); you can also do call_user_func($functionstuff, $connect); I don't know of any functional difference between the two options, but there might be one.

indulgenthipster
Mar 16, 2004
Make that a pour over
This is odd as the function works fine if I call it straight on the page, but once I call it from this other function it fails. Sorry for taking up so much room in this thread but here is a more full version of the code.

php:
<?
//the mysql works fine in this first function
function module_info($connect,$rewrite,$position) {
    $sql = "SELECT includefile FROM modules WHERE position = ? AND rewrite = ?";
    $stmt = mysqli_stmt_init($connect);
    
    if (mysqli_stmt_prepare($stmt, $sql)) {
        mysqli_stmt_bind_param($stmt, 'ss', $position, $rewrite);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt, $content, $includefile);
        while (mysqli_stmt_fetch($stmt)) {    
            if($includefile) {
                                echo 'This string echos';
                $includefile($connect);
            }
        }
    }
}

//the mysql does not work in this function
function teamlist($connect) {
    $sql = "SELECT firstname,lastname FROM staff";
    $stmt = mysqli_stmt_init($connect);
    
    echo 'This string outputs';

        mysqli_stmt_prepare($stmt, $sql);
        mysqli_stmt_execute($stmt); //error line
        mysqli_stmt_bind_result($stmt, $firstname, $lastname); //error line
        while (mysqli_stmt_fetch($stmt)) { //error line
            echo 'This does not output, but the SQL is fine';
        }
    
}
?>
Errors:

Warning: mysqli_stmt_execute() [function.mysqli-stmt-execute]: invalid object or resource mysqli_stmt

Warning: mysqli_stmt_bind_result() [function.mysqli-stmt-bind-result]: invalid object or resource mysqli_stmt

Warning: mysqli_stmt_fetch() [function.mysqli-stmt-fetch]: invalid object or resource mysqli_stmt

Begby
Apr 7, 2005

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

VerySolidSnake posted:

This is odd as the function works fine if I call it straight on the page, but once I call it from this other function it fails. Sorry for taking up so much room in this thread but here is a more full version of the code.

What you want to do is get your includefile stuff into an array, then loop through that array after closing the statement. You cannot execute another prepared statement while another is open.

So in your while(mysqli_stmt_fetch($stmt)) loop you will add the results to an includes file array, close the statement, then do a foreach on the array.

Speaking of that, you aren't closing any of your statements nor are you doing any error checking in your teamlist function.

Also, speaking of that, its generally a pretty bad idea to do something like $myfunction($arg) where $myfunction comes from text that is editable outside of your source files. If someone had access to your database they could put whatever fun things they wanted into the includefile field and PHP would happily execute it.

KuruMonkey
Jul 23, 2004
Not quite: they could put in one function name, and if the function was defined, php would call it. They have no way (through that particular avenue) of getting an arbitrary function defined ready to call, or to set any other parameters to it (other than a connection to a DB they already control...)

They could do unpleasant things, sure, but none more unpleasant than being in control of the DB in the first place.

And that was why I said not to use eval()...

As an aside, VerySolidSnake:

if($includefile) is insufficient. I put if(is_callable($includefile)) for a reason!

All you are testing is that the variable doesn't equate to false, not that it is the name of a valid function.

Really you should have a master list of valid functions to be requested in this manner, and check that its in that list. Better is to have all the functions named "handler_for_".$value_from_db and then construct the name from a parameter and the static text, so you never get "phpinfo" as your parameter value, for instance. Ideally the list of permitted function names should not be compromised just because the request is compromised (i.e. not same DB) But, again, by the time you are considering the DB compromised, you need to think in terms of :pt: anyway...

KuruMonkey fucked around with this message at 19:49 on Mar 25, 2009

indulgenthipster
Mar 16, 2004
Make that a pour over
Thanks for the suggestions on security, I'm placing that into my code.

Aside from those security and error checking issues though, any idea why the $connect is not properly passing over? None of that MySQL in teamlist is working, so I don't even have the chance to create an array.

KuruMonkey
Jul 23, 2004
Begby was saying you need to finish with, and close, the mysqli statement in the module_info function before you can successfully have another in one of the called from the db functions.

He's probably right.

So you need to build the array of function names there:

php:
<?
function module_info($connect,$rewrite,$position) {
    $sql = "SELECT includefile FROM modules WHERE position = ? AND rewrite = ?";
    $stmt = mysqli_stmt_init($connect);
    
    if (mysqli_stmt_prepare($stmt, $sql)) {
        mysqli_stmt_bind_param($stmt, 'ss', $position, $rewrite);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt, $content, $includefile);

        // setup blank array:
        $functions = array();
        while (mysqli_stmt_fetch($stmt)) {    
            if($includefile)
            {
                // make an array:
                array_push($functions, $includefile);
            }
        }
        // IMPORTANT:
        mysqli_stmt_close($stmt);
        // use the array
        foreach($functions as $func)
        {
           if(is_callable($func))
              $func($connect); // connect is useable now
                               // remember to close the staements these functions use
        }
    }
}
?>

indulgenthipster
Mar 16, 2004
Make that a pour over
That makes sense, and worked! Thanks everyone for the help.

Security question:

Is there a Holy Grail function for sanitizing user input (when considering I'm using prepared statements for every query)? Or am I pretty safe as long as I use html_special_characters on input and have an 'allowed' functions list?

Sylink
Apr 17, 2004

EDIT: NEVERMIND I AM RETARDED PLEASE REMEMBER THAT = IS NOT THE SAME AS == IN THE VERY FIRST IF STATEMENT -fml
I'm trying to make a basic user login verification thing and I'm having trouble with using sessions/understanding them.


So this my index.php

php:
<?php session_start();?>

<html>
<body>

<?php

if($_SESSION['logged'] :siren:=: 1)
{
    echo "Success!";
    echo "<br/>"$_SESSION['logged'];
    echo '<form action="logout.php" method="post">';
    echo '<input type="submit" value="Logout">';
    echo '</form>';
    }
else
{


echo '<form action="login.php" method="post">';
echo 'Username:';
echo '<input type="text" name="username" />';
echo '<br/>';
echo 'Password:';
echo '<input type="text" name="password" />';
echo '<input type="submit" value="Login" />';
echo '</form>';
}
?>

</body>
</html>
So if the session doesn't show the user as logged in it gives you the login boxes otherwise just a test message to prove it worked.

My login apparently works fine

login.php
php:
<?php

 $username$_POST["username"];
 $userpasswordmd5($_POST["password"]);
 
 
$con mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' mysql_error());
  }

mysql_select_db("cookbook2"$con);

$result mysql_query("SELECT * FROM users WHERE username='$username' and userpass='$userpassword'");
if (mysql_num_rows($result) > 0)
{

    $_SESSION['logged']= 1;
    header('Location: index.php');
    }
Else
    echo "Fail";

?>

So it redirects to index.php which then shifts to provide a button that says logout that runs logout.php

php:
<?php 
$_SESSION['logged'] = 0;

header('Location: index.php');
?>

So this seems to set the session variable but when I go back to index it treats me as still logged in. I originally tried to just destroy the session entirely but it says its not initialized. I'm somewhat confused as to what is going on because after I set the value to 0 the index.php still thinks it is 1.

I can only figure I've missed an important concept.

Sylink fucked around with this message at 22:25 on Mar 25, 2009

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:

Sylink posted:

EDIT: NEVERMIND I AM RETARDED PLEASE REMEMBER THAT = IS NOT THE SAME AS == I HAVE HIGHLIGHTED THE STUPID ERROR FOR OTHER MORONS LIKE ME TO LEARN FROM

...and you'll probably want session_start() at the beginning of login.php and logout.php.

Begby
Apr 7, 2005

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

VerySolidSnake posted:

Is there a Holy Grail function for sanitizing user input (when considering I'm using prepared statements for every query)? Or am I pretty safe as long as I use html_special_characters on input and have an 'allowed' functions list?

Prepared statements are pretty secure, html_special_characters is good if you are going to be echoing any db content. You might want to look into how to protect yourself against XSS attacks as well, google for it (cross site scripting attacks).

You also might want to take a look at PDO if you are going to be doing a lot of prepared statements. It makes it so you don't have to pass around a connect resource everywhere. Zend Framework has a nice wrapper for it that even simplifies it further.

Supervillin
Feb 6, 2005

Pillbug

Begby posted:

html_special_characters is good if you are going to be echoing any db content

Just emphasizing something that VerySolidSnake had backwards in his question. You should typically sanitize immediately before using something, no sooner.

The main reason for that, of course, is if you htmlspecialchars stuff on the way IN, you're assuming everything in your database is safe for output later. However, anything could happen between the time it's stored and the time it's used. Not necessarily an attack, either - what if you have to manually enter a row for whatever reason, and forget to manually escape it? You don't have to worry about that if you only use htmlspecialchars immediately before echoing the text.

Begby
Apr 7, 2005

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

Supervillin posted:

Just emphasizing something that VerySolidSnake had backwards in his question. You should typically sanitize immediately before using something, no sooner.

The main reason for that, of course, is if you htmlspecialchars stuff on the way IN, you're assuming everything in your database is safe for output later. However, anything could happen between the time it's stored and the time it's used. Not necessarily an attack, either - what if you have to manually enter a row for whatever reason, and forget to manually escape it? You don't have to worry about that if you only use htmlspecialchars immediately before echoing the text.

Excellent point, this is something that I should do more often.

Oraxien
Jul 4, 2005

I have oraxien.com, just use it for personal nonsense, and fun.

I have a php board at oraxien.com/yachtclub (It's a browser game forum for me and my friends who play the game together)

I recently got an email from my host that says:


This is just a note to let you know that we've moved your account to a new server!
We apologize for the lack of notice, but this was an emergency move as a perfomance and stability measure.

They then listed some things that might not work anymore, I got them all fixed except this:

Also, custom PHP (and php.ini) setups will likely be broken by the move. This is because they would have been built against the old 32bit libraries on the old server and not the 64bit libraries on this new server. Unfortunately, this isn't something we can help you troubleshoot, but you'll just basically need to rebuild your custom php (or php.ini) again.

I used the hosts "one click install" to get it all setup, so this is just frankly beyond me...

Can someone give me a little more detail how to fix this? I don't wanna have to lose all my threads or user accounts if I don't have to.

Munkeymon
Aug 14, 2003

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



Oraxien posted:

Can someone give me a little more detail how to fix this? I don't wanna have to lose all my threads or user accounts if I don't have to.

That shouldn't have anything to do with php.ini. Forum data like posts and users ought to be stored in a database somewhere. The setting pointing it to said database would most likely be in a file in the forum software itself.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Munkeymon posted:

That shouldn't have anything to do with php.ini. Forum data like posts and users ought to be stored in a database somewhere. The setting pointing it to said database would most likely be in a file in the forum software itself.

php.ini does have settings that affect DB interaction. I've had MSSQL date format (in php.ini) cause headaches on a Symfony app that took days to figure out.

Oraxien
Jul 4, 2005

Does this help?

This is what it says when you try to load the index:


Warning: require(./config.php) [function.require]: failed to open stream: Permission denied in /home/oraxien/oraxien.com/yachtclub/common.php on line 127

Fatal error: require() [function.require]: Failed opening required './config.php' (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/oraxien/oraxien.com/yachtclub/common.php on line 127

spiritual bypass
Feb 19, 2008

Grimey Drawer
Did you check the permissions on those files? Do you just need to copy them in from another directory?

Oraxien
Jul 4, 2005

royallthefourth posted:

Did you check the permissions on those files? Do you just need to copy them in from another directory?

Possibly, but it was working just fine (everyone was posting/browsing at will) before they sent me that email (was working for about a month)

Munkeymon
Aug 14, 2003

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



Oraxien posted:

Possibly, but it was working just fine (everyone was posting/browsing at will) before they sent me that email (was working for about a month)

But they put them on a different machine and may have screwed up file premissions when they did so. You could just copy the forum software to <forum_software>_backup and use you host's click-once install again. As long as you can still point it at the same database all the data will still be there. That might include modifying that config.php file it's talking about and copying across any other changes you might have made.

royallthefourth posted:

php.ini does have settings that affect DB interaction. I've had MSSQL date format (in php.ini) cause headaches on a Symfony app that took days to figure out.

Fair enough, but decent forum software shouldn't require loving with php.ini to work with the database - assuming the right modules are already included.

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer
I run a Magic: the Gathering website where I need lists of cards converted into links that go to the card's entry in the official online encyclopedia of cards, Gatherer. Basically I have a list of cards like this:

code:
4 Tarmogoyf
3 Dark Confidant
12 Forest
And want to paste it into a textbox and have it spit this out:

code:
4 <a href="http://ww2.wizards.com/gatherer/CardDetails.aspx?name=Tarmogoyf">Tarmogoyf</a>
3 <a href="http://ww2.wizards.com/gatherer/CardDetails.aspx?name=Dark_Confidant">Dark Confidant</a>
12 <a href="http://ww2.wizards.com/gatherer/CardDetails.aspx?name=Forest">Forest</a>
So my friend whipped this up for me:

code:
<pre>
<?
$i = 0;
$names = $_POST['names'];
$newnames = explode(",",$names);
while($i <= count($newnames))
{
	$split = explode(" ",$newnames[$i]);
	echo $split[0] . " &lt;a href=\"http://ww2.wizards.com/gatherer/CardDetails.aspx?name=".$split[1]."\"&gt;".$split[1]."&lt;/a&gt;<br />";
	$i++;
}
?>
</pre>
<form action="page.php" method="POST">
	<textarea name="names"></textarea>
	<br />
	<input type="submit" value="Generate" />
</form>
But unfortunately he couldn't figure out how to have it convert data from a vertical list like I want (they need to be separated by commas as it is right now) and it doesn't handle spaces in card names (which need to be converted to underscores in the url). If anyone could help it'd be much appreciated, as everything I try breaks it.

Oraxien
Jul 4, 2005

Munkeymon posted:

But they put them on a different machine and may have screwed up file premissions when they did so. You could just copy the forum software to <forum_software>_backup and use you host's click-once install again. As long as you can still point it at the same database all the data will still be there. That might include modifying that config.php file it's talking about and copying across any other changes you might have made.


Fair enough, but decent forum software shouldn't require loving with php.ini to work with the database - assuming the right modules are already included.

Hmm, my permissions look fine, or am I looking at it wrong

(Screenshot from Filezilla Client)

Mother loving Edit: I looked at my error again, looks like config.php is what had permissions missing, for public read, so I changed it, you were right:)

Thanks guys!!

Only registered members can see post attachments!

Oraxien fucked around with this message at 13:00 on Mar 27, 2009

KuruMonkey
Jul 23, 2004

BJPaskoff posted:

But unfortunately he couldn't figure out how to have it convert data from a vertical list like I want

Woot:

php:
<?php
    define('MTG_DECKLIST_REGEX''/([0-9]+) (.*)/');
    define('MTG_CARD_LINK''http://ww2.wizards.com/gatherer/CardDetails.aspx?name=');

    $names = (isset($_POST['names']) ? $_POST['names'] : '');
    
    $decklist = array();

    $lines explode("\n"$names); // not rocket science

    foreach($lines as $line)
    {
        $matches = array();
        $match_count preg_match(MTG_DECKLIST_REGEX$line$matches);
        if($match_count && count($matches) > 2)
        {
            array_push($decklist, array('name'=>$matches[2], 
                                   'count'=>(int)$matches[1],
                                   'link'=>MTG_CARD_LINK.$matches[2]));
        }
    }
    
    echo "<h1>Your Links, Sir</h1>";
    echo '<ul>';
    foreach($decklist as $line)
    {
        echo "<li>{$line['count']} <a href='{$line['link']}'>{$line['name']}</a></li>";
    }
    echo "</ul>";
?>
<form action="index.php" method="POST">
    <textarea name="names"></textarea>
    <br />
    <input type="submit" value="Generate" />
</form>
Edit: I'd forgotten the number of copies of the card.
Edit 2: I break tables!

KuruMonkey fucked around with this message at 11:30 on Mar 27, 2009

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer

KuruMonkey posted:

Woot:
Thanks! I knew it was something with \n, but that's about all I knew.

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer
What is this called?
I use it fairly often and I'd really like to have a name for it.

"<<<"

php:
<?php
$s = <<< text
THIS IS A BUNCH OF TEXT

MY FORMATTING IS PRESERVED ACROSS LINES
text;
?>

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