scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
If you don't want to reload the page, you need Javascript. PHP cannot do that. If you want any kind of interaction on the page such as click events, keypress events, etc, then you need Javascript. PHP cannot do that either. The way you bridge them is with AJAX. So, the Javascript controls everything on the page - animations, events, data binding, etc. On special events you will use AJAX to communicate with a PHP script, to pass data back and forth. This definitely has the potential to be very Javascript-heavy, depending on what exactly you want to do with it.
-
Not sure, it's been a long time since I've used Eclipse. I use PHPStorm + XDebug.
-
The easiest way to figure this out is to either find documentation on the system, or use XDebug + your favorite IDE and chase the rabbit.
-
You could do it that way, but that's not the way I would go. I would only check for the cookie if they don't already have an active session. So it would go like, first visit: check cookie, get token, match to database, create session. Second visit: session already exists from previous request, so carry on as usual. If the session expires or they have no session, check for the cookie - if no cookie, redirect to login where they re-enter username/password.
-
If mod_alias is enabled it should show up in phpinfo() next to the other loaded Apache modules, like mod_rewrite. Since you have cPanel, have you tried setting up the redirect from there?
-
Is mod_alias enabled? Do you have access to the redirect logs? Do you have any errors?
-
-> is the operator used to access class properties or methods. filter() in this case is a method in the object that $custs references. You can find the full class name to the object $custs is referencing with echo get_class($custs); Then, find that class and you'll find your filter method.
- 1 reply
-
- 1
-
Either will work, I misspoke before. Pick whichever flavor you prefer and be consistent.
-
It would show you errors when you tried to run the script. In this case, it would tell you that you were trying to use an undefined variable.
-
That sounds mostly correct. Think of it this way: you're going to have two separate authentication methods. One method is typing username/password, the other method is supplying a user ID and token. Both methods will log in a user, and after that, the application should function identically no matter which method is chosen. That means that anything you're storing in the session when they're logging in with a username/password, you should also add to the session if they're logging in via a cookie. "Remember me" is not an alternative to sessions. You should still use sessions, to prevent having to repeat the authentication on every single page load.
-
if(!get_magic_quotes_gpc()){ $fname = addslashes($fname);}Don't do this. Magic quotes have been removed as of PHP5.4. You should be escaping input with mysqli_real_escape_string. You need to escape all of your other variables that you're using in the query as well.
-
Because you INSERT and then immediately SELECT the newest message. Obviously the newest message will be the one that you just added. createMessage.php if (!empty($_POST)) { $username = trim($_POST['username']); $message = trim($_POST['message']); if (!empty($username) && !empty($message)) { // insert into database } } getMessages.php $query = mysql_query("SELECT * FROM `chat`"); $messages = array(); while ($row = mysql_fetch_assoc($query)) { $messages[] = $row; } echo json_encode($messages);Not complete code but should give you the idea. Notice that I am returning JSON from getMessages.php; which you should be doing for simplicity's sake when dealing with AJAX. Let Javascript format the output onto the screen. getMessages.php will currently return all chat messages in the database, which you probably don't want, as that's going to get crazy when you have a lot of messages. An improvement would be to add a "since" parameter in your AJAX call, and then you only fetch records that were created after that time. Also, you're going to definitely run into problems calling your script every 100ms. You'd be lucky to even get that kind of response time from your average server. I'd probably poll every 1 seconds max.
-
I'd go for something like this: class testClass { private $photos; public function setPhotos(array $photos) { $this->photos = $photos; } public function getPhotos() { return $this->photos; } } $car = new testClass(); $car->setPhotos(array('photo1.jog', 'photo2.jpg', 'photo3.jpg')); foreach ($car->getPhotos() as $photo) { echo '<img src="' . $photo . '" />'; }
-
I'd recommend you turn them on globally in your php.ini though. Search your php.ini for "display_errors" and "error_reporting" and set them to the same values as above, and then restart Apache.
-
This is the correct syntax for what you're trying to do: <img onmouseover="preview.src=<?php echo $car[0]->{'photo' . $i}();?>.src" src="<?php echo $car[0]->{'photo' . $i}()?>" alt=""/>But, I agree with what other's have said: that's a really wacky way to go about things.
-
You're inserting a message and then selecting the message that you just inserted. Thus, you're only ever going to see the message that you just sent. You should have separate scripts for reading and writing, and you should be selecting more than one row. Probably something like, fetch all messages since the last time I checked. Also, this is a really inefficient way to make a chat. Hopefully you have a low number of users. A chat should be a persistent TCP connection to push messages as they come in, rather than infinitely polling whether there are new messages or not.
-
It doesn't have "from" because you're still using the wrong variable. $headers = "From: $email\r\n";Should be: $headers = "From: $emailField\r\n";Again, if you were developing with errors turned on you would have seen this and saved a lot of time.
-
Did you put the error code at the top like I suggested? Are you getting any errors? Your code should work, if those variables have data in them. Can you view the source of the email to see if there is something weird going on where the values are supposed to be?
-
No, the highlighted part is correct. PHP doesn't care or even know about the input's ID; it only cares about the name. Try sending complete HTML. $body = <<<EOD <!DOCTYPE html> <html> <head></head> <body> <br><hr><br> First Name: $fname <br> Last Name: $lname <br> Email: $email <br> </body> </html> EOD;
-
Can you post the form please? Also try dumping the $body and see what it contains. Just before this line $headers = "From: $email\r\n"; add: var_dump($body); exit;When you post code please use the forum's code tags by clicking the <> button.
-
Yeah I tested it and I was wrong. You caught me before I edited.
-
No it's not. The DB_Connect constructor does not return anything, and he is not assigning to the return from connect(). You should do this instead: $db = new DB_Connect(); $this->db = $db->connect();Now $this->db will be the MySQLI object.
-
No, because you named it $fnameField. If you want it to be $fname then you would have to do $fname = $_POST['fname'];
-
That, and it's "magic". It's difficult to inspect them or figure out what is going on at first glance.
-
Works for me. unset(${"hcorner".$h});