Search found 792 matches

by hyper
Tue Mar 12, 2019 2:52 pm
Forum: PHP coding => General
Topic: Help - Invalid argument supplied for foreach()
Replies: 1
Views: 27

Re: Help - Invalid argument supplied for foreach()

It looks like $rules is not iterable (can't be used in a foreach loop)

try

Code: Select all

echo gettype ($rules);
to see what you've got.
by hyper
Tue Mar 12, 2019 2:42 pm
Forum: PHP coding => General
Topic: form validation using form from include () file
Replies: 5
Views: 61

Re: form validation using form from include () file

Include it using the path to the file or replace the echo with the code you want instead. There is no good reason to use $_SERVER["PHP_SELF"], as I said, learn the directory structure and use $root as shown above, you should already know which file is going to process the form and which files will b...
by hyper
Tue Mar 12, 2019 1:12 pm
Forum: PHP coding => General
Topic: form validation using form from include () file
Replies: 5
Views: 61

Re: form validation using form from include () file

$_SERVER['DOCUMENT_ROOT'] is the full address of your web address from your systems point of view, which is probably to public_html on your system - not all set ups use public_html - by using $_SERVER['DOCUMENT_ROOT'] you can ignore what your path is when developing on one system and then uploading ...
by hyper
Tue Mar 12, 2019 8:46 am
Forum: PHP coding => General
Topic: form validation using form from include () file
Replies: 5
Views: 61

Re: form validation using form from include () file

Your path is wrong, which is why the file can't be found. I use $_SERVER['DOCUMENT_ROOT']: $root=$_SERVER['DOCUMENT_ROOT']; include "$root/retail/pm_form.php"; Don't bother with $_SERVER["PHP_SELF"], just use $root and set the rest of the path: "$root/frm/frm-pm.php"; Warning: PHP doesn't guarantee ...
by hyper
Sat Mar 09, 2019 1:34 pm
Forum: PHP coding => General
Topic: Why PHP is better than Java?
Replies: 2
Views: 45

Re: Why PHP is better than Java?

Java and JavaScript are completely different languages. A CMS is not exclusive to PHP, there are no language constructs which are exclusive to PHP which mean that it is the only language that you can write a CMS in. JAVA provides database connectivity. JAVA and PHP are cross platform. Any program th...
by hyper
Mon Feb 11, 2019 1:57 pm
Forum: PHP coding => General
Topic: Storing a database value as a SESSION VAR
Replies: 1
Views: 87

Re: Storing a database value as a SESSION VAR

Sessions can be used for storing a name or anything else you need, only store what you need. It's a bad practice to pull information from a database unless you need it. 'SELECT * FROM Members' will pull everything and storing it all in sessions will place a heavier un-necessary load on the server. Y...
by hyper
Sat Feb 09, 2019 11:19 am
Forum: PHP coding => General
Topic: Print correct dates in PHP
Replies: 7
Views: 246

Re: Print correct dates in PHP

I meant to state on my last post:

Well done for giving it a go!
by hyper
Sat Feb 09, 2019 6:58 am
Forum: PHP coding => General
Topic: Print correct dates in PHP
Replies: 7
Views: 246

Re: Print correct dates in PHP

I don't know what you're expecting, are you trying to learn PHP and want some help? the switch statement, "switch" happens to be effective than several 'if, else if" Correct, but irrelevant, there are more efficient and user friendly ways that don't involve writing pages of variables, ifs or cases. ...
by hyper
Sat Feb 09, 2019 2:36 am
Forum: PHP coding => General
Topic: migrate to different php version
Replies: 2
Views: 114

Re: migrate to different php version

The bit after: PHP Warning: fclose() expects parameter 1 to be resource, boolean given in will give you the file name and line number to look at: fclose ( resource $handle ) you have not given a file handle (the one created using fopen) Whenever you get an error, read it; as it gives you where to lo...
by hyper
Fri Feb 08, 2019 9:28 am
Forum: PHP coding => General
Topic: Print correct dates in PHP
Replies: 7
Views: 246

Re: Print correct dates in PHP

You have quite a few problems in that code. I can't work out how any of it works as the switch statement can only have one result? Your foreach loops don't do anything if they find a weekend day. I suggest that you re-think how you want to achieve the end result as the way you are going about it can...
by hyper
Thu Feb 07, 2019 11:48 am
Forum: PHP coding => General
Topic: Join 2 php files
Replies: 2
Views: 132

Re: Join 2 php files

You've got the path wrong and PHP can't find the file you want, which is why it gave the error. Try php/remainder.php leaving the / off the address, I can't be sure of this since I don;t know your file structure; however I'm quite certain that you do not have a directory at the root of your file sys...
by hyper
Tue Feb 05, 2019 12:14 pm
Forum: PHP General
Topic: Refactor short code snippet
Replies: 1
Views: 121

Re: Refactor short code snippet

If you want to improve your code, just keep writing it rather than analysing every line as soon as you've written four. You'll find that you will change the way you code as you go along and read others code. So far as programming practices is concerned, here are some guidelines which might prove use...
by hyper
Thu Jan 31, 2019 10:28 am
Forum: PHP coding => General
Topic: Hiding passwords
Replies: 6
Views: 275

Re: Hiding passwords

So long as you only use the variable for the connection, no-one will see it.

As chorn says you can put your connection file outside of the web root.

You would also improve overall security if you change from MYSQLi to PDO using prepared statements.
by hyper
Wed Jan 30, 2019 4:30 pm
Forum: PHP coding => General
Topic: Hiding passwords
Replies: 6
Views: 275

Re: Hiding passwords

You're correct that nothing is 100% safe, however, you can adopt strategies which will make it more difficult. For instance, make sure that any file requested is executed. This may just be as simple as having the file's extension as .php, this will ensure that any file requested is executed as a php...
by hyper
Fri Jan 18, 2019 5:02 am
Forum: PHP General
Topic: Security of "require" and global $var;
Replies: 8
Views: 374

Re: Security of "require" and global $var;

just not so confident right now Good, you're making progress. It's not about making you feel stupid, you're not; it's about making sure that the script is doing what you think it is doing and that there are not any side effects or potential pitfalls; it will come with experience. It is really a min...
by hyper
Thu Jan 17, 2019 11:31 am
Forum: PHP General
Topic: Security of "require" and global $var;
Replies: 8
Views: 374

Re: Security of "require" and global $var;

Do not assume anything. The reason all security flaws have been exploited is because it was assumed ... The script snippet that you have shown, does not mean your site will be secure. Using prepared statements and binding values should only be part of your security measures and user input validation...
by hyper
Thu Jan 17, 2019 9:12 am
Forum: PHP General
Topic: Security of "require" and global $var;
Replies: 8
Views: 374

Re: Security of "require" and global $var;

I can't answer your post as I've no idea what your post is trying to say, I can only give basic information based on this part of your second post: I mean there is not "outside" way to pre-load the variables, right? No-one can assign variables that are assigned in your script (from the outside world...
by hyper
Mon Jan 14, 2019 12:21 pm
Forum: PHP coding => General
Topic: file_get_contents with preg_match
Replies: 3
Views: 243

Re: file_get_contents with preg_match

Nobody? :help: This isn't the most active site, so you may have to wait a bit longer for a reply, although you may not get one at all as your post doesn't make a lot of sense: with preg_match Dont waste time with regex ???? For starters, you could do with spending a bit of time reading your own pos...
by hyper
Sun Jan 13, 2019 10:04 am
Forum: PHP coding => General
Topic: date_diff
Replies: 3
Views: 215

Re: date_diff

I don't know which version of MySQL you are using, but I'm sure3 that you can gather from this what to do https://dev.mysql.com/doc/refman/5.5/en ... tions.html
by hyper
Thu Jan 10, 2019 8:17 am
Forum: mySQL & php coding
Topic: Session Management for Page Access
Replies: 1
Views: 264

Re: Session Management for Page Access

You've made a good effort, so don't take this the wrong way: You have a mis-match of brackets { }. Your if - elses are messy and the elses are not needed since the script re-directs on failure You should exit the script if you are changing the header if ($_SESSION['logged_in'] != 1 ) { $_SESSION['me...
by hyper
Fri Jan 04, 2019 1:18 pm
Forum: PHP coding => Images
Topic: Black and white background with GD library
Replies: 2
Views: 220

Re: Black and white background with GD library

On another note, if your background is transparent, you can change the background by using css, i.e. by changing the background colour of the page that the image is on.