PHP - Simple Strcmp Help
Hello,
I am very new to php and I am having a bit of an issue here. I have made a script witch uses _GET to grab a couple of variables from a C++ program I have made. The script then sends those variables to a "log" file in the same directory as the script. Later on I use those variables in my C++ app to read version info ect..(work in progress). For now just to get me started, I will just want to log those variables to the file on the server. My script works perfectly as it is with one annoying flaw: There is no check to see if the entry already exists in the log. I want to do a simple check to read all entries in the file, and then strcmp($VariableFrom_GET, $ALLENTRIESINFILE) != 0, then fwrite the new value. What I can't figure is how to save all entries from the file into an array to compare with the new string. Thanks for any help. Similar TutorialsHi, So basically this is error: Code: [Select] if (strcmp($extuser,$username) == 0 && strcmp($extpass,$password) == 0) extpass is a value it reads from the database. That value is sha1-hashed. Password is plain and is sent via a form. So what happens is the following: extuser and username equals 0, as they match. extpass and password matches IF i put the sha1 hashed password as the password. So no problems in that, it's supposed to work that way. If we change the code a bit, so that the user shouldn't post an unknown password: Code: [Select] if (strcmp($extuser,$username) == 0 && strcmp($extpass,sha1($password)) == 0) Right, so we take the submitted password and sha1 it. Then check if that new string matches the database and whops, login failed. Okay.. by doing some debugging by printing the actual values i conclude this: The sha1($password) equals 139a8cf8be8..... while in my database all the letters are CaSe. This is most likely the error.. Any ideas for a fix? I have this code on my registration form for password Code: [Select] $password = $arVals['password']; $arVals['password'] = "'".md5($arVals['password'])."'"; $query = "INSERT INTO tbl_user (fname, lname, email, phone, city, status, province, password) " ."VALUES (".$arVals['fname'].", ".$arVals['lname'].", ".$arVals['email'].", ".$arVals['phone'].", ".$arVals['city'] .", ".$arVals['status'].", ".$arVals['province'].", ".$arVals['password'].")"; and a validation on the login process page using strcmp Code: [Select] $user_id = $_POST['user_id']; $password = $_POST['password']; if ($row = mysql_fetch_assoc($result)) { // echo $row['sPassword'] . "<br>" . md5($passwd); if (strcmp($row['password'], md5($password)) != 0) { header("Location: ./login_page.php?flg=red&user_id=".$user_id); exit; } seemed like it's not working as it keeps redirecting me always and telling me that the password didn't match? I wonder what the problem is.... Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Code: [Select] <?php //ob_start(); include "../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $UserId=$_POST['UserId']; $UserId = stripslashes($UserId); $UserId = mysql_real_escape_string($UserId); $UserName=$_POST['UserName']; $UserName = stripslashes($UserName); $UserName = mysql_real_escape_string($UserName); $UserFirstName=$_POST['UserFirstName']; $UserFirstName = stripslashes($UserFirstName); $UserFirstName = mysql_real_escape_string($UserFirstName); $UserLastName=$_POST['UserLastName']; $UserLastName = stripslashes($UserLastName); $UserLastName = mysql_real_escape_string($UserLastName); $UserGender=$_POST['UserGender']; $UserGender = stripslashes($UserGender); $UserGender = mysql_real_escape_string($UserGender); $UserLink=$_POST['UserLink']; $UserLink = stripslashes($UserLink); $UserLink = mysql_real_escape_string($UserLink); $UserPicture=$_POST['UserPicture']; $UserPicture = stripslashes($UserPicture); $UserPicture = mysql_real_escape_string($UserPicture); $sql="SELECT * FROM Fb_Profile WHERE UserId='$UserId' and UserName ='$UserName' and UserFirstName ='$UserFirstName' and UserLastName ='$UserLastName' and UserGender ='$UserGender' and UserLink ='$UserLink' and UserPicture ='$UserPicture'"; $result=mysql_query($sql); $count=mysql_num_rows($result); //Lets add a first time active check 0 or 1 if 1 skip and check for update<br /> if($UserId == 'undefined') { return true; } if($count==1) { echo "&msgText=Facebook MySql Copy Successfully!\n"; return false; } else { echo "&msgText=Invalid Login!\n"; //THIS HERE IS WHAT I AM HAVING A PROBLEM WITH, IF STATEMENT STATING THAT IF $UserId IS EMPTY AND THE OTHER VARIABLES RETURN NOTHING BUT IF IS HAS A VALUE IT INSERTS //IF(!empty $UserId) $FB_Profile_Copy = mysql_query("INSERT INTO Fb_Profile(UserId,UserName,FirstName,LastName,Gender,Link,Picture) VALUES('$UserId','$UserName','$UserFirstName','$UserLastName','$UserGender','$UserLink','$UserPicture')"); $FB_BackGround_Copy = mysql_query("INSERT INTO Fb_BackGround(UserId) VALUES('$UserId')"); return false; } ?> Code: [Select] <?php if ( $_SERVER['HTTP_REFERER'] == "http://domain.net/sub/index.php" ) { echo "true"; } else { echo "false"; } ?> is the code i'm using. /sub/index.php redirects to http://domain.net/index.php it's not seeming to work. please help sort out this bug. Have tried to do this myself all day now and i`m getting a little frustrated now. I have a contact form with a select box which can have multiple options selected, i`m using formmail.php to process the info. Problem is I have forgot how to list the values within the array and format them within the email body. $licences is the multiple select box any help would be gratefully received!! Code: [Select] <?php $name=addslashes($_POST['name']); $email=addslashes($_POST['email']); $town=addslashes($_POST['town']); $phone=addslashes($_POST['phone']); $licences=addslashes($_POST['licences']); $message=addslashes($_POST['message']); // you can specify which email you want your contact form to be emailed to here $toemail = "admin@mysite.com"; $subject = "Question : mysite.com"; $headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n"; $body = "Name: ".$name."<br>\n" ."Email: ".$email."<br>\n" ."Town/City: ".$town."<br>\n" ."Phone: ".$phone."<br>\n" ."Interested in Licence/s: ".$licences."<br>\n" ."Message:<br>\n" .$message; if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) { echo "That is not a valid email address. Please return to the" ." previous page and try again."; exit; } mail($toemail, $subject, $body, $headers); echo "Thanks for submitting your message."; ?> Please .i want php code to get metacfe thumbnail from url this is the url http://www.metacafe.com/watch/5823413/the_sinister_eyes_of_dr_orloff_movie_trailer/ php code to grab 5823413 for thumbnail links this http://www.metacafe.com/thumb/5823413.jpg Im trying to parse this xml but i can get it to output a simple string, can someone see what im doing wrong?? Code: [Select] $str = "<channel><item> <id>cb-uA4QHmpDxYdpgW1jPwiYsUwjBViwlinS</id> <title>Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12</title> </item> </channel>"; $n_data = new SimpleXmlElement($str, LIBXML_NOCDATA); foreach ($n_data->channel->item as $d) { $vid = $d->id; $title = $d->title; print_r($d->title); //testing die(); //testing $arr2[] = array('vid' => $vid, 'title' => $title, 'site_id' => 10 ,'time' => 456); } The print_r() returns Code: [Select] SimpleXMLElement Object ( [0] => Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12 ) If i simply echo $d->title it returns a string, but i need to reapply $d->title to another array as shown above Hi Guys
I'm updating my website and I'm stumped on the last section. I have a dynamic Table with various fields showing from Mysql, I use MS Access as a front end, and I have a field named Download, I enter the file location of a customers invoice and it stores the link in mysql, works perfectly. BUT, the dynamic table looks like this: Download - \users\MM4512\Invoices\Invoice23.PDF which is hyperlinked so they can download it etc.. Is there a way I can change this section from the above to a simple (Download Invoice) instead of all that text? The code used is : <td><a href="<?php echo $row_Invoices['download']; ?>" target="_blank"><?php echo $row_Invoices['download']; ?></a></td> I am trying to write a PHP page that takes an XML file stored on an external server, parses it, and rewrites the data to a new XML file formatted to my liking. The feed is for events and has about 250 events to parse. The problem is that if one event has an empty node, the script will use the same event data for the node used previously. Upon research, I see that empty nodes are parsed as an empty SimpleXMLElement Object. See my code for example: XML Original: Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> Output XML (note <outcome_score> on second event): Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> PHP code: $xml = simplexml_load_file($source); echo "<event_info>"; foreach($xml->event as $event) { echo "<event>"; if($event->outcome_score != '') { echo "<outcome_score><!CDATA[{$event->outcome_score]]></outcome_score>"; } if($event->quotes != '') { echo "<quotes><!CDATA[{$event->quotes]]></quotes>"; } } if($event->radio != '') { echo "<radio><!CDATA[{$event->radio]]></radio>"; } if($event->sched_opp != '') { echo "<sched_opp><!CDATA[{$event->sched_opp]]></sched_opp>"; } echo "</event>"; } echo "</event_info>"; Basically, whenever an event has no outcome score, the most recent outcome score is repeated for all events after. Any help would be greatly appreciated! Thanks! Hello, i am newbie at PHP codes and i need help little! How to limit of chars of song? I uploaud an images and post php code! $fp_data = ereg_replace("^.*<body>","",$fp_data); $fp_data = ereg_replace("</body>.*","",$fp_data); list($currentlisteners,$status,$peak,$max,$reported,$bit,$song) = explode(",", $fp_data, 7); if($showsong == '1') { $stationinfo = ' '.$currentsong.' '.$song.' '; } if($showlisteners == '1') { $stationinfo = $stationinfo.' '.$currentlisteners.' of '.$peak.' '.$listenerlabel.' '; } } } // Include the layout for display require(JModuleHelper::getLayoutPath('mod_ngs_shoutcast')); ?> Thank you! I think I'm using simple xml wrong I'm trying to read strings of xml and get it to list the "attributes" in the strings but it's not working. How would I read and list the attributes of this string <Address><to>Joshua</to><from>Rockhampton</from><country>Australia</county></Address> It needs to out put a string that can be printed and look like (or something like) to:Joshua from:Rockhampton country:Australia All my code produces errors and the page just goes blank and I don't know what is wrong.l Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this... if grade_type >=100 $final_grade = A Idk, im new to php and need help doing this... here is my code... Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_id', $_SESSION['grade_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_points']); $statement->execute(); $statement->closeCursor(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="delete_grade.php" method="post"> <input type="submit" name="remove" value="Delete" /> <input type="submit" name="update" value="Update" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> Code: [Select] <html> <head> <title>Delete Grade</title> </head> <body> <form method="post" action="delete_grade.php"> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete grades if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'grade has been deleted.<br />'; } if (isset($_POST['update'])) { foreach($_POST['update'] as $update_id) { $query = "UPDATE grades SET grade_id = $update_id"; mysqli_query($dbc, $query) or die ('can\'t update user'); } } //Display grade info with checkbox to delete $query = "SELECT * FROM grades"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; echo ' ' .$row['grade_type'] .' '. $row['grade_name']; echo '<br />'; } mysqli_close($dbc); ?> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> </form> </body> </html> Hi guys, this function below is for card validation, however anycard i enter i get the invalid card number, this is not connected to any gateways, this is just an Luhn card validation demonstration. can you tell me please why i get that? <?php if ($_POST['pay']) { $cardNo = addslashes(strip_tags($_POST['cardNo'])); function luhnCheck($cardNo) { $cardNo = str_replace(" ", "", trim($cardNo)); if(!is_numeric($cardNo) or strlen($cardNo)>19) return false; $skip = $newNum = $total = 0; for($i=0;$i<=(strlen($cardNo)-1);$i++) { if($skip ==0) { $tmpNum = ($cardNo[$i]*2); $total += (strlen($tmpNum)==2 ? (substr($tmpNum, 0, 1)+substr($tmpNum, 1)) : $tmpNum); $skip = 1; }else{ $total += $cardNo[$i]; $skip = 0; } } return (($total % 10) == 0); } /* Example Usage */ if(luhnCheck($_GET['cc'])) { echo("Valid Number."); }else{ echo("Invalid Number."); } } ?> <form name="confirm" method="post" action=""> <input type="text" name="cardNo"> <input type="submit" name="pay" value="Pay Now"> </form> I know it could be a issue with this line if(luhnCheck($_GET['cc'])) { but im wondering where should and how put this cc in my form? regards I am about to build a site for a liqueur brand and have to create a simple screen that asks if the user is of the right age. This does not have to be linked to a credit card, just a simple yes or no screen. I am thinking this would probably be done via a cookie, but I am not sure. Somehow it would have to work where it gets checked each time anyone goes to the site, regardless of the entry point. So for example it would get checked on mydomain.com, but also on mydomain.com/about, or mydomain.com/somethingelse. The yes or no screen would of course only show the first time the user came to site. Via what technology would I do this? Cookie? Can cookies have an expiration date? I would love some comments or direction on how this is done best. Thanks a lot! Lets say I have: $var=5; What would an output look like to get me: 1<br> 2<br> 3<br> 4<br> 5<br> Im at a complete loss! Thanks! I'm teaching myself php and mysql -- and my coding is a little rough. But what i'm trying to do is display information from a mysql table in another table on a website. I can do this just fine simply displaying the table, but i want a little something different. I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns. for example..... the table from mysql has names scott, john, james, mary, simon. with the code I have i can make it display like this: scott scott scott scott scott john john john john john james james james james james mary mary mary mary mary simon simon simon simon simon i want it to diplay like this: scott john james mary simon new names will continue down here is my code: <?php require ("connectigb.php"); $result = mysql_query ("SELECT pledgeName FROM pledgewall"); $fields_num = mysql_num_fields($result); echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>"; echo "<table border='1' align='center' style='width:960px;'><tr>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) if ($cell != "") { for ($j=0; $j<5; $j++) { echo "<td>$cell</td>"; } } echo "</tr>\n"; } mysql_free_result($result); echo "</table></center>"; ?> any ideas on what i can do here, i'm sure this is a simply fix. i just haven't come across it yet. thanks for the help in advance. |