The simple answer to your question. On every page you want to protect, you need to check if the user is logged in.
How to check if the user is logged in depends on your implementation.
Heres is a simple login scenario:
1) Login page with {user} and {pass}
2) Validate {user} and {pass} and issue that user a {session_key}
3) On every page you protect, check for valid {session_key}
That is all there is to password protected pages.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Do a var_dump() on your array to be sure of it's structure.
You can also do this within your loop. Then it is just making sure you write the correct notation to reference the index you need.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Do a var_dump() on your array to be sure of it's structure.
You can also do this within your loop. Then it is just making sure you write the correct notation to reference the index you need.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
You can use proc_open() to open multiple php processes. You can open a process to a PHP file that will run the server online test. You don't have to wait for proc_open() to return, so you can run it multiple times.
If you want to read the returns async, then use stream_select(). Otherwise you can just have the php scripts called by proc_open() write to persistent storage, like a db or file with the results.
You can also use exec() to execute processes async. eg:
exec('php /path/to/server_online_test.php http://example.com &');
That would call /path/to/server_online_test.php passing it "http://example.com" as an argument. You can retrieve the argument via $argv[1]
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
The $pattern must be a regular expression. It must have delimiters around the pattern, and optional modifiers after the second delimiter.
Example patterns:
"/cb/" - matches cb
"/cb/i" - matches upper and lower case cb
see the docs for preg_match. http://php.net/preg_match
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Warning: sprintf() [function.sprintf]: Too few arguments in C:\xampp\htdocs\folder\search.php on line 62
Query was empty
Are you using a PHP framework? Or a custom database class?
Whats happening is that your SQL query is being run through sprintf() function, which will try and replace the special keys that start with the '%' signs with the variables passed in. See: http://php.net/sprintf
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
What is the error. Do you get the error in PHP or in MySQL?
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
I'm impressed with Aptana Studio 3 and it is wonderful. I have decided to go back to eclipse after years of using Netbeans. In NB I was having option of separating my files from project meta data but I cannot find how to do it with AS. Also in Netbeans debugging and running server is breeze but cannot find it in Eclipse. So any help in the aspects is appreciated
Thanks
I don't think Aptana3.0 has PHP debugging. Try installing 2.0.
Apatana3.0 tries to do too much (has too much built in) and less ability to use external plugins which makes it less customizable. I'm using the prebuilt version however, maybe you can get better results with the Eclipse plugin version.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
From the docs it seems it should work.
Try taking a look at the HTTP request with a tool like Wireshark so see if you're actually getting a HTTP request.
Also if you use a try/catch block around the xmlhttprequest open method you should see the error mesage.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Are you aware that XMLHTTPRequest can only be made to the same domain?
You need the domain you're requesting from to grant cross domain access somehow or you will have to proxy the request.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
I don't want to have the submit button. Is it possible? If it can, how to rewrite the code? Thanks!
You can use a redirect, with cookies or session.
eg:
<?php
@session_start();
if (isset($_GET['tz'])) {
$_SESSION['tz'] = $_GET['tz'];
} else if (!isset($_SESSION['tz'])) { ?>
<script>
window.location = '<?php echo htmlentities($_SERVER['PHP_SELF']); ?>?tz=' + (new Date().getTimezoneOffset()/60);
</script>
<?php } ?>
Note that using JS assumes the clients clock is set to the correct timezone. Another option is to use the users IP and a geocoding service to guess their timezone.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
In short, it is up to you what your logic is, just don't worry about optimization as an issue preventing you from writing it out to cover all scenarios. Test it afterwards for performance issues, not theoretically during your coding process. It usually makes development a lot more efficient.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
For the first issue, where you have duplicates. What you can do is put a unique index on the user_id row. That way a duplicate creates an error and can never exist.
Do not worry about the extra load on the db when you check if an entry exists. It is a necessary part of your logic, so do it. Foremost is that your application works well.
If you have problems later on, it most likely will not be because you're checking for an existing entry. Read some posts online on "premature optimization". You can wonder about design all day if you think of every small decision and how it affects load.
On fail of the insert, you will have to figure out what went wrong. You can either change your onstoreuser to onbeforestoreuser or whatever it is called. Then do your insert before user is stored, and if it fails, return false so that the user registration fails. Then send yourself an email, or other notice or log the error somewhere for notification later.
When updating the credits row, you should check how many rows were affected in the update. If the update did not affect any rows, then something is wrong, so notify the user and yourself.
You can also hook into the user login through a plugin. When the user logs in, check if their credits row exists. If not, create it. This works for users that already exist in the db and would not be handled by registration events.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Hi, where is the best practice to put js, image, css files when you make component? I put them in the same directory as component is. Is it good practice? Or should they be in media directory?
A lot of components will have a js/, image/ and css/ folder under the root of the component. I believe it just depends on what you feel is the best structure.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Hi,
would it be difficult to let's say add a record to another table on user registration? Lets say I want to add a records how many credits the user has in jos_credits table when user registers, in other words - add record with that user id and set credits to 0 initially. When they add money to a website, they will get credits.
One thing I can think of is use database trigger, but I don't like them very much. Is there another way to do it with a component for example?
Another way to partialy solve that problem would be not to add record to a credits table, and only add it when the user deposits money. The problem is - we will have to check if there is already a record created when the user adds money, so do we have insert new or update an existing, so it is waste of recourses.
Joomla has a plugin system that will trigger certain events in the Joomla Framework.
The User plugins have events for saving user data, authentication etc.
see: http://docs.joomla.org/Reference:User_Events_for_Plugin_System#5.3.7_onAfterStoreUser
Here is a bit on creating a plugin: http://docs.joomla.org/Tutorial:Creating_a_Plugin_for_Joomla_1.5
Basically you will create a plugin which is an xml file and a php file. The PHP file contains a class that extends the plugin base base class. Then you define functions which handle the different events. You're interested in the onAfterStoreUser() method.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Just to make sure:
if(!isset($_POST['anything'])){
will return TRUE if $_POST is NOT set right?
Are you sure you aren't confusing it somehow? It would be very improbable that something so unique would happen both on your server, and on your localhost at the same time.
If it was a coincidence, then it probably is not the ! operation, but a problem with $_POST or something similar.
When dealing with bugs like this, the last thing you want to blame is the internals of the programming language, as those are hardly ever the cause of the error.
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
Try debugging your code. Make sure you're getting the correct list/array of passwords.
eg:
$var_list = explode("\n",$var_data);
var_dump($var_list);
or:
print_r($var_list);
Zero13 recommended using:
$var_list = explode("\r\n",$var_data);
Instead since Windows line breaks are \r\n instead of just \n in Linux. However, to work with both Windows and Linux you need something like:
$var_list = explode("\n",$var_data);
// trim each value in the data
$var_list = array_map('trim', $var_list);
However, if spaces mean something in each line you need to only trim the \r character.
Just a note, instead of using:
echo ( '<meta http-equiv="REFRESH" content="0;url=WinthropPoll01.html">');
You can use:
header('Location: WinthropPoll01.html');
That sends a HTTP redirect which is followed without displaying any content. However, that only works if you have yet to display any content at all.
To solve that you usually use output buffering to buffer your content (see: ob_start() ) or you can test for output using headers_sent().
http://us2.php.net/manual/en/function.headers-sent.php
eg:
if (!headers_sent()) {
header('Location: WinthropPoll01.html');
} else {
echo ( '<meta http-equiv="REFRESH" content="0;url=WinthropPoll01.html">');
}
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9
digital-ether
Nearly a Posting Virtuoso
1,295 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Skill Endorsements: 9