Itsu Posted October 23, 2010 Share Posted October 23, 2010 I keep getting this error and I don't know what's wrong. My mysql class is fine, but then the user class keeps getting the error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home2/-/public_html/special/classes/users.php on line 1 Any change I make, it's always an error on line 1. user.php: <?php include"mysql.php"; class User extends mysql { var $mysql; function __construct(){//Create a 2nd clean function that automatically cleans sessions, gets and posts $this->mysql = new mysql(); foreach($_POST as $key => $val){//For every post $_POST[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); $$key = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); } foreach($_GET as $key => $val){//For every get $_GET[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); $$key = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); } /* foreach($_SESSION as $key => $val){//For every session $_SESSION[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); $$key = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); } */ foreach($_COOKIE as $key => $val){//For every session $_COOKIE[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); $$key = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES))); } } public static function Clean($string){//Create a clean function if(get_magic_quotes_gpc()){//If magic quotes is enabled $string = stripslashes($string);//Remove slashes from the string }elseif(!get_magic_quotes_gpc()){//If not $string = addslashes(trim($string));//Add slashes to the string then trim is } $string = escapeshellcmd($string);//Remove all SHELL commands $string = mysql_real_escape_string($string);//Stop MOST MySQL injections $string = stripslashes(strip_tags(htmlspecialchars($string, ENT_QUOTES)));//Remove XHTML, remove slashes return $string;//Return the final string } function Encrypt($string){ $string = md5($string); $string = sha1($string); $string = md5($string); return $string; } function LoginForm($page){ $fields = array( 'user' => array( 'type' => 'text',//Type of input 'pre' => 'Username',//Label of input 'value' => ''),//Value of input 'pass' => array( 'type' => 'password',//Type of input 'pre' => 'Password',//Label of input 'value' => ''),//Value of input ); return CreateForm ($page, 'post', $fields, 'login', 'test', 'Sign In!'); } function Login($username, $password){//Create a login function for the user system $this->Connect();//Connect to the database! $username = $this->Clean($username);//Clean the username input to stop hackers $password = $this->Clean($password);//Clean the password input to stop hackers $password = $this->Encrypt($password);//Take the unencrypted password and run it through our encrypt function! $query = @mysql_query($this->GetUserLogin($username, $password)) or die(mysql_error());//create the user table by calling the function CreateUser in the querries class if($query){//If the query has worked if(mysql_num_rows($query) == 1){//If the query has got a result ie the information is correct session_register("USR_USERNAME", $username);//Start the session and set the username setcookie("id", $username,time()+500000); setcookie("pass", $password,time()+500000); return 'You are now logged in'; }else{ return 'Incorrect username or password.'; } }else{ return '<b>Mysql Error</b>'; } } function Logout(){ if(isset($_SESSION['USR_USERNAME'])){ unset($_SESSION['USR_USERNAME']); unset($_COOKIE['id']); unset($_COOKIE['pass']); } } function RegisterForm($page){ $fields = array( 'user' => array( 'type' => 'text',//Type of input 'pre' => 'Username',//Label of input 'value' => ''),//Value of input 'pass' => array( 'type' => 'password',//Type of input 'pre' => 'Password',//Label of input 'value' => ''),//Value of input 'cpass' => array( 'type' => 'password',//Type of input 'pre' => 'Confirm Password',//Label of input 'value' => ''),//Value of input 'email' => array( 'type' => 'text',//Type of input 'pre' => 'Email',//Label of input 'value' => ''),//Value of input ); return CreateForm ($page, 'post', $fields, 'register', 'test', 'Sign Up!'); } function Register($username, $password, $cpass, $email){//Create a new function that needs certain variables to work $this->Connect();//Connect to the database! /*Clean the variables to stop hackers*/ $username = $this->Clean($username); $password = $this->Clean($password); $cpass = $this->Clean($cpass); $email = $this->Clean($email); /*Encrypt the 2 passwords*/ $password = $this->Encrypt($password); $cpass = $this->Encrypt($cpass); $getuser = @mysql_query($this->GetUser($username, $password)) or die(mysql_error()); $r = mysql_fetch_array($getuser); $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+"; $_host = "([-0-9A-Z]+\.)+"; $_tlds = "([0-9A-Z]){2,4}$/i"; if($password !== $cpass){ die("The passwords you entered don't match!"); }elseif($username == NULL || $password == NULL || $email == NULL){ die("Please enter data into the specified boxes!"); }elseif(!preg_match($_name."@".$_host .$_tlds, $email)){ die("Please enter a valid email address"); }elseif(mysql_num_rows($getuser) > 0){ die("The username you entered already exists!"); }elseif($username == "Guest"){ die("Name cannot be used"); }else{ $ip = $_SERVER['REMOTE_ADDR'];//Set the ip variable as the users ip address $actcode = $this->GetCode(); $query = @mysql_query($this->RegisterUser($username, $password, $email, $ip, $actcode)) or die(mysql_error());//Send the query to the query page if($query){//If the query has worked $this->SendEmail($username,$email,$actcode); return "Thanks for registering, but before you can use your account, you need to activate it, an email will be sent to you within 10 minutes (Usually Instantly)!";//Return a success message }else{ die("<b>MySQL error!</b>n"); } } } function GetUserInfo(){ $this->Connect(); if(isset($_SESSION[uSR_USERNAME])){ $query = @mysql_query($this->GetUser($_COOKIE['id'], $_COOKIE['pass'])) or die(mysql_error());//Get their info from the DB if($query){//If the query worked $logged = mysql_fetch_array($query);//Get the user information $logged['type'] = 1;//Set the type of user to 1 - they arent a guest } }else{ $logged = array( 'username' => 'Guest', 'type' => 0, 'ip' => $_SERVER['REMOTE_ADDR'] ); } return $logged; } function GetCode(){//Create a new function that creates a random string for the activation code $alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //String of A-Z and 0-9 $actcode = substr(str_shuffle($alphanum), 0, 10); //shuffle the string, cut it so we have 10 characters return $actcode; //Return our 10 character code } function SendEmail($user,$email,$code){//Create a new function to send the email, we have the users username, email and actcode with us. $link = '/activate.php?code='.$code; $re = 'Activate Account'; $headers = 'From: [email protected]'; $msg = 'Hello '.$user.', You are receiving this email because you have recently registered at, you will first need to activate your account before you can access it though. Click the link below to activate your account.'.$link; mail($email,$re,$msg,$headers); } function FindCode($actcode){//A new function to find the code in the table. Our $actcode here is passed from the activate.php file. $this->connect();//Connect to MySQL if($actcode){//If $actcode is NOT empty $query = @mysql_query($this->SearchCode($actcode)) or die(mysql_error());//search code sql if(mysql_num_rows($query) == 1){ //If we have one row $query = @mysql_query($this->EditCode($actcode)) or die(mysql_error()); //Edit table if($query){ //If query above succeeded return "You account has been activated and you can now log in!n"; //Confirm message }else{ //Otherwise an error die("<b>MySQL error!</b>n"); } //Otherwise invalid activation code }else{ die("<b>Invalid Activation Code</b>n"); } }else{ //Otherwise $actcode is empty. die("Actcode is empty."); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/216670-errors-on-line-1-every-time/ Share on other sites More sharing options...
Hybride Posted October 23, 2010 Share Posted October 23, 2010 What's in mysql.php? You might have the same set of quotes that are interfering when you included that file. Also, $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+"; $_host = "([-0-9A-Z]+\.)+"; $_tlds = "([0-9A-Z]){2,4}$/i"; You're missing slashes (//) for the regular expressions. So try this: $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+/"; $_host = "/([-0-9A-Z]+\.)+/"; $_tlds = "/([0-9A-Z]){2,4}$/i"; Quote Link to comment https://forums.phpfreaks.com/topic/216670-errors-on-line-1-every-time/#findComment-1125739 Share on other sites More sharing options...
trq Posted October 23, 2010 Share Posted October 23, 2010 [ot] Why would a User extend a mysql? There is no relation at all. [/ot] Quote Link to comment https://forums.phpfreaks.com/topic/216670-errors-on-line-1-every-time/#findComment-1125745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.