Everything posted by Rob G
-
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.
-
Help needed with XML (PHP)
The first SimpleXMLElement object created by the function is the root element of the XML document (in this case BrowseNodeLookupResponse) so you don't need to try to go into it. foreach ($pxml->BrowseNodes->BrowseNode->TopItemSet->TopItem as $item) { is all you need! The clue is in the errors. There are 4 of the "property from non-object" errors on that line, so count back from the last one you try to get to find the original broken bit!
-
PHP Version
All I meant was something like saving the current version along with the date it was last checked locally on the clients version, and then only checking once a day or something. If there's any kind of delay between remote servers, your visitors can be left sitting there while they talk to each other. Not a massive deal but still.
-
PHP Version
Yeah that sounds good! It also paves the way for other data updates from the main server if needed (like currency exchange rates or something) in the future. Remember any kind of remote connection can slow down the page though so be sure to cache the result in some way.
-
Information on text hover / dotted line?
I could be mistaken, but that sounds very much like something that javascript would have to be used for. Afraid I don't know of any scripts off hand that do that but it would be straight forward enough to do using a framework I should think.
-
Geolocate Postcode - Multiple Street Address Options
Hi, I think it's just called something like reverse post code lookup or something. Anyway, if you want a quick easy solution I've used Postcode Anywhere before and can vouch for the system being really simple to integrate. Doubt you'll find anything free though as mentioned above.
-
Best way to create e-commerce website?
In my short experience working for agencies, how it usually goes down is the client buries all evidence and denies they were ever hacked in the first place (no real way to track a fraud use back to their website directly anyway), the agency backs them up, and blames the hack on a very obscure security flaw and doesn't mention that they forgot to sanitise a mysql variable. That was an eye opener for me really, so thought I'd share. Anyway, back to the question at hand, I'm sorry to say that in e-commerce it actually does make a difference. While offering paypal as an option is a really good idea, I've found that conversion rates improve drastically with a decent custom checkout process, I assume because it increases confidence. That and client likes it as transactions are cheaper than PP! Sagepay offer various levels of integration which allow you to make it look like the site handles all credit card information, while they take care of most of the PCI compliance burden. There are also other gateways you can use. Most require some knowledge of back-end code though. If you don't know how to code PHP or something similar, another option would be to use a big old e-commerce system like magento (can take a while to learn in itself) for which you can get plugins which give sagepay integration straight away. Or team up with a developer.
-
PHP Version
Probably the easiest way is have a url on your main server which returns the latest version number, and you can just check whether the client's version number, which could be stored in a txt file or db depending how you update it, is the same or smaller etc.
- a Cleaner/Quicker way
-
a Cleaner/Quicker way
You can make it a bit easier to manage using arrays and loops to output things. If you need to output the links/images at different places throughout the site, it might be worth placing it in a function. Below is some very rough code which I haven't tested at all but I think will work. Hopefully gives you an idea of how you can use nested foreach loops at least to reduce duplicate code. The methods of setting up arrays are both very similar, I just put the different ones in for variation # Get users links $links = array(); $links[1] = $row['link1']; $links[2] = $row['link2']; # Types of links $validLinks = array ( 'facebook' => 'images/facebook.png', 'twitter' => 'images/twitter.png' ) foreach ($links as $link) { // set up the default image $imageSrc = 'images/website.png'; foreach ($validLinks as $type => $linkImageSrc) { // overwrite the default image with the correct one if found if (stripos($link, $type) !== false)) { $imageSrc = $linkImageSrc; // as we have now found the image we can stop looping over the validLinks break; } } // output the link with the chosen image echo '<a href="' . $link . '" >'; echo '<img src="' . $imageSrc . '" />' echo '</a>'; }
-
Stepped find and replace
You could also build it up as a set of SQL queries within excel by just swapping the columns, putting in the update table set part_number = ' in a column before the new number and copying it down for each row, then adding in the ' where part_number = ' in the column between the two numbers and again copying it down the rows, then finishing off the SQL statement with '; in a final column. Just save as a txt file which will give you a few extra tabs but I'm pretty sure you'll be able to just run that file as SQL.