PHP - Errors On Line 1 Every Time
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: auto@domain.com'; $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."); } } } ?> Similar TutorialsHi, can any see is the are mistakes in this for me. Thanks echo'<img src="skinFiles/'.$skin['thumb_name'].'"class="skinImage" onclick="changeSkin(\'skinFiles/'.$skin["css_name"].'\')" />'; How do I display the actual errors in IIS 7.5? If I miss a semicolon, I get: "HTTP Error 500.0 - Internal Server Error" absolutely useless. In prior versions, I could see the line and get to the PHP error. How do I display PHP errors? I've added: set_ini('display_errors', '1'); but it doesn't help. what im trying to do is take a youtube embed code find the URL code for that video and remove all other parts of the code keeping only the URL of the video after i get the URL by it self then replace the http://www.youtube.com/ part of the URL with http://i2.ytimg.com/vi/ to do this i know that i need something like this to get the URL of the video http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+) but how to only return just the URL is something idk how to do then use str_replace http://www.youtube.com/(?:v|cp)/" with http://i2.ytimg.com/vi/ so in the end im asking if anyone know how to remove all other codes i dont want and only keep the URL this may have to be done using "regex" im not sure as i dont know to much about regex and what it can do but does sound like it would help lol PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel i have to read a single line from a csv, its a really big file and i only need one column.
i need the response to be a string ,i made a search and found the following code but i dont have any idea how to get a single line from a single string per run .
<?php $row = 1; //open the file if (($handle = fopen("file.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } ?> Edited by bores_escalovsk, 16 May 2014 - 06:38 PM. Dear All Good Day, i am new to PHP (a beautiful server side scripting language). i want to send a mail with line by line message i tried with different types like by placing the things in table and using <br /> but the thing is the tags are also visible in the message of the mail. Here is my code: $message1 = "Name :". $_REQUEST['name']."<br />"; $message1 .= "Surname :". $_REQUEST['surname']."<br />"; $message1 .= "Cellphone :". $_REQUEST['mobileno']."<br />"; $message1 .= "Telephone :". $_REQUEST['landno']."<br />"; $message1 .= "Fax :". $_REQUEST['fax']."<br />"; $message1 .= "Company :". $_REQUEST['company']."<br />"; $message1 .= "Email :". $_REQUEST['email']."<br />"; $message1 .= "Country :". $_REQUEST['country']."<br />"; $message1 .= "Enquity :". $_REQUEST['enquiry']."<br />"; $message1 .= "Date&Time :". $date."<br />"; For this code if try to print/echo it it is working fine it is displaying line by line, but using this variable ($message1) in the mail these <br /> are also visible. Can any one guide me to resolve(to remove these tags from the message part) this issue. Thanks in Advance. :confused: Hi. I want a simple textbox, that when submited, will replace very every new line, with the <br> tag. What will happen, when it submits, it will take the contents of a textbox, add the <br> tag where a new line is suposed to be, and save the string to a MySQL Database. I think this is the easiest way of allowing a user to edit what appears on a website when logged in, but if there is a easier way, then please tell me. What I am trying to do, is a login page, and once logged in, you enter new text into the textbox, click submit, and on the website homepage, the main text will change to what was submitted. But if there is a new line, I think the only way in HTML to make one is to put a <br> tag, so I want the PHP to but that tag wherever there is a new line. Sorry if I am confusing, I am not that advanced at PHP, but I would be very happy if you could supply me with the correct code. Time is running out... If you do not understand me, please tell me -- PHPLeader (not) Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; }
What are the differences and implications of UTC time and Zulu time? <?php function getArr(string $time):array { $dateTime = new \DateTime($time); return [ 'time'=>$time, 'timestamp'=> $dateTime->getTimestamp(), 'dateTime' => $dateTime ]; } $arr = getArr('2020-08-05'); $arr_z = getArr('2020-08-05T00:00:00Z'); print_r($arr); print_r($arr_z); echo('equal timestamps: '.($arr['timestamp'] === $arr['timestamp']?'true':'false'));
Array ( [time] => 2020-08-05 [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) ) Array ( [time] => 2020-08-05T00:00:00Z [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 2 [timezone] => Z ) ) equal timestamps: true
This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. I am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! Hello, I tried to implement some PHP code to enable a web page to show "Dinner" specials versus "Lunch" specials based on the time. The business is located in the Eastern Time Zone, so I only need to routine to work based on Eastern Time (New York). What I am noticing is that the server is processing the lines of code so fast that the command to establish the correct time for the remaining code is not always being acknowledged. This line of code appears to be processing too fast for the remaining lines of code: date_default_timezone_set ( "America/New_York" ); Is there some additional code I can put in place to make sure the correct time is always ascertained? I need the $hourmin variable to always return a combination of hour + minute based on 24-hour time and Eastern Time zone. My code is as follows: <?php $name8 = file_get_contents("test/special8name.txt"); date_default_timezone_set ( "America/New_York" ); $gethour = date("H"); $getminutes = $gettimedate["minutes"]; $gettimedate = date(); $hourmin = $gethour . $getminutes; $currentday = date("l", time()); $currentdate = date("M j, Y"); if ($hourmin < 1500 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesred\">$name8 </span>"; } else if ( $hourmin > 1500 && $hourmin < 2300 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } else if ( $currentday == "Saturday" or $currentday == "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } ?> OK So I've got a datepicker that sends a date in d/m/y format. My DB stores the data in Unix Timestamp Which I can convert the date to with strtotime however this does the exact date & time. All I want is the actual day. I've spent hours trying to convert this with just the day with mixed results... Thanks. I have a script that reads a .gz file into an array and prints the name of each record but will not work on larger files. Is there a way to read 1 line at a time? Here is the code I have so far. Code: [Select] <?php if ($handle = opendir('.')) { print "<ol>"; while (false !== ($file = readdir($handle))) { if($file != '..' && $file!="." && $file!="start_update.php" && $file!="sharons_dbinfo.inc.php" && $file!="root.php" && $file!="read_directory.php" && $file!="read_dir.php" && $file!="new_category.php" && $file!="index.php" && $file!="file_count.php" && $file!="dir_loop2.php" && $file!="dir_loop1.php" && $file!=".htaccess" && $file!="Answer.txt" && $file!="Crucial_Technology-Crucial_US_Product_Catalog_Data_Feed.txt"){ $filename = $file; $go = filesize($filename); if($go >= 1){ $filename2 = explode("-", $filename); $filename2 = $filename2[0]; echo str_replace("_"," ",$filename2) . ' | Filesize is: ' . filesize($filename) . ' bytes<br>'; $gz = gzopen($filename, 'r'); $lines = gzfile($filename,10000); foreach ($lines as $line) { $line2 = explode(",", $line); $line2 = str_replace("," , "-" , $line2); echo "<li>".str_replace("," , "-" , $line2[4])."</li><br>"; } } } } closedir($handle); } ?> </ol> How to get this echo line to display as one line? No matter what I have done it displays as two lines. I even tried <nobr></nobr> Teachers Name: John Jones $userid = mysql_real_escape_string($_GET['user_id']); $sql = "select * from users where `id`='$userid' "; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<h3>Teachers Name: </h3>" . $row["first_name"] . " " . $row["last_name"] ; } Thanks for your help. I am making a time clock, and I was wondering what is the best way to calculate the number of hours an employee worked? I have a table called "statuses" it holds names of punch types: - id = the auto_inc - status = "in/out/break/lunch" text statuses - paid = whether or not the punch is paid or not (true/false) I have another table called "logging" This table holds the information about the punch type: - id = the auto_inc - owner = the member id - ip = members ip - inout = the punch type from the statuses table - location = the city/state of where the punch took place - date = the time the member punched Maybe I am over thinking this, but what is the best way to calculate the hours a person has worked? Right now I am getting all the punches for for a particular member between a date range. then loop through the data to display it and passing it to a method in a class called Calc. I want to then add the times from punch in to punch out, then the next punch in to punch out. Any suggestions? Hi, The hosting provider for my domain confirm me that the server time is in EST (UTC-5). They also sent me a grab supporting that Code: [Select] server time is now: ---------------------- Sun Nov 7 02:20:01 EST 2010 ------------------- But when I use the following code, the output I get is has 1 hr difference (UTC-6) echo date("d M, Y h:i:s A",time()); Output==> 07 Nov, 2010 01:20:01 AM But it suppose to give the same time as the server, ryt? Can anybody please explain? Thanks, I have this: $sql = mysqli_query($conn, "SELECT ip , page , CASE WHEN referrer = '' THEN 'N/A' ELSE referrer END as referrer , DATE_FORMAT(date, '%m/%d/%y') as date , TIME_FORMAT(time, '%T') as time FROM tblTraffic ORDER BY date DESC, time DESC"); most of my traffic report contains the correct times, my time, which is CST in the USA. but some records are off by a lot. Does the time() function capture the time of the actual location from which the visitor is coming from? if so, what could I do to return my timezone for any visitor? w3 schools and php.net don't mention this. |