|
Oh, I did substitute that as well, but I got the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/virtual/site19/fst/var/www/html/rpg/club_join.pro.php on line 30 Sorry, should've made it clear. EDIT : Ah, and I've corrected the way it updates member numbers, that was wrong as well.
|
# ? Apr 21, 2008 17:00 |
|
|
# ? May 15, 2024 12:45 |
|
MVC theory question: I'm currently playing around with the Propel ORM framework and trying to work out how best to integrate it into Kohana (an MVC framework). My question is how should I go about transforming Propel's generated data objects when they're passed through the controller and into the view? Leaving them as they are would be exposing details of the data layer to the presentation layer, but constructing a new object for each one seems completely over the top. Not sure how to proceed; please advise!
|
# ? Apr 21, 2008 17:01 |
|
Inquisitus posted:MVC theory question: When applying MVC, it is absolutely normal for the view to get state from a model object directly. If you want to expose some other interface than what your ORM provides, maybe read up on the adaptor pattern.
|
# ? Apr 21, 2008 18:50 |
|
LastCaress posted:Oh, I did substitute that as well, but I got the error: php:<? header(error("club.php?game=$game&clubid=$clubid","Thank you for joining $getclub[name]."));?> There are a couple of ways to fix it. You can either use string concatenation, so you would have php:<? header(error("club.php?game=$game&clubid=$clubid","Thank you for joining " . $getclub['name'] . "."));?> php:<? header(error("club.php?game=$game&clubid=$clubid","Thank you for joining {$getclub['name']}."));?> opblaaskrokodil fucked around with this message at 20:06 on Apr 21, 2008 |
# ? Apr 21, 2008 19:56 |
|
opblaaskrokodil posted:Edit: Why is that an error call within a header call anyway? I'm not familiar with VPet, but it seems like a weird thing to be doing It probably returns a Location: header.
|
# ? Apr 21, 2008 20:08 |
|
LOL AND OATES posted:It probably returns a Location: header. I guess it could be urlencoding the second param of error and appending that to the redirect URL or something then printing it out @ that page. Otherwise I don't know what the second param is for, since you can't print it out on the current page without loving up sending headers?
|
# ? Apr 21, 2008 20:12 |
|
opblaaskrokodil posted:Otherwise I don't know what the second param is for, since you can't print it out on the current page without loving up sending headers? As far as I know, PHP won't send the HTTP header until it reaches the first HTML templated area or echo statement (or printf or whatever), so he's fine as long as it's not being set after one of these conditions gets met. Still, there's no need to set the header more than once, so the code should probably use elseif statements instead to make sure no more than one of these conditions gets evaluated as true at the same time: php:<? if ($getclub['private'] == 1) { die(header(error("club.php?game=$game&clubid=$clubid","You can't join a private club."))); } elseif ($clubrank > 0) { die(header(error("club.php?game=$game&clubid=$clubid","You are already a member of this club."))); } elseif ($getmemberdata4['id']) { die(header(error("club.php?game=$game&clubid=$clubid","You are already a member of a club."))); } ?>
|
# ? Apr 21, 2008 20:28 |
|
For some reason I cannot remember how to do this, or at least I swear that I had to do this for that PHP class I took a few years back... So we have a trouble ticket system at my work that is written in PHP, and they want me to add some fields to the form. They want something like: php:<? echo "is this a new instance? <INPUT TYPE=CHECKBOX NAME=instance>"; //HOW THE gently caress DO YOU DO THIS PART if (instance == checked) { echo "more input fields"; ... } echo "<input type=submit name=submit>"; ?>
|
# ? Apr 21, 2008 20:37 |
|
The variable you're checking for is $_POST["instance"] (or $_GET["instance"] depending on the form action) and its value is probably true if checked and false if not. I'm not 100% on this, so you might want to check by slipping in an echo $_POST["instance"]; in there somewhere and see what displays in your browser. Also, I recommend using HTML templating instead of echo statements wherever possible, as it allows HTML sections to get context highlighted properly in editors such as Notepad++ and you don't have to explicitly state line breaks with "\n". The end result is something like this: php:<? is this a new instance? <input type="checkbox" NAME="instance" /><br /> <?php if ($_POST["instance"] == true) { ?> more input fields<br /> <?php } ?> <input type="submit" name="submit" /><br /> ?> noonches posted:I sounds like Jimix is trying to do it dynamically after the page loads based on user actions. In other words Javascript. Yeah, if you're trying to make form fields appear in real time, just to it on the client side with Javascript. Zorilla fucked around with this message at 21:03 on Apr 21, 2008 |
# ? Apr 21, 2008 20:44 |
|
I sounds like Jimix is trying to do it dynamically after the page loads based on user actions. In other words Javascript.
|
# ? Apr 21, 2008 20:48 |
|
Zorilla posted:As far as I know, PHP won't send the HTTP header until it reaches the first HTML templated area or echo statement (or printf or whatever), so he's fine as long as it's not being set after one of these conditions gets met. Still, there's no need to set the header more than once, so the code should probably use elseif statements instead to make sure no more than one of these conditions gets evaluated as true at the same time: What I was wondering about was where it was going to display to the user, for example, 'You are already a member of this club'. --- Jimix posted:So we have a trouble ticket system at my work that is written in PHP, and they want me to add some fields to the form. They want something like: Nevermind, the one below is a lot cleaner looking. opblaaskrokodil fucked around with this message at 20:53 on Apr 21, 2008 |
# ? Apr 21, 2008 20:48 |
|
Jimix posted:For some reason I cannot remember how to do this, or at least I swear that I had to do this for that PHP class I took a few years back... If I am understanding you, you do not want PHP for this, you want javascript. code:
|
# ? Apr 21, 2008 20:51 |
|
I guess I just imagined writing something like what I had in mind in PHP, thanks for your help everybody!
|
# ? Apr 21, 2008 21:06 |
|
Or better yet, using event handlers and DOM writing (no idea if this exact code works, but you get the idea):code:
Zorilla fucked around with this message at 22:46 on Apr 21, 2008 |
# ? Apr 21, 2008 21:09 |
|
Zorilla posted:The variable you're checking for is $_POST["instance"] (or $_GET["instance"] depending on the form action) and its value is probably true if checked and false if not. I'm not 100% on this Checkboxes will not appear in _GET/_POST if they are not checked. If they are checked, they will contain the contents of the value attribute. I don't know what they contain if there is no value attribute.
|
# ? Apr 21, 2008 21:26 |
|
opblaaskrokodil posted:
This returns "Thank you for joining ." (maybe there's still a mistake in club.inc.php? opblaaskrokodil posted:
Returns the same. Vpet was a very incomplete game engine that I bought on an impulse (well not that expensive) and seems like an abandoned project. EDIT: Well, I put this: $waga = 'lol'; header(error("club.php?game=$game&clubid=$clubid","Thank you for joining $waga")); which returned : Thank you for joining lol So I guess the problem lies somewhere in the club.inc.php file :\ EDIT 2: I tried putting the $getclub = mysql_query("SELECT * FROM clubs2 WHERE id = '$clubid' AND game = '$game'"); inside the club_join.pro.php but didn't work. So instead of mysql_query i put "fetch" . Don't ask my why, I had seen it in other parts of the code. It worked! So I put it in the club_inc and it didn't work. I don't get this at all :| EDIT 3: Maybe that header thinggie doesn't have access to the club_inc stuff? EDIT 4: I think I found the problem. The original was: php:<? $getclub = mysql_query("SELECT * FROM clubs2 WHERE id = '$clubid' AND game = '$game'") or die (mysql_error()); if (mysql_num_rows($getclub) == 0) { die(header(error("club.php?game=$game","This is not a real club."))); }?> LastCaress fucked around with this message at 22:56 on Apr 21, 2008 |
# ? Apr 21, 2008 21:29 |
|
duz posted:Checkboxes will not appear in _GET/_POST if they are not checked. If they are checked, they will contain the contents of the value attribute. I don't know what they contain if there is no value attribute. They return "on". Checking for a value is unecessary unless you're using that value for some processing, if it's just a flag, on should work.
|
# ? Apr 21, 2008 21:45 |
|
hey so i'm working on my first php website and i've run into a problem with sessions. index.php includes login.php login.php is a basic username, password and login button. it does various checks to see if the user exists, if the passwords are correct. here is the part of the code i create the session. i set two variables (logged in, and uname) as session varibles than load the table of contents for the user. php:<? if(md5($_POST['pword']) == $row[0]){ //if they do, log the user in session_start(); $_SESSION['loggedIn'] = true; $_SESSION['uname'] = $_POST['uname']; include "usertoc.php"; ?> php:<? <p> <?php print "<a href=\"user.php?uname=" .$_SESSION['uname']. "\">My Profile</a><br />"; ?> Add Data<br /> Search<br /> Browse<br /> <hr width="85%" size="1px" color="#735511"/> <a href="logout.php">Logout</a><br /> </p> ?> user.php php:<?php //figure out which link bar to include if(isset($_SESSION['loggedIn'])) include "usertoc.php"; else include "toc.php"; ?>
|
# ? Apr 21, 2008 23:12 |
|
LastCaress posted:EDIT 2: php:<? $resource = mysql_query("SELECT * FROM clubs2 WHERE id = '$clubid' AND game = '$game'"); $getclub = mysql_fetch_array($resource); ?>
|
# ? Apr 21, 2008 23:32 |
|
Possym posted:It includes toc.php every time! I'm not experienced with sessions at all, did I do something to mess it up on accident? Are you running session_start(); before you start messing with sessions or outputting anything?
|
# ? Apr 21, 2008 23:57 |
|
duz posted:Are you running session_start(); before you start messing with sessions or outputting anything? i don't really understand. after the login verifies, that is when i use session_start(). i don't output anything. the flow is like this: -index.php includes login.php -from index.php i write my username and password and hit login. --the code verifies the info is right and starts the session. it assigns two session variables some values. -it reloads page with usertoc.php in the place of login and renders the dynamic link based on a session variable correctly. -when i go to the user.php page from the link the session variables are null. it's strange to me that the session variables when i click on one link, but for another they aren't.
|
# ? Apr 22, 2008 01:07 |
|
Possym posted:i don't really understand. after the login verifies, that is when i use session_start(). i don't output anything. If I had to guess, I'd say you aren't running session_start() first on user.php. session_start() has to be the first thing output, so it's best to just put it as the first line of code, or in an include thats on the top of every page.
|
# ? Apr 22, 2008 01:12 |
|
thank you so much. I put session_start on the top of all the pages and it's working now!
|
# ? Apr 22, 2008 01:24 |
|
I need to generate XML with a PHP script, but I'm unsure of the best method from a performance perspective. Can anyone give me some advice or point me at a resource that I can read more on the topic? EDIT: Is the most common way to just foreach and echo XML tags? Snozzberry Smoothie fucked around with this message at 02:56 on Apr 22, 2008 |
# ? Apr 22, 2008 02:47 |
|
A session question of my own: how do I get them to persist between browser sessions? The top of my login page looks like this: (check_login() retuns true, false, or "admin" depending on outcome of username/password combo) php:<? session_start(); if (!(@$_POST["submit"])) { session_destroy(); } else { $userstatus = check_login(@$_POST["username"], @$_POST["password"]); if (!$userstatus) { $error = "Invalid username or password."; } else { $_SESSION["loggedin"] = true; if ($userstatus == "admin") { $_SESSION["isadmin"] = true; } header("Location:index".PAGE_EXT); } } ?> And pages you can only access after being logged in look like this: php:<? session_start(); if (@$_SESSION["loggedin"] != true) { header("Location:login".PAGE_EXT); } ?> I've tried setting cookie timeout, but that has no effect. Zorilla fucked around with this message at 04:23 on Apr 22, 2008 |
# ? Apr 22, 2008 04:21 |
|
Snozzberry Smoothie posted:I need to generate XML with a PHP script, but I'm unsure of the best method from a performance perspective. Can anyone give me some advice or point me at a resource that I can read more on the topic? Here's the DOM approach to XML: http://www.ibm.com/developerworks/library/os-xmldomphp/ Or you could do something like this: php:<?php $items = array("stuff", "more stuff", "holy crap here's some more stuff", "boopty boop"); ob_start(); ?> <stuff> <?php foreach ($items as $item) { ?> <item><?php echo $item; ?></item> <?php } ?> </stuff> <?php $xmldata = ob_get_contents(); ob_end_clean(); $file = fopen("items.xml", "w"); fwrite($file, $xmldata); fclose($file); ?> Both methods are probably blazing fast, but this probably has less overhead from not loading any classes - not that it matters for such a tiny task. Zorilla fucked around with this message at 05:26 on Apr 22, 2008 |
# ? Apr 22, 2008 04:45 |
|
Zorilla posted:A session question of my own: how do I get them to persist between browser sessions? The top of my login page looks like this: You'd need to set a cookie explicitly, a cookie timeout only works on an actual cookie, not a session. I usually set a cookie with the value of some fields in the database hashed together, and have a separate login function that sets up the sessions if thats set and correct. noonches fucked around with this message at 05:02 on Apr 22, 2008 |
# ? Apr 22, 2008 05:00 |
|
noonches posted:You'd need to set a cookie explicitly, a cookie timeout only works on an actual cookie, not a session. Ok, I was trying using $_COOKIE in conjunction with $_SESSION without adjusting the default timeout value of "0" before giving up the first time, then only using $_SESSION when I tried setting cookie timeout the next time, so you can see why things didn't work. Looks like I've got a bit of modifications to do. noonches posted:I usually set a cookie with the value of some fields in the database hashed together, and have a separate login function that sets up the sessions if thats set and correct. If the cookie data is nothing but a hash, how does it carry information about who is logged in between browser sessions? Or are you saying you store this in addition to a username and password cookie? Zorilla fucked around with this message at 05:10 on Apr 22, 2008 |
# ? Apr 22, 2008 05:03 |
|
Snozzberry Smoothie posted:I need to generate XML with a PHP script, but I'm unsure of the best method from a performance perspective. Can anyone give me some advice or point me at a resource that I can read more on the topic? Use SimpleXML. It makes it so easy. Zorilla posted:Ok, I was trying using $_COOKIE in conjunction with $_SESSION without adjusting the default timeout value of "0" before giving up the first time, then only using $_SESSION when I tried setting cookie timeout the next time, so you can see why things didn't work. Looks like I've got a bit of modifications to do. Sessions expire when the browser closes or after 24 minutes of inactivity. What you want are cookies. The cookie will store a unique ID/hash that points to an entry in your database with the session information.
|
# ? Apr 22, 2008 09:02 |
|
duz posted:Sessions expire when the browser closes or after 24 minutes of inactivity. What you want are cookies. The cookie will store a unique ID/hash that points to an entry in your database with the session information. Ok, so this sounds like I actually have to create a MySQL table whose purpose is to store hashes that coordinate with remote users' cookies. Am I way off here? Zorilla fucked around with this message at 09:25 on Apr 22, 2008 |
# ? Apr 22, 2008 09:14 |
|
Is there a way to apply an external stylesheet file to just a table? I took a stylesheet from google and applied it to a table, but it transforms the style of the whole page :| Also, does anyone want to help me with designing a PvP system? I'll give a forums upgrade. Thanks!
|
# ? Apr 22, 2008 09:23 |
|
LastCaress posted:Is there a way to apply an external stylesheet file to just a table? I took a stylesheet from google and applied it to a table, but it transforms the style of the whole page :| Also, does anyone want to help me with designing a PvP system? I'll give a forums upgrade. Thanks! Cheap answer: put the table in a separate page and use an inline frame. Non-nerd rage inciting answer: give the table a unique class maybe, then make modifications to the stylesheet in question so that all styles apply to elements inside that table and to nothing outside it. For instance, change: code:
code:
Zorilla fucked around with this message at 09:30 on Apr 22, 2008 |
# ? Apr 22, 2008 09:27 |
|
Well the stylesheet can't possibly have been made by a human unless he took massive amounts of LSD : https://www.bazul.org/rpg/pretty.css Maybe this is overkill because I just want my table to look like this : http://www.bazul.org/rpg/battle_pvp.php?game=1 (login/pass bobin)
|
# ? Apr 22, 2008 09:40 |
|
Zorilla posted:Ok, so this sounds like I actually have to create a MySQL table whose purpose is to store hashes that coordinate with remote users' cookies. Am I way off here? Unless you want to store sensitive information in a cookie that's readable by anyone. The table could consist of just two columns, a session id and the serialized session data. It's really up to you how you want to do it.
|
# ? Apr 22, 2008 09:49 |
|
LastCaress posted:Well the stylesheet can't possibly have been made by a human unless he took massive amounts of LSD : https://www.bazul.org/rpg/pretty.css Yeah, Google optimizes the hell out of all their content, removing line breaks, spaces, and anything deemed to be dead weight. Have you seen their front page HTML? Standards compliancy be damned! The table you linked to is using legacy color definitions to achieve the look you want anyway. In CSS, you probably just want something like this: code:
Zorilla fucked around with this message at 09:55 on Apr 22, 2008 |
# ? Apr 22, 2008 09:51 |
|
Wow I'm glad this computer thing makes sense. I did a table.css with that code and added <table summary=' ' width='95%' border='0' class='myclass'> to the php and it works! Sorry for being obtuse some times, but this is the first time I'm playing with html/php/mysql
|
# ? Apr 22, 2008 15:20 |
|
LastCaress posted:Wow I'm glad this computer thing makes sense. I did a table.css with that code and added <table summary=' ' width='95%' border='0' class='myclass'> to the php and it works! Sorry for being obtuse some times, but this is the first time I'm playing with html/php/mysql Attributes like border= and width= are becoming deprecated. If you're going to define appearance inline, use the style= attribute, as it allows you to use the same CSS syntax you're using in your stylesheet. In your case, use something like <table class="myclass" style="width: 95%; border: none;"> That's just an example, and there aren't too many instances where you'll need to define styles inline instead of from a stylesheet, so everything I put in style="" should probably just go to table.myclass entry in your CSS. As with anybody messing around with CSS, I recommend installing Firebug so you can see changes to CSS properties in real time. (Get 1.1 Beta; 1.0 has a bug where it won't handle <a> tags properly). Zorilla fucked around with this message at 20:46 on Apr 22, 2008 |
# ? Apr 22, 2008 20:37 |
|
I'm having a problem with strpos() that I'm not sure how best to resolve. I've got a function that cycles through a string and looks for instances of months in the format of 'mon ', i.e. 'apr ', 'may ', etc. My problem occurs when testing for $curPos - if a month occurs at the zero position of $str, then the test will fail when ideally it will recognize a month is there for further processing. Since zero evalutes to false, it fails even though I can tell the difference between a month that never occurs and a month at the zero position - I just can't test for it. The only workaround I have is to concat a blank space at the beginning of $str to bump the whole thing forward one character. Any ideas how to tell the difference between a string NOT found by strpos as opposed to one found at the beginning of the string? php:<?php $months = array (1 => 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'); function FindMonthPosition($str) { global $months; print "$str\n"; $curPos; foreach($months as $month) { $curPos = strpos($str, "$month "); if($curPos) { print "$month, $curPos\n"; } } } ?>
|
# ? Apr 23, 2008 01:04 |
Grigori Rasputin posted:Since zero evalutes to false, it fails even though I can tell the difference between a month that never occurs and a month at the zero position - I just can't test for it. http://us3.php.net/strpos php.net posted:Warning
|
|
# ? Apr 23, 2008 01:13 |
|
|
# ? May 15, 2024 12:45 |
|
Grigori Rasputin posted:I'm having a problem with strpos() that I'm not sure how best to resolve. I've got a function that cycles through a string and looks for instances of months in the format of 'mon ', i.e. 'apr ', 'may ', etc. PHP has powerful functionality for manipulating date and time formats. What is the end goal of this code?
|
# ? Apr 23, 2008 01:19 |