-
-
Multiple of 5
Hi! There are a few reasons it isn't working. It's worth turning on display of E_NOTICE errors in php.ini for your local dev environment as it helps spot some issues. OK so firstly, the ternary operator isn't usually used like that, though it will work. What you're after there is either: if (isset($_SESSION['count'])) { $_SESSION['count']++; } else { $_SESSION['count'] = 1; } or if you really wanted to use the ternary operator, it's usually used like: $_SESSION['count'] = (isset($_SESSION['count']) ? $_SESSION['count'] + 1 : 1); In this case, the if structure is much clearer so I'd suggest using that. The isset() is the proper way of checking if it exists, and not using it will generate a E_NOTICE error. The other issue is in PHP, all variables begin with a dollar sign so your second if statement should read: if (!($_SESSION['count'] % 5)) { echo "hello"; } Notice also that the brackets after the negative ! surround the entire calculation. This is important because otherwise you are applying the ! to only the first 5 (which evaluates to false as ints greater than 0 are converted to true) so you actually get 'false % 5', which after some int casting behind the scenes leaves you with (int) 0, always. It might actually be clearer to use the full expression if ($_SESSION['count'] % 5 === 0) { echo "hello"; } You could also, as Zed suggests, put the session variable in a local variable just to save you some typing each time such as: if (isset($_SESSION['count'])) { $count = $_SESSION['count']++; } else { $count = $_SESSION['count'] = 1; } And then use $count in your second if. Up to you, but hopefully all that helps you out a bit Good luck!
-
Parsing Tabs?
Not sure if it works with normal string functions in PHP, I think it does, but in REGEX at least (preg_match() and other functions) you can to use '\t'
-
Wordpress - PHP
You can set up your web server to parse .html files for php (allowing you to use includes), but then if you move files to a new server and forget, you end up leaving your php code in plain text essentially, which is rarely a good thing. Always use .php for publicly accessible php files. You can include any file you like within a php script, .txt or .pdf, and it will be parsed for possible php. Hope that makes sense
-
Wordpress - PHP
Yeah as mentioned above, there's no right or wrong way. More a matter of style really. Some people prefer always to drop out of PHP to do html and then use short tags (not really vital, but <?= instead of <?php echo just looks neater) for variables. I prefer this way as I find it can be easier to read/edit things this way if you have a lot of HTML output, and don't have to deal with escaping quotes etc. Others prefer to just include it in echos. just be consistent in each file at the very least so you don't have to check both places for HTML.
-
PHP not working in opera?
Got a visible link so we can see the full page? At a guess though, it could be some wierd HTML related issue because it looks like the PHP code you have does something like: if (something) { // close table tag } else { // don't close table tag, but output an unclosed img tag (<img src="" /> is how it should be really) } So could be that's what is throwing the spanner in the works as occasionally, or even always, you'll have broken HTML. W3 HTML validator will help you find all the issues.
-
php
Hey, I think your issue is that PHP parses the include path relative to the first file that does the including. I think this is because it puts included scripts into the scope where they were included from. So in this case I imagine you're including the header from somewhere else. Solution is to either use a absolute path, sort out your include path to include the main dir, or if all the files including header.php etc are in one directory, make it relative to that.
-
fopen and a parse error on </html>?
Yeah what Jock said! No worries though. We have all been caught out at some (many) points before If you're just learning, you might be interested in this series of tutorials which cover the various file functions amongst most other things you need to know. Have fun!
-
Insert values of Radio form into mysql
Hi, First off, always escape data you'r putting into a query string, unless you like getting hacked The reason it's not working is because the REQUEST array, along with GET and POST, is indexed by the 'name' attribute of the form element, not the ID. Also, ID attributes in html must always be unique on that page. The correct code (complete with mysql escape in place) is: $color12 = mysql_real_escape_string($_REQUEST['okay']); $sql = "INSERT INTO stylesheet VALUES ('$color12')";
-
fopen and a parse error on </html>?
From the php manual: If there's a parse error on a line outside of what should be PHP, it means that for some reason the close tag is missing, so look for things that could be eating it like here/now doc or /* comments.
-
Please I need help over a team work issue
Ah yeah sorry didn't read properly and kinda misunderstood Thought you didn't want them having access to the main DB cos it had sensitive data or something. I'd not heard of Liquibase before but it looks decent, and you'll probably need to use something like that. Definately use SVN or something as developers overwriting something you just spent 5 hours perfecting is not fun. Getting used to SVN is vital, so learn that first. Using OOP to keep table access limited to specific classes (eg User class is only one that makes use of the users and userPermissions tables etc) is the next step as it makes grouping code and DB changes together much easier. What I said before is still kind of relevant though. There can be real nightmares when you have multiple people doing work on the same area of code on the same DB. If you want to stick to one central DB you're going to have to update the dev copy after every commit to see any changes and apply DB changes at that time, which can be time consuming for testing code you've just written, especially if it breaks things, stopping all work for other developers too! Alternatively, if you have each developer with their own working copy (ie checkout of the SVN repository running on their own local webserver) but pointing to a central database, if they make any changes to the DB but haven't comitted their code cos it doesn't work just yet, then things could break badly for all other developers, again stopping all work. So multiple databases will make things a less painful if done right, and a tool like Liquibase might do the job. Regular SQL dumps would be the simplist probably, though not very nice to use. The set up I've used before had a central mysql server which had a series of dev databases on. Each developer was usually working on a different one (we had a DB per client but all used the same code base) so this worked. When a developer committed changes which used a modified DB schema, the SQL for the change was stored in a central list against the revision number, so that when doing SVN updates to live/staging servers, it automatically ran the SQL needed to keep everything working. The same happened for our working copies and dev databases, though triggered manually to help avoid schema conflicts. Communication is key.
-
Please I need help over a team work issue
You could get everyone to run their own dev server, including db, and every week or few days send out a SQL dump of the db you're working on. That way they all know what the schema is and can use it with whatever dummy data you provide.
-
MeetUp
Hey all, I'm in Chippenham which is quite near Swindon! I'm around London every couple of weeks at least though (usually for rock climbing or gigs). That conference looks interesting as I need to work on my design skills so may very well go. For those in wiltshire/bristol/bath area there's a thing gathering called Bathcamp, who host evenings in bath every month I think, though I've never actually managed to get to one! There's one on 1st September though, so maybe that could be an unofficial first meet?
-
Decoding gzip (using PHP sockets)
It's not cos of the read limit on the fgets call you've given is it?
-
Cookie Security
User agents can be played with and faked so shouldn't always be relied on. Also some browsers can change it for no reason *looks at IE* which can be a pain for your users. It's usual to store some kind of extra information in the cookie that can't be guessed easily, like a random key which you also save against the user and then check userID and this key each time they visit. That way even if someone used someone elses User ID and copied their user agent somehow in this case, they wouldn't know about their unique key so would definately fail!
-
-
PHP Security, Password/SHA1
It's probably best to escape all data with mysql_real_escape_string or whatever just before putting it into the query, just so if you change something later down the line so the sha1 happened in the SQL or something then there's no chance of forgetting to add in the escape. Not like you lose anything from doing it! The regex is pretty redundant then too.