PHP - Using Curl For Database Matching
I have a list of companies I have to look up information for on the entity search page for the state.
here is what i have so far except there seems to be a verification error. Anyone know how to fix this so the page will display results? <?php // INIT CURL $ch = curl_init(); // SET URL FOR THE POST FORM LOGIN curl_setopt($ch, CURLOPT_URL, 'http://appext9.dos.state.ny.us/corp_public/CORPSEARCH.SELECT_ENTITY'); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); //set curl options curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2. Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729)"); curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEJAR, 'CURLCOOKIE'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); //visit page to get cookies //$strGet_page_contents = curl_exec ($ch); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'p_entity_name=Apple LLC&p_name_type=Arwen&p_search_type=BEGINS&submit=Search!'); // EXECUTE $store = curl_exec ($ch); echo curl_exec ($ch); // CLOSE CURL curl_close ($ch); ?> Similar TutorialsHere we go, I need to use a query where it uses a posted time value to compare if there are the same times on the posted date value. I want it so the user cant book the same time on the same day as someone before bascially. My input so far is this Code: [Select] <?php ob_start();?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Conforming XHTML 1.0 Strict Template</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link type="text/css" href="ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" /> <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> </head> <body> <form name="input" action="input.php" method="post"> Subject: <input type="text" name="subject" /> First Name: <input type="text" name="firstname" /> Surname: <input type="text" name="surname" /> Trainer: <input type="text" name="trainer" /> Email: <input type="text" name="email" /> Date: <input type="text" name="event_date" id="date" /> Time: <input type="text" name="event_time" id="time" /> <input type="submit" value="Submit" name="submit" /> </form> <script type="text/javascript"> $('#date').datepicker(); $('#time').timepicker({}); </script> <?php include_once("functions/database.php"); include_once("functions/number.php"); if (isset($_POST["submit"])) { echo $_POST['event_date']; echo mdy2mysql($_POST['event_date']); echo $_POST['event_time']; echo time2mysql($_POST['event_time']); $queryselect = "SELECT * FROM events LIKE '".$_POST['event_time']."'"; if ($queryselect == true) { echo "sorry this time is already booked"; } else { $query = "INSERT INTO events (subject, firstname, surname, trainer, email, event_date, event_time, status) VALUES('".$_POST["subject"]."', '".$_POST["firstname"]."', '".$_POST["surname"]."','".$_POST["trainer"]."','".$_POST["email"]."' ,'".mdy2mysql($_POST['event_date'])."','".time2mysql($_POST['event_time'])."', 'pending' ) "; $result = mysql_query($query, $db_link) or die(mysql_error().'cannot get results!'); header("Location: input.php"); } ?> can anyone help me ? very much appreciated. Hi, i'm currently building essentially an API for my URL shortener site so other sites can implement it. But i've hit a stumbling block on the last script of the lot(the others merely collate the data and store it) In this last script, i need to find all this data, stored in cookies and inout it into the database, as the main site does(i'm confident this bit works, as it's the code from the main site just copied across, and i can see the data in the database). Importantly, i then need o look in another table for the callback URL to send the data back to $urltoshorten = $_COOKIE["URLtoShorten"]; $alias = $_COOKIE["urlalias"]; $key = $_COOKIE["key"]; //connection details go in here $alias =mysql_real_escape_string($alias); $urltoshorten = mysql_real_escape_string($urltoshorten); $base = "http://s-url.co.uk/i/?id="; $url = $base . $alias ; //this is the main bit, where the URL shortening occurs mysql_query("INSERT INTO table (id, name) VALUES('$alias', '$urltoshorten')")or die( mysql_error()); //this is where the callback url is looked for $result= mysql_query("SELECT apiaddress FROM apistuff WHERE apinumber='$key'")or die( mysql_error()); $row = mysql_fetch_array($result); $new = $row[apiaddress]; //I then start a CURL session to POST data to the page in question, as found above $Curl_Session = curl_init($new); curl_setopt ($Curl_Session, CURLOPT_POST, 1); curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "shortenedurl=$url"); curl_exec ($Curl_Session); curl_close ($Curl_Session); annoyingly, no errors get thrown, as far as i can see, i just end at a blank page without being returned to the callback page. I'm rather stumped on this one, where am i likely to be going wrong/how do i go about correcting it. Cheers Joe good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. Hi, I am in the procress of creating discussion system however I am a bit puzzled about the best way to go about it. I am starting the discussion by creating an ID number and then match the answer to the initial ID number. However, I dont know whether if is best to put the responses into a different database. I'm a bit puzzled how ID matching systems works. Lets say: Question 1 = ID1 Question 2 = ID2 Question 3 = ID3 Question 1 Answer 1 = ID4 (How is this matched to ID1) Question 2 Answer 1 = ID5 (How is this matched to ID2) is this based on preg_match? Wondering if someone could help me. What I am trying to do is display the information from each row. I am trying to read from 2 tables and display them on a page. I want them to show like this name,make,type, price,"images/listings/a1.jpg,images/listings/a2.jpg,images/listings/a3.jpg,images/listings/a4.jpg,images/listings/a5.jpg,images/listings/a5.jpg" name,make,type, price,"images/listings/b1.jpg,images/listings/b2.jpg,images/listings/b3.jpg,images/listings/b4.jpg,images/listings/b5.jpg,images/listings/b5.jpg" Example. the table structures are as so: Code: [Select] listings -------------------------------- id name make type price (then a couple more columns I dont need data from) -------------------------------- 1 name1 make1 type1 price1 2 name2 make2 type2 price2 3 name3 make3 type3 price3 listimages ---------------------------------------------------- id imagepath mainimage listingid ---------------------------------------------------- 1 images/listings/a1.jpg 1 1 2 images/listings/a2.jpg 0 1 3 images/listings/a3.jpg 0 1 4 images/listings/a4.jpg 0 1 5 images/listings/a5.jpg 0 1 6 images/listings/a6.jpg 0 1 7 images/listings/b1.jpg 1 2 8 images/listings/b2.jpg 0 2 9 images/listings/b3.jpg 0 2 10 images/listings/b4.jpg 0 2 11 images/listings/b5.jpg 0 2 12 images/listings/b6.jpg 0 2 13 images/listings/c1.jpg 1 3 etc Here is the code I am using. Everything works except some of the listing images don't match up to the names. I think when certain names don't have pictures it just moves up the images to the next person. I need to somehow associate the listingid column from listimages table with the id column from the listings table. The mainimage column tells what image of the group of images is default for that name. 1 being the default 0 not the default Here is the code I am using. Code: [Select] <?php // Make a MySQL Connection mysql_connect("localhost", "xxxxxx", "xxxxxx") or die(mysql_error()); mysql_select_db("xxxxxx") or die(mysql_error()); $result = mysql_query("SELECT * FROM listings l JOIN listimages li ON l.id = li.listingid ORDER BY l.id DESC") or die(mysql_error()); $last_listingid = null; $curRow = array(); while($row = mysql_fetch_array($result)) { // Check for a difference in listing ID - and if it is, then we should show the previous row first if ($last_listingid != $row['listingid'] && $last_listingid !== null) { // Implode the array with quotes around it echo $row['name']; echo ","; echo $row['make']; echo ","; echo $row['model']; echo ","; echo $row['type']; echo ","; echo $row['price']; echo ","; echo '"' . implode(',', $curRow) . '"<br />'; // And start fresh $curRow = array(); } // Now we can save it to the array $curRow[] = $row['imagepath']; // And set the new ID $last_listingid = $row['listingid']; } // Finally, we'll need to implode it one last time since there should always be at least one value in the array echo '"' . implode(',', $curRow) . '"'; ?> Please let me know what I am doing wrong Anyone Thanks I'm working a membership application page for my amateur radio club. I'm currently stumped passing a variable from HTML to PHP. The variable is called "nametag" and it's a "radio" type. No Matter if I select 10 or 0. I still get 15 being passed to PHP.
Any help is appreciated.
Thanks -HP Garcia What I'm trying to do is have it match up the image file name wiht the same name as the link. Sometimes it does but sometimes obviously the image is random. Any ideas? Code: [Select] function spotlight($dbc){ $query = " SELECT * FROM characters WHERE characters.statusID = 1 AND characters.styleID = 1 ORDER BY RAND() LIMIT 1"; $result = mysqli_query($dbc, $query); $row = mysqli_fetch_array($result); $shortName = $row[ 'shortName' ]; $labels = array('shortName'); $img = array(); if($handle = opendir('images/spotlight/')) { $count = 0; while (false !== ($file = readdir($handle))) { if(strlen($file) > 2){ $img[$count] = $file; $count++; } } } echo "<a href='bio.php?shortName=" . $shortName . "'><img src='/images/spotlight/".$img[rand(0, (count($img)-1))]."' alt=Spotlight border=0 /></a>"; }
I wish to find the closest two DateTimes which are within $fillStart and $fillEnd and have the same week and 24 hour times as $gapStart and $gapEnd. For instance, the following results in $fillStartModified and $fillEndModified which meets that criteria. fillStart 2019-07-23 00:15:00 Tue fillEnd 2019-09-23 13:00:00 Mon gapStart 2019-05-23 00:15:00 Thu gapEnd 2019-06-23 13:00:00 Sun fillStartModified 2019-07-25 00:15:00 Thu fillEndModified 2019-08-25 13:00:00 Sun I came up with the following which seems to work, but it is kind of complicated and I am not positive it will meet all edge conditions. Any recommendations? Thanks function getFill(\DateTimeImmutable $fillStart, \DateTimeImmutable $fillEnd, \DateTimeInterface $gapStart, \DateTimeInterface $gapEnd) { //$gapInterval = $gapStart->diff($gapEnd); // Doesn't work $gapInterval = new \DateInterval('PT'.($gapEnd->getTimestamp() - $gapStart->getTimestamp()).'S'); if($gapStart > $fillStart) { //The fill is older than the gap so make the fill's endTime match the gap's endTime $fillEndModified = $fillEnd ->modify('previous '.$gapEnd->format('D')) ->setTime(...explode('.', $gapEnd->format('H.i.s.u'))); if($fillEndModified->diff($fillEnd)->format('%a') >= 7) { $fillEndModified = $fillEndModified->add(new \DateInterval('P7D')); } $fillStartModified = $fillEndModified->sub($gapInterval); if($fillStartModified < $fillStart) { $fillStartModified=null; $fillEndModified=null; } } else { //The fill is newer than the gap so make the fill's startTime match the gap's startTime $fillStartModified = $fillStart ->modify('next '.$gapStart->format('D')) ->setTime(...explode('.', $gapStart->format('H.i.s.u'))); if($fillStart->diff($fillStartModified)->format('%a') >= 7) { $fillStartModified = $fillStartModified->sub(new \DateInterval('P7D')); } $fillEndModified = $fillStartModified->add($gapInterval); if($fillEndModified > $fillEnd) { $fillStartModified=null; $fillEndModified=null; } } return [$fillStartModified, $fillEndModified]; }
Hi there im just trying to understand how to compare and output results in a table. For example lets say i have the following table: Beans ID Type Location And say 3 records: 1 Baked kitchen 2 Runners Garage 3 Broad Kitchen I want to select only the beans that have matching locations and output the Type: Baked, Broad. I'm trying to get my head around how to work this out, if you could nudge me in the right direction that would be excellent. Thank you. Hello
So I want to try and match everything preceding a file extension in a string using preg_match.
An example file name: "Images_home_blah.blah.jpg" .
I've tried the following regex:
/^([a-z0-9_\-\.]+)(?!\.jpg)/iBut this sadly appears to capture the whole string instead of ignoring the '.jpg' part. Can anyone point me in the right direction? Thanks, Drongo Basically i want to take an array of numbers let's say: Code: [Select] <? $array1=array("1","2","3","4"); ?> Now say i reprint that same array, but the 3 is missing. Code: [Select] <? $array2=array("1","2","4"); ?> How would i print what's missing from $array1 out of $array2? Sorry if this is confusing, i'll be happy to go into details if needed. Hello group. I need some help with my code.
<?php
$a1 = array("line1"=>"1-2-3-10-14","line2"=>"1-2-3-10-34","line3"=>"1-2-7-16-35","line4"=>"1-2-3-17-19","line5"=>"2-5-11-15-32");
$result = array_intersect($a1,$a2); ?> Right now, I can only search and find an exact match of all 5-Numbers. I want to code a PHP form that will take a (5-number string) as input and then compare that string against an array database of (5-number strings) to find all matching number occurrences for each “LINE 1 thru LINE 5”. For instance, if I were to type the 5-number string “1-2-3-10-34” as input. The Output populated results would look like this .. Edited February 21, 2019 by Jayfromsandiego I am trying to identify the username from a series of windows logs. I have been using (?:User Name:|Account Name:)\s*([\S]+) and it works for examples 1-4, however I'm having problems with example 5. Because it has two occurrences of the pattern Account Name: in the string I can only get the regex to return the first match, i.e. USER-PC$. How can I tell regex, that if there are two Account Name: patterns in the string, or the string contains the pattern "New Logon:" then return the second Account Name: match, i.e. John.Doe? eg 1 - The screen saver was invoked. Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4091 Session ID: 1 eg 2 - User initiated logoff: Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0x3d95c This event is generated when a logoff is initiated. No further user-initiated activity can occur. This event can be interpreted as a logoff event. eg 3 - User Logoff: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x458E4AB4) Logon Type: 8 eg 4 - Successful Network Logon: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x43) Logon Type: 8 Logon Process: Advapi Authentication Package: Negotiate Workstation Name: USER-PC Logon GUID: {2e483a4f-} Caller User Name: USER-PC $ Caller Domain: INTERNAL Caller Logon ID: (0x0,0x7) Caller Process ID: 4816 Transited Services: - Source Network Address: xx.xxx.xx.x Source Port: 35029 eg 5 - An account was successfully logged on. Subject: Security ID: S-X-X Account Name: USER-PC$ Account Domain: INTERNAL Logon ID: 0x3e7 Logon Type: 2 New Logon: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4062 Logon GUID: {23-xx-22} Process Information: Process ID: 0x2fc Process Name: C:\Windows\System32\winlogon.exe Network Information: Workstation Name: USER-PC Source Network Address: xx.x.x.x Source Port: 0 Any help would be appreciated:) Hey, I need a bit of help replacing some variables in a string. I know its done with preg_replace. Here is the string: Code: [Select] Header 1 <|header 2|> header 3 <b>header 4</b> I would like to get ONLY <|header 2|> from the above string. But "header 2" is variable so please its useless if the preg_replace isn't flexible to find whatever word is in there regardless. Thanks you. In the below example, we match 0 or more alphanumeric characters in the beginning and 0 or more alphanumeric characters in the end. Then we create 4 groups. Each group has "?=" which means "the next text must be like this". Now in first group we match any character 8 or more times. The next group we match 0 or more characters and a digit. In the next group we match 0 or more characters and a lowercase letter. In the next group we match 0 or more characters and an uppercase letter.
<?php $password = "Fyfjk34sdfjfsjq7"; if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password)) { echo "Your passwords is strong."; } else { echo "Your password is weak."; } ?>My question is do these four groups impact each other? That is, the fact that the first group has 8 or more characters means that all the groups must have 8 or more characters. The fact that the second group has a digit means that all the groups must have a digit. Or do they work exclusively meaning that a 4 character word with a single digit would match this pattern, even though first group says it must have 8 characters. Hi I'm trying to match @USERNAME in a string and replace it with @<a href="message.php?member=USERNAME">USERNAME</a> I've tried a few different methods: Code: [Select] preg_replace ('/@(.*?)/', '<a href="message.php?member=$1">$1</a>', $str)and also * and \@ but i just can't seem to get it to work. any help would be appreciated! Hi everyone, My code is meant to give a certain response if the hospital number & PIN together do or do not match. However, whatever I input, whether it is correct information or random numbers, I still get the output that the data has been submitted successfully. Any thoughts?
<?php $connect = mysqli_connect($hostname, $username, $password, $databaseName); $query = "UPDATE card SET comments = '$comments' , seniorsent = '$seniorsent' WHERE hospitalnumber = '$hospitalnumber' and PIN = '$PIN'"; @mysqli_query($connect, $query); $result = mysqli_query($connect, $query); if($result) { echo 'Data submitted successfully'; }else{ echo 'Please check that all details are correct'; } >
Thanks in advance, samanj Say i have two arrays with custom keys. What would be the easiest way to write a function that would determine if all the keys in arrayOne are in arrayTwo? The example below would return false because keys 3 and 4 are missing in arrayTwo. Any help would be much appreciate. thanks! Code: [Select] <?php $arrayOne['1'] = "adg"; $arrayOne['2'] = "a4g"; $arrayOne['3'] = "346"; $arrayOne['4'] = "etwe"; $arrayTwo['1'] = "xcb"; $arrayTwo['2'] = "acbr"; $arrayTwo['6'] = "yiy"; $arrayTwo['7'] = "mmm"; ?> I attempted to try to do what was in the comments, but I am not able to do it any help is appreciated Code: [Select] <?php $a = array(9, 3, 1, 0, 99, 2, 5, 6, 32, 1, 55); $b = array(9, 18, 1, 0, 23, 22, 4, 6, 5, 32, 55); function getAverage () { echo "The average is " . array_sum($a) . "\n"; // Show the sum of the entire array (should display 19.36) } getAverage(); echo "<br><br>"; function highestValue() { echo $a[max]; // Show the index value of the highest number (should display 4) echo $a(max); // Show the value of index 4 (should display 99) echo $a[min]; // Show the index value of lowest number (should display 3) echo $a(min); // Show the value of index 4 (should display 0) } highestValue(); echo "<br><br>"; function displayMatch() { //Write a function that tests the values of both arrays. If the values at the same index match display the following: "The values at <insert the matching index> match." } displayMatch(); ?> |