|
gibbed posted:Drop the trailing ?> too, there is no need for it in this script. That's just taking it too far gibbed posted:Edit: wait why the hell did you put a \r\n in the header() call? That was me getting confused between header and mail (which I'd just been using and takes headers as a string, hence needing line breaks).
|
# ? Apr 15, 2008 00:17 |
|
|
# ? May 15, 2024 03:49 |
|
This is a more general question rather than a what's wrong with this code question. I need to adjust a login screen so that when the user enters details and submits, it logs them into both a system that being developed, as well as phpBB3. Note that while the actual database for the two is the same, the system user table is different from the phpBB3 user tables for various reasons. Basically the way this should work is fill in form, and get logged into the system and phpBB3 at the same time, but I'm having trouble figuring out how phpBB3 handles that sort of thing.
|
# ? Apr 15, 2008 18:07 |
|
Hobo posted:This is a more general question rather than a what's wrong with this code question. Follow the path of the form being submitted and you'll find where phpBB is handling the request, from there just input your own login code. The action attribute of the login form will say something like "login.php?step=2" then just find that part of login.php and hey presto, you can use the login.
|
# ? Apr 15, 2008 18:35 |
|
Evil Angry Cat posted:Follow the path of the form being submitted and you'll find where phpBB is handling the request, from there just input your own login code. The action attribute of the login form will say something like "login.php?step=2" then just find that part of login.php and hey presto, you can use the login. What do I do about the SID that phpBB3 passes? Not sure how it generates that.
|
# ? Apr 15, 2008 18:55 |
|
Hobo posted:What do I do about the SID that phpBB3 passes? Not sure how it generates that. If you're just hijacking the login so you can log yourself in elsewhere you don't need to follow that. You want it so you login you user to your main site as well as phpbb when they login? Well just find where phpbb logs in and add your own login code to that section, no need to follow phpBB's lead.
|
# ? Apr 15, 2008 19:40 |
|
Evil Angry Cat posted:If you're just hijacking the login so you can log yourself in elsewhere you don't need to follow that. You want it so you login you user to your main site as well as phpbb when they login? Well just find where phpbb logs in and add your own login code to that section, no need to follow phpBB's lead. The problem is, it needs to be the other way, i.e. adding phpBB's login code to the main site's code, rather than vice versa. If it was the other way around, it would be simpler as I could look at a few plugins I know about, but hey, requirements documents and all that prevent me from doing it the simple way. :/ Are you saying it would be possible to just totally ignore the SID?
|
# ? Apr 15, 2008 20:50 |
|
I would like to sort file names with file extensions numerically. It's not sorting correctly right now, and I think it is because of the file extensions. So far I have: code:
|
# ? Apr 16, 2008 19:53 |
|
You probably want to do a Natural Sort.
|
# ? Apr 16, 2008 19:56 |
|
Also suggesting use of glob() instead of the opendir crap.
|
# ? Apr 16, 2008 21:18 |
|
duz posted:You probably want to do a Natural Sort. Yes! This is awesome. Exactly what I wanted. Now, I'm trying to make it go in reverse order like before, and I can do it but I don't know if it's the best way because it seems to be working very slow, but then again it could just be my internet connection. code:
|
# ? Apr 16, 2008 22:05 |
|
gibbed posted:Also suggesting use of glob() instead of the opendir crap. But do I really need it? Is there a reason this would be better in my situation?
|
# ? Apr 16, 2008 22:07 |
|
awdio posted:
It's slow because you're reversing the array each time you loop.
|
# ? Apr 16, 2008 22:20 |
|
duz posted:It's slow because you're reversing the array each time you loop. Yeah I see that, but even if I put the array_reverse($files) after natsort, it won't permanently do anything because its not resorting the array. Also putting rsort after the natsort will do away with the natsort. It doesn't seem too bad now, and maybe it was just my connection, but is there a better way I should do this?
|
# ? Apr 16, 2008 22:26 |
|
awdio posted:Yeah I see that, but even if I put the array_reverse($files) after natsort, it won't permanently do anything because its not resorting the array. Also putting rsort after the natsort will do away with the natsort. Read the docs. array_reverse returns the reversed array. You'll need to do $files = array_reverse($files);.
|
# ? Apr 16, 2008 22:35 |
|
duz posted:Read the docs. array_reverse returns the reversed array. You'll need to do $files = array_reverse($files);. Well that was all too obvious. Thanks. I probably would have thought to do that after taking a break, but yes it does work a bit faster.
|
# ? Apr 16, 2008 22:56 |
|
Here's a reasonably silly question: I'm writing a script that fetches data from a MySQL database and displays it. Instead of directly writing each row to the screen after I've read it from the database (with mysql_fetch_assoc()), I'm thinking of storing the data in a two-dimensional array where data[0]['id'] would be the value of the column named "Id" in the first row. I'm doing this so I can use the data in the table for other things, like exporting it to an excel or text file, without traversing the table every time. The problem is that the table has 14 columns, and thousands of rows. The average query will return about 2.000 rows. So that's an array with around 30.000 strings, and quite possibly a lot more. I'm not too experienced with PHP, is an array this big a silly thing to do? How big is too big?
|
# ? Apr 16, 2008 23:41 |
|
Without setting a cookie, session or global variable, I need to pass a variable from index.php to a PHP script included as an image. eg php:<? // index.php global $inIndex = true; [code] <img src='showImage.php?param1=yay¶m2=wee'> ?> php:<? // showImage.php global $inIndex; if ($inIndex == true) { //show real image } else { //show fuckoff.jpg } ?>
|
# ? Apr 16, 2008 23:51 |
|
Zedlic posted:The problem is that the table has 14 columns, and thousands of rows. The average query will return about 2.000 rows. So that's an array with around 30.000 strings, and quite possibly a lot more. It depends what problem you are trying to solve and what resources you have in greatest abundance. The situation that I've encountered large arrays in most is when creating reports from large amounts of data; in this case I would say yes, if it's going to save you a few massive queries or expensive joins, do it. But if this is something you want to do every time someone loads a page on your website then you might have a problem. Try it out by running your script and printing out the value of get_peak_memory_usage() at the end, to see how much memory it used.
|
# ? Apr 17, 2008 00:00 |
|
Safety Shaun posted:Without setting a cookie, session or global variable, I need to pass a variable from index.php to a PHP script included as an image. I'm not quite sure but I think you are trying to prevent hotlinking: Check the value of $_SERVER['HTTP_REFERER'] and deny access if: a: There is a url, AND: b: The address in that URL is not your website (I don't think you can safely rely on an accurate referrer always being present).
|
# ? Apr 17, 2008 00:13 |
|
Mashi posted:Check the value of $_SERVER['HTTP_REFERER'] and deny access Ahh yes of course, thank you. If nobody chimes in with the way I originally planned I'll do that.
|
# ? Apr 17, 2008 00:22 |
|
Safety Shaun posted:Without setting a cookie, session or global variable, I need to pass a variable from index.php to a PHP script included as an image. This is technically what you asked for :P php:<? [code] $inIndex = 'true'; echo "<img src='showImage.php?param1=yay¶m2=wee&inIndex=$inIndex'>"; ?> php:<? // showImage.php if ( isset($_GET['inIndex']) && $_GET['inIndex'] == 'true') { //show real image }else{ //show fuckoff.jpg } ?> Lumpy fucked around with this message at 03:33 on Apr 17, 2008 |
# ? Apr 17, 2008 03:30 |
|
Safety Shaun posted:Ahh yes of course, thank you.
|
# ? Apr 17, 2008 05:24 |
|
Php noob. I built an html form with some mandatory fields with an i-frame "status" window at the bottom. On submit, the script fires in the i-frame and checks for proper date formats, empty values, etc. and either alerts the user to missing data, or says "Record successfully entered". The frame is helpful because if there are mistakes they can just fix the error and hit submit without hitting back or refilling the whole thing. Is there a way to have the php script either blank the form on a successful submit, or redirect everythiong to a full "record successfully entered" page? Because as it stands now people can keep clicking submit and load up my db with dupes. PowderKeg fucked around with this message at 16:51 on Apr 17, 2008 |
# ? Apr 17, 2008 16:32 |
|
What you are doing seems to make no sense. It seems like you are using an i-frame to mock up browser side validation that javascript was made for. As for the question, yes, there is, you can do a header redirect to redirect the page after the processing is finished, but if you add JS form validation, and have the form action submit to a processing page that displays the thank you after it's done, you won't need that.
|
# ? Apr 17, 2008 17:43 |
|
PowderKeg posted:Is there a way to have the php script either blank the form on a successful submit, or redirect everythiong to a full "record successfully entered" page? Because as it stands now people can keep clicking submit and load up my db with dupes. The form should probably submit to the page it's on, then in the PHP on that page, have it redirect to a success page if all goes well after submitting (like here).
|
# ? Apr 17, 2008 23:04 |
|
gibbed posted:Also suggesting use of glob() instead of the opendir crap. Okay, glob is way better you're right. Gets rid of a lot of code and I don't have to tell it to open or close the directory. Definitely using this from now on. Thanks.
|
# ? Apr 19, 2008 06:52 |
|
Well I've bought a game engine on an impulse buy. Unfortunately the project was not really active and while they sold me the game very fast, they never responded to my information requests after they had my money (the engine is the VPet v3.0). The engine is full of bugs and incomplete, so I've been editing it to make it work. The problem is I'm a veterinarian with absolutely no coding experience. PHP seems logical enough and I've already managed to implement a player vs player system (yay me) but I'm having trouble with a lot of stuff (and spending hours to discover that php had problems with "" and '' was not much fun). The game can be found at https://www.bazul.org/rpg (it's partially in portuguese so not very interesting for you guys). The problems I'm having right now: 1-The enemy player table is too big (http://www.bazul.org/rpg/battle_pvp.php?game=1). I want it to only return 20 results and the others would have a "next page" "previous page" link. This is my code (and don't laugh at me I have no idea what I'm doing!) php:<? $getEnemies = mysql_query("SELECT * FROM user_pets2 WHERE 1 > '0' AND game = '$game' ORDER BY two_p_wins DESC, two_p_loses ASC"); echo" <link href='/rpg/pretty.css' type='text/css' rel='stylesheet'> <table summary=' ' width='95%' border='0'> <tbody><tr> <th scope='col' width='23%' align='left'><strong>Pet Name</strong> </td> </th> <th scope='col' width='11%' align='left'><strong>Level</strong> </th> <th scope='col' width='13%' align='left'><strong>Strength</strong> </td> </th> <th scope='col' width='11%' align='left'><strong>HP</strong></th> <th scope='col' width='11%' align='left'><strong>Wins(PvP)</strong> </td> </th> <th scope='col' width='13%' align='left'>Losses(PvP)</th> <th scope='col' width='9%' align='left'><strong>Owner</strong></th> <th scope='col' width='9%' align='left'><strong>Fight</strong></th> </tr> "; $x = 0; while ($array = mysql_fetch_array($getEnemies)) { $id = $array[id]; $y = $x % 3; if ($y == 0) { echo "<tr width=100%>"; } $getOwner = fetch("SELECT * FROM members2 WHERE id = '$array[owner]' AND game = '$game'"); echo " <tr><td valign='top'><b>$array[name]</b></td><td valign='middle'>$array[level]</td><td valign='bottom'> $array[strength]</td><td valign='middle'>$array[max_hp]</td><td valign='middle'>$array[two_p_wins]</td> <td valign='top'>$array[two_p_loses]</td><td valign='top'>$getOwner[username]</td> "; if ($userid != $array[owner]) { echo" <td valign='top'><a href=battle_pvp.php?game=$game&id=$array[id]&act=prestart>Challenge</a></td></tr>"; } if ($userid == $array[owner]) { echo " <td valign='top'>Own Pet </td></tr> "; } if ($y == 2) { echo "</tr>"; } $x++; } echo "<tbody></table></p>"; ?> Thanks! LastCaress fucked around with this message at 10:55 on Apr 19, 2008 |
# ? Apr 19, 2008 10:51 |
|
I am dumb and I am amazed I have never hit this problem before.php:<? if (! $disable_field) { foreach ($form as $field) { if (array_key_exists('disabled', $field)) { unset($field['disabled']); }; # If I print_r $field here 'disabled' is gone! Yay! }: }; # If I print_r here 'disabled' is not gone wtf! ?> edit: ok, I sort of understand what is going on here. $field is a copy of the data in $form. I am just used to reading through arrays or copying relevant stuff into new ones, I guess this is the first time I have actually tried to edit them. So could I not do unset($form[$field]['disabled']) in place of my current unset()? It isn't working either! edit 2: o snap php:<? if (! $disable_field) { foreach ($form as $fieldname => $field) { if (array_key_exists('disabled', $field)) { unset($form[$fieldname]['disabled']); }; }: }; ?> other people fucked around with this message at 18:01 on Apr 19, 2008 |
# ? Apr 19, 2008 17:38 |
|
Well, I have no idea what VPet is like.LastCaress posted:I want it to only return 20 results and the others would have a "next page" "previous page" link. This is my code (and don't laugh at me I have no idea what I'm doing!) For what it's worth, you could combine your select in the loop with the original query by joining the members2 table on user_pets2.owner = members2.id. You can achieve a limited range of return results with LIMIT $a, $b at the end of the statement where $a is the lower limit, and $b is how many you want. So taking your original query of code:
code:
----------------------------------------------- I just started working with CakePHP (and the whole MVC thing), and I was wondering how to access a model from within a component. MVC Class Access Within Components talks about how to get access to the controller, but if I'm using the component from some other controller it also doesn't necessarily have access to the model I want. Am I going about this in the wrong way, or is there some way to solve this? (apart from the hackish / bad php:<? include_once("../../cake/libs/model/model.php"); include_once("../app_model.php"); include_once("../models/modelIWant.php"); ?> opblaaskrokodil fucked around with this message at 08:04 on Apr 20, 2008 |
# ? Apr 20, 2008 07:27 |
|
Sorry, double posted it.
|
# ? Apr 20, 2008 07:39 |
|
Well the 1<0 condition was probably when I just started and was removing other code so I guess that was left behind... The limit thing worked, thanks! EDIT : Damnit, now I realized a part of the code doesn't work with PHP5, I'm going to have to convert it to php5 and have no idea how. I just hope it's not that different :\ LastCaress fucked around with this message at 22:24 on Apr 20, 2008 |
# ? Apr 20, 2008 11:42 |
|
LastCaress posted:Well the 1<0 condition was probably when I just started and was removing other code so I guess that was left behind... The limit thing worked, thanks! Which part doesn't work? PHP5 is generally pretty similar to PHP4 (in that most PHP4 stuff should work fine in PHP5). (also I got my question answered @ the cakePHP google group, so I guess I don't need an answer for that anymore)
|
# ? Apr 21, 2008 10:12 |
|
As I said, my coding experience is null. I can run the server in php4 and the code has no problem, and when I put it in php5 there are problems, so obviously the problem is there. The following code:code:
Parse error: syntax error, unexpected T_PRIVATE, expecting ']' in /home/virtual/site19/fst/var/www/html/rpg/club_join.pro.php on line 14 Now I guess what you need is that club.inc.php and the line is: code:
|
# ? Apr 21, 2008 16:17 |
|
You need to put quotes around associative array indices:php:<? if ($getclub['private'] == 1) { // ... } // ... if ($getmemberdata4['id']) { // ... } ?>
|
# ? Apr 21, 2008 16:20 |
|
Not really sure this belongs here or the python thread, but whatever. I'm learning python on the sides and I'm noticing some stuff. Basically, python will use a bunch of elifs instead of switches/cases (as far as the tutorial told me, and I hope it's right). This means there's no nead for 'break;', but it acts the same. However, I noticed that PHP doesn't require the break; to be syntactically right. So I could do: php:<? $x = 1; switch($x){ case 1: echo "woo"; case 2: echo "haa"; break; } //this echoes 'woohaa' ?> (I also found http://simonwillison.net/2004/May/7/switch/, but it doesn't say much about the possibility to move from statement to statement like I did in PHP) edit: fixed linking MononcQc fucked around with this message at 16:35 on Apr 21, 2008 |
# ? Apr 21, 2008 16:25 |
|
I'm pretty sure PHP is working "correctly", as it were, and python is wrong. You can exclude the break in just about any language and it acts the same as your PHP example, as far as I remember.
|
# ? Apr 21, 2008 16:31 |
|
noonches posted:I'm pretty sure PHP is working "correctly", as it were, and python is wrong. You can exclude the break in just about any language and it acts the same as your PHP example, as far as I remember. Alright, good to know, and also surprising it's not everything > PHP on this issue, like it seems to be about code-related things according to posts I read here.
|
# ? Apr 21, 2008 16:33 |
|
Inquisitus posted:You need to put quotes around associative array indices: Thanks, it worked, except for this line that doesn't return the clube name :\ code:
|
# ? Apr 21, 2008 16:36 |
|
LastCaress posted:As I said, my coding experience is null. I can run the server in php4 and the code has no problem, and when I put it in php5 there are problems, so obviously the problem is there. The "problem" is that PHP5 has increased security and since the code is poorly written, it's getting tripped up.
|
# ? Apr 21, 2008 16:37 |
|
|
# ? May 15, 2024 03:49 |
|
LastCaress posted:Thanks, it worked, except for this line that doesn't return the clube name :\ Because it needs to be $getclub['name'] you've left out the quotes again. You have to use ' ' here rather than " " because of how the variable is called in the string.
|
# ? Apr 21, 2008 16:40 |