-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
How to create a select query calculating 'age' by user's date of birth?
Ch0cu3r replied to thara's topic in PHP Coding Help
First don't use varchar for storing dates, set your dob field to use DATE type. Then you can use MySQL's DATE aggregate functions. Example SELECT ... FROM users WHERE YEAR(NOW())-YEAR(dob) BETWEEN $minAge AND $maxAge -
Sessions? How to secure pages for only logged in users
Ch0cu3r replied to FatesCall's topic in PHP Coding Help
I guess you are referring to the "Error: Username or Password is incorrect!" being shown when you load your login form. This is showing because PHP is checking the username/password without the form being submitted. You only want PHP check the username/password when the form has been submitted. To do so you can wrap the if ($user && $password) block of code within another if statement which checks to see if a POST request has been made. Example // Only check the username/password when on POST request if($_SERVER['REQUEST_METHOD'] == 'POST') { $user = trim($_POST['user']); $password = trim($_POST['password']); if($user && $password) { ... check username/password here ... } } -
In order for PHP to send emails with mail() you need to tell PHP your SMTP email server address/port in the php.ini. However the mail() function does not support SMTP servers which require authentication. If your SMTP server does requires authentication then look into using PHPMailer instead.
-
@NotionCommotion as Barand mentioned usual cause is magic quotes, which auto escapes quotes within user input variables such as $_GET, $_POST etc. @rwigs rather than do it in your query have you tried using stripslashes when you output the results from your query? The best way to prevent this is to first find out why backslashes are being added to the quotes when inserted into your database. Barand has highlighted one possible case, another case (which I hope is not true) is the use of addslashes on the values being used in your insert query. This should never happen! If this is the case then you need to update your code to use MySQLi or PDO and use prepared queries
-
RewriteRule cannot capture the values in a querystring. You need to use a RewriteCond on the %{QUERY_STRING} server variable to capture the article_title query string value #below masks URL successfully to html #NOTE: the &r=0 query string param this is to prevent an infinite redirect loop RewriteRule ^a/(.*)/(.*)\.html$ /a/$1/?req=read&article_title=$2&r=0 [L] # redirect old url format to new .html format RewriteCond %{QUERY_STRING} ^req=read&article_title=([^&]*)$ [NC] RewriteRule ^a/(.*)/$ /a/$1/%1.html? [R=301,L]
-
Use number_format echo number_format($loadtime, 2); // output loadtime to 2 decimal places
-
It is up to you whether or not use the built in filters. You are free to write your own if you wish to do so. Thats fine for those methods. My comment was referring to your code comment for the email method it says $name is never used. Thats why I said if you are not going to use $name as an argument then there is no point in defining it as a argument for your email method
-
Yes you can use filter_var for validating user input, PHP has built in standard filters for validating user data listed here: http://php.net/manual/en/filter.filters.validate.php What i do not understand about your code is this protected function email($x,$true,$name) { //$name isn't used with the email method, but is used with other methods to return a response like "$name is not a bla" Why have $name as an argument if you are not going to be using it? I'm struggling to understand whats happening here. Whats with the !$true and !trim() and why return false when an email is valid? return (!$true || !trim($x) || filter_var($x, FILTER_VALIDATE_EMAIL) )?false:'Invalid email.';
-
Can you post your code for showing whats in the session?
-
wamp need to authenticate something with vhost.sourceforge.net
Ch0cu3r replied to Supervan's topic in Apache HTTP Server
This sounds to me something in your hosts file is overriding the localhost domain First open Notepad (As Administrator - right click Notepad and select Run as Adminstrator) now press Ctrl+O (or File > Open) in the filename box type the following path C:\Windows\System32\drivers\etc\hosts and press Open Delete the following line 127.0.0.1 vhost.sourceforge.net Save the hosts file and try accessing the http://localhost again If it still tries to go to that domain then there is some other software you have installed which is interfering. WAMP and XAMPP never try to access third party sites when you access localhost - the only time you are redirected to third party sites is if your click the links from their context menus. -
You use REPLACE for updating values within existing rows If are inserting a record but don't want duplicate records use INSERT IGNORE
-
Its not working for your second test because array_walk_recursive passes the key/value pairs as the 1st and 2nd arguments to the callback function. Also the value for the $character_mask will not be passed to the callback function either. You will need to pass it as the 3rd argument to array_walk_recursive, the character mask will then be available as the 3rd argument to the callback function. Also why does the trim routine need to be wrapped in a class? It would be better to do your trim routine within a function.
-
Make sure mod_rewrite is enabled in Apaches config. I'm guessing this is possibly why your download link is not working. To the author of the script WTF! global $_SERVER;
-
By Calc you mean OpenOffice Calc? Maybe this is what you are after? https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Calc_Guide/Speeding_up_data_entry
-
sloppy performance on win - which is the best tool to test the win
Ch0cu3r replied to dil_bert's topic in Miscellaneous
There is not much you can do with that spec unfortunately. If you do have money to spend then I would definatly recommend you add more memory, 2GB of memory is very low especially for a 64bit OS. You should have at least 4 GB or more. Depending on budget you could swap your mechanical harddrive for a 120GB solid state drive -
You have defined 4 functions but you never call them. Have a read of the following documentation for how to use functions properly http://php.net/functions
-
It would be nice if you explained your problem is. What you are code is supposed to do etc. Also when posting code please wrap it within tags (I have modified your post).
-
I should of also mentioned you can write your own error handler using set_error_handler. So if any PHP error occurred you can serve up a custom error page setting the error message dynamically. You can also set your own error messages using trigger_error. Where as the 500 Internal Server page would only be able to show a a generic error message - Although it is possible show dynamic error messages it just depends how your code handles errors. In which case you may as well write your own error handler.
-
It seems Firefox does not like having backslashes as the directory separator in the url for your images. <img src="images\banner2 EDIM VTC.png"> You should be using forward slashes as the directory separator in your urls <img src="images/banner2 EDIM VTC.png"> IE/Chrome is most likely auto correcting the urls for you. There are other issue, such as non standard HTML. <center> should not be used to postion items on the screen this should be done with CSS. In some places your have closing tags for elements which you have not used/opened. I would also suggest get rid of the silly no right click script. You cannot protect your HTML source code, all I need to do is disable JavaScript and I have right click capabilities back.(Alternatively press F12 to open the browser console or just download your entire html page).
-
error_reporting only controls what type of errors to report. It does not handle whether to actually show the error message, which is handled by a setting called display_errors Disabling display_errors will make PHP issue a standard HTTP 500 status code when any errors occur. You can configure your HTTP server to issue a custom 500 error page (a static HTML page or it can be a PHP script).
-
You are getting that error due the function myerrorhandler() being declared twice. PHP is reporting it has already being declared on line 10 of SecureFunctions.php. The error has being triggered because you are trying to redefine that function again on line 36 of SecureFunctions.php. Functions cannot be declared more than once. How are you defining this function? Can we see the code for SecureFunctions.php?
-
Don't use regex for parsing HTML. Instead you should query the DOM to retrieve the content you want from a HTML element on a webpage. You may find using simplehtmldom a lot simpler to use, it uses jquery like syntax for querying the DOM.
-
To see why you are getting that error enable error reporting/display errors with the following two lines at the top of your code ini_set('display_errors', 1); error_reporting(E_ALL); The other way to find out the error message is to check your servers error logs.
-
No. It will halt the script for 15 seconds, then the two dates will be shown. This is because by default PHP buffers the output which is then output all at once to the browser. However if you ran this script form the command line then yes, it will echo the first date and then 15 seconds later output the second date. If you want the contents to be streamed in the browser then you need to flush the buffer. Have a read of the following article for more info. http://www.sitepoint.com/php-streaming-output-buffering-explained/
-
I assume its the native value you want to check is not empty? <?php foreach ($footer["countries"] as $country): if(!empty($country['native'])): ?> <option value="<?= $country['english'];?>" data-int-url="<?= $country['url'];?>" data-int-img="<?= $country['img'];?>" data-int-cc="<?= $country['cc'];?>"> <?= $country['native'];?> </option> <?php endif; endforeach; ?>