-
Posts
178 -
Joined
-
Last visited
Everything posted by Pain
-
kicken cheers, swapping those two lines has fixed the error. Muddy_Funster so you think i should simply write them down in a procedural style?
-
Hello again. I am trying to extend a class, but it gives me an error: Fatal error: Class 'Redirection' not found in /home/searchqu/public_html/game/class.session_destroy.php on line 3 Im trying to extend the logout class: <?php session_start(); class SessionDestroy extends Redirection{ public function destroy_session() { session_destroy(); Redirection::redirect("login"); } } ?> this is my redirection class: <?php class Redirection { function redirect($parameter) { header("Location: $parameter"); } } ?> and this is my actual logout page: <?php ob_start(); require('class.session_destroy.php'); require('class.redirect.php'); $logout = new SessionDestroy; $redirect = new Redirection; $logout->destroy_session(); ob_end_flush(); ?> What could be the problem here? Thanks:]
-
Hi there. I want to keep on updating database even if the user is offline and there is no active session. For example, i want to keep increasing players resources in an online browser based game. What would be the best way to do this?
-
Hello. I wrote this small class which should redirect user to another page. <?php class Redirect { public function redirect($parameter) { header("Location: " . $parameter . ")"; } } ?> Doesn't really work because of the incorrect syntax in this line: header("Location: " . $parameter . ")"; What would be the correct syntax in this case?
-
So should i create another function for session handling?
-
Hi there. I am trying to retrieve stuff from the database and then assign it to a session variable like this: function selectDB() { global $mysqli; if ($stmt = $mysqli->prepare("SELECT username, password FROM ww3_users WHERE username = ? AND password = ?")) { $stmt->bind_param('ss', $new_username, $new_password); $new_username = $_POST['username']; $new_password = $_POST['password']; $stmt->execute(); $stmt->bind_result($username, $password); while($stmt->fetch()) { return $username; } $_SESSION['username'] = $username; return $_SESSION['username']; } else { return false; } } Is it the correct way to assign like this? $_SESSION['username'] = $username; return $_SESSION['username']; The code successfully retrieves username and pwd from the db, but the session variable is empty.. thanks!
-
Hi there. I am trying to display a session variable on the page. However i am not sure if the code should be placed in the view or in the model? Also is this line of code written correctly? print_r $this->session->all_userdata() Thank you:)
-
Hi there. I am unsuccessfully trying to echo out a variable taken from the table... This is a very simple mysqli class: <?php class Database{ function selectOne($table, $table_entry) { global $mysqli; $this->table = $table; $this->table_entry = $table_entry; if ($stmt = $mysqli->prepare("SELECT $this->table_entry FROM $this->table")) { $stmt->execute(); $stmt->bind_result($variable2); while($stmt->fetch()) { return $variable2; } } } } ?> And this is the main page.. Probably there's something wrong with those two lines..? Thanks for any help:) <?php $database->selectOne("ww3_users", "username"); echo $database->selectOne->variable2; ?>
-
Lol, how stupid of me. Thanks:]
-
Hello. I've built a mailer class specifically for account activation. <?php class Mail { public $unique; public $subject = "You must activate your account"; public $message = "Please click on the link below to activate your account "; public $headers = "This is automatically generated email, please do not respond to it."; public function sendActivationMail($to) { $this->unique = md5(uniqid(rand())); if (!mail($to, $this->subject, $this->message, $this->headers)) { return false; } else { return true; } } } ?> However i am unable to add property $unique to my message (in this case it is $message). How can i do this? Thanks:]
-
Hello. I have started using prepared mysqli statements such as this. $username = $_POST['username']; $password = $_POST['password']; $password_repeat = $_POST['password_repeat']; $email = $_POST['email']; if ($stmt = $mysqli->prepare("INSERT INTO ww3_users (username, password, password_repeat, email) VALUES (?, ?, ?, ?)")) { $stmt->bind_param('ssss', $username, $password, $password_repeat, $email); $stmt->execute(); $stmt->close(); } The question is - do i have to escape strings? Thank you:)
-
Thank you, everything works just fine:)! However i am positive that the structure is not very well made. Can you give me any advice on how could I improve the structure of this code?
-
I've fixed it a bit: <?php $submit = $_POST['submit']; class Login { function validateEmail($email) { if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { return $email == FALSE; }else{ return $email == TRUE; } } function validatePassword($password) { if(strlen($password) < 5) { return $password == FALSE; } else { return $password == TRUE; } } function validatePasswordRepeat($password_repeat) { if ($_POST['password'] !== $password_repeat) { return $password_repeat == FALSE; }else{ return $password_repeat == TRUE; } } public function successfullyRegistered() { header('Location: successfully_registered.php'); } } $validation = new Login; if (isset($submit)) { $validation->validateEmail($_POST['email']); $validation->validatePassword($_POST['password']); $validation->validatePasswordRepeat($_POST['password_repeat']); if (($validate->validateEmail($_POST['email']) == TRUE) && ($validate->validatePassword($_POST['password']) == TRUE) && ($validate->validatePasswordRepeat($_POST['password_repeat']) == TRUE)) { $validation->successfullyRegistered(); } } ?> <html> <head><title>New user</title></head> <body> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p>Password</p> <input type="password" name="password" /> <p>Repeat password</p> <input type="password" name="password_repeat" /> <p>Email</p> <input type="text" name="email" /> <input type="submit" name="submit" /> </form> </body> </html> And i get another error now. Call to a member function validateEmail() on a non-object in /home/searchqu/public_html/ww3/process_registration.php on line 43 Thanks for spotting that one!
-
Hello. I am learning some php OOP. While building a basic verification class i've faced this error: Fatal error: Can't use method return value in write context in /home/searchqu/public_html/ww3/process_registration.php on line 45 Where did i go wrong? Here is my code. Any advice would be greatly appreciated. Thank you. <?php ob_start(); $submit = $_POST['submit']; class Login { function validateEmail($email) { if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { return $email = FALSE; }else{ return $email = TRUE; } } function validatePassword($password) { if(strlen($password) < 5) { return $password = FALSE; } else { return $password = TRUE; } } function validatePasswordRepeat($password_repeat) { if ($_POST['password'] !== $password_repeat) { return $password_repeat = FALSE; }else{ return $password_repeat = TRUE; } } public function successfullyRegistered() { header('Location: successfully_registered.php'); } } $validation = new Login; if (isset($submit)) { $validation->validateEmail($_POST['email']); $validation->validatePassword($_POST['password']); $validation->validatePasswordRepeat($_POST['password_repeat']); if (($validate->validateEmail($_POST['email']) = TRUE) && ($validate->validateEmail($_POST['password']) = TRUE) && ($validate->validateEmail($_POST['password_repeat']) = TRUE)) { $validation->successfullyRegistered(); ) } ob_end_flush(); ?> <html> <head><title>New user</title></head> <body> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p>Password</p> <input type="password" name="password" /> <p>Repeat password</p> <input type="password" name="password_repeat" /> <p>Email</p> <input type="text" name="email" /> <input type="submit" name="submit" /> </form> </body> </html>
-
Still gives me an error - Notice: Undefined index: someval in /home/searchqu/public_html/ww3/main.php on line 17
-
A bit confused... <form method="POST"> <input type="text" name="someval" /> <input type="submit" name="submit" /> </form> <?php error_reporting(-1); class Product{ public function convertToUpperCase($var){ if(isset($submit)) { $this->var = strtoupper($this->var); return $this->var; } } } $someval = $_POST['someval']; $submit = $_POST['submit']; $product = new Product; echo $product->convertToUpperCase($someval); ?> Once again i get the error of not defining variables: Notice: Undefined index: someval in /home/searchqu/public_html/ww3/main.php on line 22 Notice: Undefined index: submit in /home/searchqu/public_html/ww3/main.php on line 23 And when i input some text nothing happens.:/
-
I want to input some text into a textbox and then use that input in the class. Not sure how to even start, couldn't find any decent tuts on that.
-
Thanks, that works just fine. Still got one q though. If i were to use a POST variable, how should it look like? Should i assign POST to variables INSIDE the class?
-
Ok im starting to pick things up. I've adjusted the code to <?php error_reporting(-1); class Product{ public $type = "Milk"; public function convertToUpperCase(){ $this->type = strtoupper($this->type); return $this->type; } } $product = new Product; echo $product->type; echo $product->convertToUpperCase($type); ?> It now does work, but still produces an error: Notice: Undefined variable: type in /home/searchqu/public_html/ww3/main.php on line 15 So there is still something not quite right with this line. echo $product->convertToUpperCase($type);
-
Notice: Undefined variable: type in /home/searchqu/public_html/ww3/main.php on line 14 Notice: Undefined variable: type in /home/searchqu/public_html/ww3/main.php on line 8
-
It does not echo out the string in upper case. Where did I go wrong?
-
Hello. I am fairly new to the object orientated php. Just wondering if I could get any help with this one. With this code I am attempting to convert a string to upper case. <?php class Product{ public $type = "Milk"; public function convertToUpperCase(){ strtoupper($type); } } $product = new Product; echo $product->type; echo $product->convertToUpperCase($type); ?> Thanks!
-
Thanks for the answer! This is what i've come up with: RewriteRule ^member/([a-zA-Z0-9_-]+)/?$ user_profile.php?username=$1 Looks like it does work, however i think i must create an actual directory called 'member'?
-
Hi there. I'm have a rewritten url for a social site members and it looks like this: http://theWeb.net/user_nickname However i would like it to look like: http://theWeb.net/member/user_nickname Can i somehow do this with mod rewriting? I've got some code from the .htaccess, your help would be very much appreciated! RewriteBase / RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^user_profile-([0-9]+)\.php$ user_profile.php?id=$1 RewriteRule ^user-profile/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ user_profile.php?id=$2 RewriteRule ^([a-zA-Z0-9_-]+)$ user_profile.php?username=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ user_profile.php?username=$1