PHP - Create Php For Rest Api Concept. Need Someone Review My Coding
Dear Friends. Just now I tried to create PHP to make Rest API for my mobile application and I would like to know that it's good coding and need any improve? it is my first time for Rest API. normally I just connect to PHP file directly on .htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([0-9A-Za-z_]+)$ function.php?func=$1 [L,QSA] RewriteRule ^([0-9A-Za-z_]+)/$ function.php?func=$1 [L,QSA] on function.php $func = $_GET['func']; switch( $func) { case 'lab_info': //ໜ້າຫຼັກ define( '_FUNC', 'lab_info.php'); break; case 'customer_info': //ຂໍ້ມູນຜູ້ໃຊ້ define( '_FUNC', 'customer_info.php'); break; default: // No function define( '_FUNC', 'functionnotfound.php'); break; } if( defined( '_FUNC') && constant( '_FUNC') !='') require( "func/" . _FUNC); on customer_info.php $error = array(); if(isset($_POST['user']) != 'lung'){ $error['status'] = "422"; $error['title'] = "Authentication Fail"; $error['detail'] = "Invalid user authentication"; echo json_encode($error);die(); } if(!isset($_POST['user'])){ $error['status'] = "401"; $error['title'] = "Invalid Attribute"; $error['detail'] = "Invalid Attribute For Information"; echo json_encode($error);die(); } $result = $conn->query("select Lab_Name,Lab_Username,Lab_Password from tb_labmanagers"); $customer = array(); while($row =mysqli_fetch_assoc($result)) { $customer[] = $row; } echo json_encode($customer); this image attached file is result from postman, client need to send user = 'lung' to get information
Similar TutorialsI have the concept I want... and I know how to do some of these things by themselves... but not in combination, and I really need to do this in combination for the concept to work. I'm totally new to PHP/mySQL... Background information: I'm using ExpressionEngine (incase anyone is familiar)...and I'm using that for a membership system as well as a means to restrict certain content to certain member/account types. The website is membership ONLY... (using cookies to remain logged in). The part I want to make happen with PHP/mySQL is to restrict some content even further. I want this content to be accessible through sequence only. The sequence of what is presented is important... so imagine it is something like this: Section 1 : About the world. Section 2: About something else. (((For example--- the user clicks Section 1... and now (invisible to the user) the DATE/TIME is taken into the database as the moment they BEGAN that part of the section.))) ((( Now the user is presented with the information they requested))) "Here is the content--- information on some countries in the world. INFoRMATION IS HERE... BLA BLA BLA BLA BLA BLABLA BLA BLA BAL BLA BLA BLA BLA BLABLA..." Now user has available choices: "------------------------ 1. Tell me about Japan. 2. Tell me about Hawaii. 3. Tell me about Mexico. 4. Tell me about U.S.A." Clicking a link will either take the user to a new PAGE (file) with the information in it... or it will somehow channel the next information from somewhere (text file or something) into the same page, changing the content that way. However it happens, I want it to be so when a choice is made--- you can not press the back button and choose something else. I want the user to really 'think' about the choices they are making before they make them... they are free to take their time as long as they wish while they're IN sequence... but if they interrupt the sequence by pressing back or just closing the browser window *** I WANT TO MAKE THAT SPECIFIC SECTION (1) INACCESSIBLE FOR A DURATION OF TIME (few days) ***. (((hence the grabbing of the date/time when the user began that section)))... When the time limit is lifted--- then they can access that content again. If this requires multiple pages--- then each page will require the previous as a referrer, so that way nothing can be accessed out of the intended sequence. The idea is that, if the user begins a section--- they MUST go through step 1--- to reach step 9... and they need to do each one in order. The user will have a wide variety of choices though... which means there will be ONE starting point (the beginning of the section), and potentially hundreds of 'ending' points to that section. For now, I'll just says 'dozens' of ending points... but eventually it will be many more. Each part of the section requiring the previous page to access it (maintaining sequence). If this effect can be done without the need for multiple pages, that might be good... as there will likely be hundreds/thousands of them when I'm done. That seems like a bit much... but sometimes one page will only have a small bit of information in it, and nothing else before the next choices are presented. But then again, I'm not sure which would be worse/take longer, having thousands of pages or thousands of database entries I need to figure out how to link up with and where. Does this make sense? I'm trying to figure out a good place to START making this happen... have any of you done anything like this before? Thanks for any help you can be... can someone please help me understand the concept how to implement the "Domand Driven Design" strategy in PHP ? ok let's say for example I have a user and a user got multiple addresses. so the user got e.g
class User { public $userId; public $name; public $age; public function setUserId($userId) { $this->userId = $userId; } public function getUserId() { return $this->userId; } public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } public function setAge($age) { $this->age = $age; } public function getAge() { return $this->age; } }
Then Address got e.g class Address { public $addressId; public $country; public $city; public $zip; public function setAddressId($addressId) { $this->addressId = $addressId; } public function getAddressId() { return $this->addressId; } public function setCountry($country) { $this->country = $country; } public function getCountry() { return $this->country; } public function setCity($city) { $this->city = $city; } public function getCity() { return $this->city; } public function setZip($zip) { $this->zip = $zip; } public function getZip() { return $this->zip; } }
So how to apply the concept of the Domain Driven Design here ? This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=355702.0 Hi I have been getting to know PHP OOP concepts, and I started trying by writing a class and handful of functions to connect to the database and retrieve the information from the tables. I went through previous posts having similar titles, but most of them have written using mysql functions and I am using mysqli functions. I want somebody to through this simple script and let me know where the mistake is. This is my class.connect.php: Code: [Select] <?php class mySQL{ var $host; var $username; var $password; var $database; public $dbc; public function connect($set_host, $set_username, $set_password, $set_database) { $this->host = $set_host; $this->username = $set_username; $this->password = $set_password; $this->database = $set_database; $this->dbc = mysqli_connect($this->host, $this->username, $this->password, $this->database) or die('Error connecting to DB'); } public function query($sql) { return mysqli_query($this->dbc, $sql) or or die('Error:'.mysqli_error($this->dbc).', query: '.$sql); } public function fetch($sql) { $array = mysqli_fetch_array($this->query($sql)); return $array; } public function close() { return mysqli_close($this->dbc); } } ?> This is my index.php: Code: [Select] <?php require_once ("class.connect.php"); $connection = new mySQL(); $connection->connect('localhost', 'myDB', 'joker', 'names_list'); $myquery = "SELECT * FROM list"; $query = $connection->query($myquery); while($array = $connection->fetch($query)) { echo $array['first_name'] . '<br />'; echo $array['last_name'] . '<br />'; } $connection->close(); ?> I am getting a error message "Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1, query: 1" Any idea why this is happening? Thanks why is it that when i try to submit it tells me add a picture but i did added Code: [Select] <?php //decarling some variables $msg = ""; //begin if if($_POST['submitbtn']){ $author = mysql_real_escape_string($_POST['author']); $date = mysql_real_escape_string($_POST['date']); $picture = $_FILES['picture']['name']; $ext = strtolower(substr($name,strpos($name,'.')+1)); $size = $_FILES['picture']['size']; $maxsize = 200000; $type = $_FILES['picture']['type']; $tmp = $_FILES['picture']['tmp_name']; $review = mysql_real_escape_string($_POST['review']); $move = "uploads/"; if(isset($author) && !empty($author)){ if(isset($date) && !empty($date)){ if(isset($picture) && !empty($picture)){ if($size <= $maxsize){ if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){ if(move_uploaded_file($tmp,$move.$name)){ if(isset($review) && !empty($review)){ $query = mysql_query(" INSERT INTO reviews ('',author,date,picture,review) VALUES ('',$author,$date,$picture,$review)"); }else $msg = "Please write a review"; }else $msg = "Error has happen try again later"; }else $msg = "Image must be a jpg, jpeg, or png"; }else $msg = "You must select a smaller image size"; }else $msg = "Select a picture"; }else $msg = "Please enter a date"; }else $msg = "Please fill in the Authors name"; } //ending the if here ?> I've develped this small script to display user reviews stored in a my databases review table. The problem with the script though is that it seems to be looping ad nauseum. The wierd thing though, is that I've used a very similair script to display another list of items on this site, and it worked correctly without any issue. Could someone take a look at this for me and diagnose the error with the script. The SQL table: Code: [Select] CREATE TABLE IF NOT EXISTS `rev` ( `id` int(11) NOT NULL AUTO_INCREMENT, `rev_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `usr_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `text` varchar(600) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; The PHP script: Code: [Select] User reviews for <? echo $member;?> <br> <table border="0"> <?php for($count = 1; $count <= $revrows; $count++) { $sqlrev = "SELECT * FROM rev WHERE rev_name = '$member' ORDER BY id DESC"; $revresult = mysql_query($sqlrev) or die(mysql_error()); $revrows = mysql_fetch_row($revresult); $revname = mysql_fetch_array($revresult); ?> <tr> <?php print "Review by: " . $revname['usr_name'] . "<br>". $revname['text']; ?> </tr> <?php } ?> </table> Heya folks, I came here in hope someone could shed some light on the situation I'm in, it's probably looking me straight in the face and I cant see it.. So basically, I've got my page sorted, I'll theme it for my website later, but it echo's out entry's from a SQL database (images to be reviewed) then it has the name, id and accept and reject buttons. Currently I have the page echoing perfectly, the reject button removes from SQL but does not delete the actual image (that's where I need help) The accept button currently has no function as I've tried INSERT INTO but I cant get it working, so here's some code I hope someone knows what's missing Page that echo's from SQL; Code: [Select] <?php $dbHost = "xxxxxxx"; $dbUser = "xxxxxxx"; $dbPass = "xxxxxxx"; $dbName = "xxxxxxxx"; $db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbName,$db); $image_name='fullsize' ?> <?php $result = mysql_query("SELECT id, fullsize FROM tblimages"); $filename['fullsize'] ?> <html> <table> <tr> <td>Image Uploads</td> </tr> <?php while($row = mysql_fetch_array($result)) : $image = $row['fullsize'] ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['fullsize']; ?></td> <td><?php echo '<img src= "uploads/'.$row['fullsize'].'" width="180" height="180"/> '; ?> </td> <!-- and so on --> <td> <form action="delete.php" method="post"> <input type="hidden" name="delete_id" value="<?php echo $row['id']; ?>" /> <input type="submit" value="Reject" /> </form> <form action="insert.php" method="post"> <input type="hidden" name="insert_id" value="<?php echo $row['filename']; ?>" /> <input type="submit" value="Accept" /> </form> </td> </tr> <?php endwhile; ?> </table> </html> The delete.php's code is; Code: [Select] <?php if(isset($_POST['delete_id']) && !empty ($_POST['delete_id'])) { $delete_id = mysql_real_escape_string($_POST['delete_id']); mysql_query("DELETE FROM tblimages WHERE `id`=".$delete_id); header('Location: test.php'); } ?> And my insert.php is currently faulty code, so but I used virtually the same as the delete.php but where 'delete_id' is I replaced with 'insert_id' My database is laid out like this, tblimages (this is where images that need to be reviewed are stored) [id, fullsize] <- columns stored inside images (this is where images that have been accepted should be moved to) [filename] <-where images should be inserted to. Hope someone can understand and help with this, if so, thank you very much ^_^ I've been maintaining my old site http://www.tomsfreelance.com even though it's kind of just a business card at this point. So I decided to implement some javascript stuff I had been working on for other reasons. So far it seems to I have some work to do in Firefox, but I think it's working pretty well otherwise.
This is a bit of an oddball of a site and just about 99% javascript.
Feedback is much appreciated!
This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=354376.0 Hello all. I'm a newbie to this site and PHP and trying to build a basic contact/info form for an insurance company. I've been testing what I've done in FF, IE, and Google Chrome, and it seems to be generating consistent results ... but I thought I'd run it past the EXPERTS here, so you can tell me all that I've done wrong. : ) Attached is the PHP page that is triggered by a basic HTML page with check boxes, etc. And below is what a resulting email looks like, which is fine by me (of course this is empty). Thanks for any advice! -RP ------------------------------------------------- Name: Tel: Company: State: Website: Employees: ===== Type of Business ===== Manufacturer: Retailer: Jobber/Restyler: Distributor: Motorsports: Professional Services: ===== Insurance Needs ===== General Liability: Garage/Keepers: Property Building: Property Equipment: Loss of Income: Worker's Comp.: Internet Liability: Life & Disability: Product Liability: Legal Liability: Property Contents: Cargo/Mobile Property: Employee Dishonesty: 401K & Retirement: Health: Other: Personal Comments: ========================= So I was working on this site past month. I know it is too much time for such simple website, but I am a perfectionist and I need to have everything perfect. It is using JQuery, Twitter Bootstrap (I am deep fan of TWBS and I am using it on almost every website I make) and Yeti(?probably, I forgot ) theme from Bootswatch. Of course also FontAwesome for YT, FB, Twitter an GitHub icons. On smaller resolutions it is looking epic (1024x768 etc etc), on mobile devices too, but I am not sure how it looks on HD, HD-ready resolutions (yes, I can use zoom-out in my browser, but it is misleading...). What do you think?
P.S.: Projects in "My Recent Work" are clickable and that will toggle description with some fancy fade effect (using jQuery.toggle()).
P.S.2: I am not sure if I should vertically-center contact text or let it be with big top and bottom padding. What do you think?
P.S.3: Oh, I almost forgot. Website link is here http://deathbeam.github.io/. Yes, I am using GitHub pages, I love git. And nope, I do not bought my own domain yet.
P.S.4: I accept "brutal" criticizm, feel free to be rude
P.S.5: (this is starting to be annoying lol): If you guys have time, can you please tell me what feeling do you have from my subsite http://deathbeam.git...fwphp/index.htm. I tried to keep everything as simple as possible, but I am not sure if it is not too much :/
P.S.6: I am really sorry for my English...
Edited by deathbeam, 08 September 2014 - 01:08 PM. Hello guys,
I am an intermediate level PHP programmer and digging my way through this giant universe of programming,
During this term, I have been able to build logics for problems (simple ones though) using my own thinking etc etc..
Anyway, I fully understand that I still have a lot to learn and I dont have any teachers to guide me through. So I wanted to request that If i submit an application for a quick review, like what I missed, how should I do it next time and guidance like this will seriously help me through.
I know it will be a pain reviewing someone else's apps but i dont have elsewhere to go..
hello dear community i try to find a way to use file_get_contents: a download of set of pages: Can any body review my approach .. and as i thought i can find all 790 resultpages within a certain range between Id= 0 and Id= 100000 i thought, that i can go the way with a loop: http://www.foundationfinder.ch/ShowDetails.php?Id=11233&InterfaceLanguage=&Type=Html http://www.foundationfinder.ch/ShowDetails.php?Id=927&InterfaceLanguage=1&Type=Html http://www.foundationfinder.ch/ShowDetails.php?Id=949&InterfaceLanguage=1&Type=Html http://www.foundationfinder.ch/ShowDetails.php?Id=20011&InterfaceLanguage=1&Type=Html http://www.foundationfinder.ch/ShowDetails.php?Id=10579&InterfaceLanguage=1&Type=Html How to mechanize with a loop from 0 to 10000 and throw out 404 responses once you reach the page we then could use beautifulsoup to get the content (in our case the image file address) but we also could just loop trough the images directely with simple webrequests. Well - how to proceed: like this: <?php // creating a stream! $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Cookie: foo=bar\r\n" ) ); // opens a file $file = file_get_contents('http://www.example.com/', false, $context); ?> a typical page is http://www.foundationfinder.ch/ShowDetails.php?Id=134&InterfaceLanguage=&Type=Html and the related image is at http://www.foundationfinder.ch/ShowDetails.php?Id=134&InterfaceLanguage=&Type=Image after downloading the images we will need to OCR them to extract any useful info, so at some stage we need to look at OCR libs. I think google opensourced one, and since its google it has a good chance it has a python API can anybody review the approach - look forward to hear from you I have spent a little time lately developing a database class (not finished yet) that automatically will escape the data that is sent to it if used properly. I would like to get some input on it and see what some of you guys think of it. Mainly I would like to know if it is easy to use, if there is any potential issues so far, and if there are any suggestions on better ways to do things in the class. I have attached a copy of the class to this post. Here is an example of how to use it: Code: [Select] //create object $db = new db(); //perform query $users = $db->table('users')->select('*')->where("name='%s'")->vars("somename")->getResults(); //another way to perform the query above $db->table('users')->select('*')->where("name='%s'")->vars(array("somename")); $users = $db->getResults(); You will have to change the db connection properties at the top of the db.class.php file for your own connections. Please let me know of any suggestions, questions or issues that you have. In a project that I'm working on I can specify routing rules, which is somewhat similar to mod_rewrite but in PHP. It's currently set up to use full regular expressions, but it's kind of overkill. I'm trying to convert it to use routing rules similar to some of the php frameworks I've seen. The code I've written up below is working, and while it's unlikely that I would need anything more complex, I'm wondering if anyone would like to comment, offer suggestions, or offer criticisms. This little piece of code is just a part of a bigger routing class, but this is the code that I'm concerned with. Thanks.
<?php $cfg['routes'] = [ 'cars/(:any)/(:any)/(:num).php' => 'cars/$3/$1/$2', 'default_route' => 'cars/index', 'trucks/parts?year=(:num)' => 'parts/trucks/$1', 'vans/articles(:any)' => 'articles$1' ]; $uris = [ 'cars/toyota/tercel/2014.php', # /cars/2014/toyota/tercel 'default_route', # /cars/index 'trucks/parts?year=2014', # /parts/trucks/2014 'vans/articles?p=42342' # /articles?p=42342 ]; $i = 0; foreach( $cfg['routes'] as $k => $v ) { $k = '|^' . preg_quote( $k ) . '$|uiD'; $k = str_replace( [ '\(\:any\)', '\(\:alnum\)', '\(\:num\)', '\(\:alpha\)', '\(\:segment\)' ], [ '(.+)', '([[:alnum:]]+)', '([[:digit:]]+)', '([[:alpha:]]+)', '([^/]*)' ], $k ); echo '<br />' . $uris[$i] . '<br />' . $k . '<br />'; if( @preg_match( $k, $uris[$i] ) ) { echo preg_replace( $k, $v, $uris[$i] ) . '<br /><br />'; } $i++; } Hello,
I'm the sole developer of Aptugo (http://www.aptugo.com), a web RAD development environment with focus on making every developer's life easier. I've spent countless hours over the last two years developing it, and while the main focus is to be a CRUD boilerplate, it can actually build complete websites with great features (Aptugo's website was completely built with Aptugo, and google page insights gave me a score of 92 right out of the oven and without any effort).
Anyway, it would be really nice if you could spend a few minutes taking a look at Aptugo, It is free, and I really want to keep it free forever, in order to be able to achieve that, I really mouth-to-mouth promotion, so I'm not trying to sell you anything here, I'm just asking for help and your empathy! . If you could tell me: "I would use aptugo if it..." I would really appreciate it.
Have a great day,
Gaston
i want the code for review approval platform (costumer reviews for a product )and in backend editing the code and updating it if(get_images_for_delete($username, $newid, $mysqli) !== FALSE){ // WE are dealing with images $images = get_images_for_delete($username, $newid, $mysqli); $sourceBucket = "***********"; $targetBucket = "***********"; foreach($images as $image){ // copy our object $aws = new s3; $aws = $aws->copyObject($targetBucket, $image, $sourceBucket, $image); // delete our object $aws_delete = new s3; $aws_delete = $aws_delete->deleteObject($image); // copy our (thumbnail) object $aws2 = new s3; $aws2 = $aws2->copyObject($targetBucket, "thumb_".$image, $sourceBucket, "thumb_".$image); // delete our (thumbnail) object $aws_delete2 = new s3; $aws_delete2 = $aws_delete2->deleteObject("thumb_".$image); }Is my code. Do I need to declare so many new s3 classes? All the methods are within the same class. Not sure if this is the correct way to go about it. I have a problem with the below code: Code: [Select] <?php $sql_ranks = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date > '$last_sunday' AND vtp_tracking.action_date < '$next_sunday' GROUP BY teams.team_name ORDER BY surfs DESC"); $rsranks = mysql_query($sql_ranks); echo "<br><table align='center' valign='top' border='0' width='300px'> <tr><td colspan='2' align='center'><font size='2px'><b>Team Rankings (Current Week)</b></font></td></tr> <tr><td><font size='2px'><b>Team</font></td><td align='right'><font size='2px'>Total Surfs</font></td></tr>"; while ($row = mysql_fetch_array($rsranks)) { echo "<tr><td><font size='2px'><b>".$row[team_name]."</font></td><td align='right'><font size='2px'>".$row[surfs]."</font></td></tr>";} echo "</table>"; ?> Problem is that the last output (".$row[surfs].") is the same for all teams. It seems it is not making a total of all id's and not per team_name. anyone can see what I am doing wrong. I need to sort by team_name and the surfs should display the total of the members with team_id is ".$_GET['t']." |