PHP - Output Data From Yahoo Csv
Hey guys, newbie here love the site, lots of great info, hopefully one of u guys can help me out.
i have adapted code from http://www.singhvishwajeet.com/2009/06/25/using-php-to-get-stock-quotes-from-yahoo-finance/ (which is free to use) i have been working on a way to enter a company code, e.g. BARC -barclays bank, on one page then on another im trying to serahc the yahoo csv for a number of specific numbers that are "live" and then output them on my site, which in turn i shall work with but i cant seem to out put the data, its the $stat bit im struggling with i will attach the files, hopefully someone can help me Similar TutorialsHi, I have an image (a weather map) which is created using php which pulls data from a mysql database. I would like to be able to output the result image as a gif or jpg file. Can anyone suggest how this could be done? Many thanks, Simon Hi all, I'm recent working on my php to extract some data from mysql database. Is it possible to output the database data into <a href> turn to the hyperlink instead of using http://mysite.freesite.com/mydatalink.com to this http://mydatalink.com? The script I have made so far is doing something wrong and I can't be able to find the solution. here's the current code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var) { return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />', $errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $qrytable1="SELECT id, links FROM mydatalist WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="' . $row["links"] . '">Link</a> </td>'; } } } } ?> I don't want to adding an <a href> into the first echo statement, because I am stored the links in the database which you can see that I am using ['links']. I need to ouput the data from the db to turn into hyperlink. If anyone could assist with this I'd be very grateful! Thanks, Mark Hello, I seem to have some problem with my script that has a goal of outputting data about the file size when a filename is queried.
The sql table name is file
The table columns are as followed: id | name | mime | size
The file name is stored in name. The script that i have that gets the file name is:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>File Select</title> <!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--><script>var __adobewebfontsappname__="dreamweaver"</script><script src="http://use.edgefonts.net/aguafina-script:n4:default.js" type="text/javascript"></script> </head> <body> <div id="title"> <h3 align="center">File Upload</h3> </div> <form action="result.php" method="post" name="fileID" target="_self" class="inp" AUTOCOMPLETE="ON"> <h1> <!--Input file name--> <label for="fileID">File Name: </label> <input type="text" name='file1' id='sampleID' list="samp"> </input><br> <datalist id="samp"> <?php $connect = mysql_connect('localhost', 'root', ''); mysql_select_db("test_db"); $query = mysql_query("SELECT * FROM `file` ORDER BY `file`.`name` ASC LIMIT 0 , 30"); WHILE ($rows = mysql_fetch_array($query)): $File_name = $rows['name']; echo "<option value=$File_name>$File_name/option> <br>"; endwhile; ?> </datalist> <input type="submit" class="button" > </form> </body> </html> I'm not even sure how to explain it. I'm linking a team's roster to its coach. Now I'm getting a weird offset issue when I output the roster. It has something to do with the STATUS. Down below DIV class="roster_player_list", my Status values are 1, 2, 3, or 4, and each is then assigned a word value. My output should look like this (without the arrow and number) : Returning Starter <---- 1 # # # Key Returner <--- 2 # # Varsity Newcomer <--- 3 # # # Key Freshmen <--- 4 # The last "1" (Returning Starter) disappears from my list on both of my test accounts. I should have four Returning Starters instead of three. I've changed a player's status from a 2 to a 1, and the list changed. That player disappeared, the other appeared. Code: [Select] $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE s.coachFirst='".$current_first."' AND s.coachLast='".$current_last."' AND s.id = p.tid ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="roster_team_info">' . $current_first . ' ' . $current_last . ' <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; echo '<div class="roster_player_list">'; $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; } Hey Guys, I'm struggling with some logic of how to do something wondering if anyone can point me in the right direction. Details: I am making a PHP/MySQL game to learn more PHP, I've got my login/logout system created. However I am planning on the game been map based on a 100x100 grid. I have two tables: USERS Username, Password, x, y Test, Test, 1, 1 MAP X, Y, type 0,1,1 0,2,1 0,3,2 0,4,3 0,5,2 etc I am stuck on how to get the user's logged in X and Y coordinates and then compare them with the map table X and Y, to see what type of field to show, 1,2 or 3. Is there a name for this type of function so I can do some research on it? Or could someone give me an example? Would be fantastic if anyone has any advice. Thanks in advance NewcastleFan trying to create a simpleprogram that will read a text file and output information and calculations using the data in the text file. I have 4 radio buttons which represent an item Number. when one is selected the output form should print to a table the ID,Part,Count, Price, and the inventory Value= ($count * $price), can anyone tell me what i am doing wrong? This is what the .txt file looks like: AC1000:Hammers:122:12.50 AC1001:Wrenches:5:5.00 AC1002:Handsaws:10:10.00 AC1003:Screwdrivers:222:3.00 Here's what i have so far: Code: [Select] <?php $inf = 'infile.txt'; $FILEH = fopen($inf, 'r') or die ("Cannot open $inf"); $inline = fgets($FILEH,4096); $found = 0; //$ptno = //if (isset($_POST['AC1000']) || isset($_POST['AC1000']) || isset($_POST['AC1000']) || isset($_POST['AC1000'])) { while (!feof($FILEH) && !($found)){ list($ptno,$ptname,$num,$price) = split (':', $inline); if ($ptno == $id) { print '<table border=1>'; print '<th> ID <th> Part <th> Count <th> Price'; print "<tr><td> $ptno </td><td>$ptname</td>"; print "<td> $num </td><td> \$price</td><tr>"; print '</table>'; $found = 1; } $inline = fgets($FILEH,4096); } if ($found !=1) { print "Error: PartNo=$id not found"; } fclose ($FILEH); ?> Hi guys, is there anyway to process this $result from a mysql query inside PHP so that the data below will be formatted to a pivot-like table? The number of rows and columns of the output 'table' will be indefinite. Thanks so much! Data: ID Row Col Name 1 1 A A1 2 2 A A2 3 3 A A3 4 1 B B1 5 2 B B2 6 3 B B3 7 1 C C1 8 2 C C2 9 3 C C3 Results: A1(1) A2(2) A3(3) B1(4) B2(5) B3(6) C1(7) C2( C3(9) Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. Hi every one I've downloaded some classes but they weren't work . How do I send a private message? thanks If your working with Yahoo API, or Yahoo Scraping, is there a way to detect the 999 error. I have an App that deals heavily with Yahoo scraping. However, Yahoo after awhile has the 999 error. What I want to do is detect when it returns the error, serialize all the arrays up into a database, and allow the client to try it again later when Yahoo has removed it's blocking restriction (after about an hour). So, what I have thought about is doing a standard detection script. Just to see if the text 999 was found. SO the function that I use to get data from Yahoo, after awhile it returns: Quote Warning: file_get_contents(http://siteexplorer.search.yahoo.com/search?p=http://http://www.seomarketing.com&bwm=i&bwmf=u&bwms=p&fr2=seo-rd-se&b=1501) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 999 Unable to process request at this time -- error 999 in /var/www/vhosts/seomarketing.com/httpdocs/seotools/competitiveanalysis/functions.php on line 86 What I want to do is supress that error (Which I can do with Error Reporting, or the @ symbol. That is easy. What I also want to do is put up a conditional. if (file_get_contents($url) throws a warning) { // Do some database work. } I can't figure out the best way to approach this. Any advice? Hello, everyone. I'm still kind of new at this, so please bear with me. I've customized a website (hosted by Yahoo Small Business) which is now fully functional aside from the "Contact Us" page. I have a PHP file named "send_email.php" uploaded to my root directory which has the following code: <?php $contact_name = $_POST['name']; $contact_email = $_POST['email']; $contact_subject = $_POST['subject']; $contact_message = $_POST['message']; if( $contact_name == true ) { $sender = $contact_email; $receiver = "my@email.com"; $client_ip = $_SERVER['REMOTE_ADDR']; $email_body = "Name: $contact_name \nEmail: $sender \n\nSubject: $contact_subject \n\nMessage: \n\n$contact_message \n\nIP: $client_ip \n\nFlash Contact Form provided by http://www.flashmo.com"; $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion(); if( mail( $receiver, "Flash Contact Form - $contact_subject", $email_body, $extra ) ) { echo "success=yes"; } else { echo "success=no"; } } ?> I went ahead and changed "my@email.com" to my actual email address. The problem I'm having, though, is that the form fails every time...except if I enter my own email address in the "Email" field which should be filled in by the customer. I can't figure this out. It's probably something simple that I'm doing wrong, or perhaps it has something to do with Yahoo Web Hosting. I'm also thinking I have to fill something in the "Client IP" section of the code...but I'm not sure what should go there. I'd really appreciate your time and responses. Thanks so much. Hello, For months I'm looking for a weather script for my modest blog I finally have a php script that displays yahoo weather (5 days) in English (TUE, WEN, THU, ...) It would be nice if someone can tell me if there is a way, function or script, to translate these days in French Yahoo team says that it is not possible :http://developer.yahoo.com/forum/General-Discussion-at-YDN/Can-Yahoo-Weather-API-show-by/1275022713000-d78748d9-0247-313b-ad9e-3503b8ea3d07 Cordially, Kim. Hello ive Googled around for ages for a PHP script that Shows the yahoo user statuts .. but the only thing i ve found is this link from yahoo thats saying the Online/Offline statuts http://opi.yahoo.com/online?u= ive heared that theres some way of sending a bot to the id and see if its on invisible .. dos anyone know a way to do it ? It seems something has changed at Yahoo Finance. I use a Stock quote script (micro stock) to post stock quotes from specific tickers on my website. It worked fine for years until recently. Now i am unable to access any data directly from any Yahoo finance URL. Hereafter my script which comes from 1) Micro Stock : http://www.phptoys.com/product/micro-stock.html or 2) Getting Stock Quote : http://www.phptoys.com/tutorial/getting-stock-quote.html <?php function getStockSite($stockLink){ if ($fp = fopen($stockLink, 'r')) {$content = ''; while ($line = fread($fp, 1024)) {$content .= $line;}} return $content;} function processStockSite($wurl){ $wrss = getStockSite($wurl); $text = ''; if (strlen($wrss)>100){ // Get text $spos = strpos($wrss,'</span>:',$spos)+3; $spos = strpos($wrss,'<big>',$spos); $epos = strpos($wrss,'</div><h1>',$spos); if ($epos>$spos){ $text = substr($wrss,$spos,$epos-$spos);} else {$text = '-';}} // Get results $result['text'] = $text; return $result;} <html> <head> <title>Get Stock tutorial</title> </head> <body> <?php // Get stock data $data = processStockSite('http://finance.yahoo.com/q?s=GOOG'); echo $data['text']; ?> I am not php programmer and i hope someone can help me in this matter since that script was a marvel. Thank in advance. I have successfully used the Yahoo local search API and received results in XML format. I am trying to use PHPs Simple XML to parse the data into an array so I can loop through and print specific elements. I cannot get to specific elements and I have read several threads online. Below is some code and below that is the XML. I am trying to get to the elements like title, address, etc. Code: [Select] $url = 'http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=<my yahoo api key>&category=Casinos&query=blackjack&zip=95035&radius=20&results=10'; $xml = file_get_contents($url); $phpobject = simplexml_load_string($xml); foreach($phpobject->attributes() as $name=>$attr) { $res[$name]=$attr; } Code: [Select] <ResultSet xsi:schemaLocation="urn:yahoo:lcl http://local.yahooapis.com/LocalSearchService/V3/LocalSearchResponse.xsd" totalResultsAvailable="48" totalResultsReturned="10" firstResultPosition="1"> − <ResultSetMapUrl> http://maps.yahoo.com/broadband/?q1=Milpitas%2C+CA+95035&tt=poker&tp=1 </ResultSetMapUrl> − <Result id="34179399"> <Title>Bay Area Poker Chip</Title> <Address>1274 Piper Dr</Address> <City>Milpitas</City> <State>CA</State> <Phone>(408) 263-8611</Phone> <Latitude>37.412359</Latitude> <Longitude>-121.891794</Longitude> − <Rating> <AverageRating>5</AverageRating> <TotalRatings>1</TotalRatings> <TotalReviews>1</TotalReviews> <LastReviewDate>1198993183</LastReviewDate> − <LastReviewIntro> I bought 100% real clay chips from here and obsolutely love it. I had a poker game that night and needed chips and a table. They had everything in stock and saved me time to look around. Great products and great service and I highly recommend this place to anybody </LastReviewIntro> </Rating> <Distance>1.33</Distance> − <Url> http://local.yahoo.com/info-34179399-bay-area-poker-chip-milpitas </Url> − <ClickUrl> http://local.yahoo.com/info-34179399-bay-area-poker-chip-milpitas </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1274+Piper+Dr+Milpitas+CA&gid1=34179399 </MapUrl> <BusinessUrl>http://bayareapokerchip.com/</BusinessUrl> <BusinessClickUrl>http://bayareapokerchip.com/</BusinessClickUrl> − <Categories> <Category id="96928631">Graphic Design</Category> </Categories> </Result> − <Result id="44540748"> <Title>Bay Area Poker Chip</Title> <Address>519 Montague Expy</Address> <City>Milpitas</City> <State>CA</State> <Phone>(408) 263-8611</Phone> <Latitude>37.409925</Latitude> <Longitude>-121.89489</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>1.48</Distance> − <Url> http://local.yahoo.com/info-44540748-bay-area-poker-chip-milpitas </Url> − <ClickUrl> http://local.yahoo.com/info-44540748-bay-area-poker-chip-milpitas </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=519+Montague+Expy+Milpitas+CA&gid1=44540748 </MapUrl> <BusinessUrl>http://www.bayareapokerchip.com/</BusinessUrl> <BusinessClickUrl>http://www.bayareapokerchip.com/</BusinessClickUrl> − <Categories> <Category id="96925976">Sporting Goods</Category> <Category id="96935378">Games</Category> </Categories> </Result> − <Result id="67710717"> <Title>Poker Da Vinci</Title> <Address>51 E Campbell Ave</Address> <City>Campbell</City> <State>CA</State> <Phone>(408) 866-4446</Phone> <Latitude>37.287157</Latitude> <Longitude>-121.94942</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>10.40</Distance> − <Url> http://local.yahoo.com/info-67710717-poker-da-vinci-campbell </Url> − <ClickUrl> http://local.yahoo.com/info-67710717-poker-da-vinci-campbell </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=51+E+Campbell+Ave+Campbell+CA&gid1=67710717 </MapUrl> <Categories/> </Result> − <Result id="21599986"> <Title>Bay 101 Banquet Facilities</Title> <Address>1801 Bering Dr</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 451-8888</Phone> <Latitude>37.373044</Latitude> <Longitude>-121.912125</Longitude> − <Rating> <AverageRating>4</AverageRating> <TotalRatings>2</TotalRatings> <TotalReviews>2</TotalReviews> <LastReviewDate>1200040214</LastReviewDate> − <LastReviewIntro> If youre looking for high limit action Bay 101 is the place to go in San Jose. You can regularly find limit games up to $80-$160 in their spacious high ceiling room. </LastReviewIntro> </Rating> <Distance>4.13</Distance> − <Url> http://local.yahoo.com/info-21599986-bay-101-banquet-facilities-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-21599986-bay-101-banquet-facilities-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1801+Bering+Dr+San+Jose+CA&gid1=21599986 </MapUrl> <BusinessUrl>http://bay101.com/</BusinessUrl> <BusinessClickUrl>http://bay101.com/</BusinessClickUrl> − <Categories> <Category id="96929273">Casinos</Category> </Categories> </Result> − <Result id="21401964"> <Title>Thwart Poker Incorporated</Title> <Address>525 Lincoln Ave</Address> <City>Palo Alto</City> <State>CA</State> <Phone>(650) 329-9627</Phone> <Latitude>37.444049</Latitude> <Longitude>-122.151513</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>14.09</Distance> − <Url> http://local.yahoo.com/info-21401964-thwart-poker-incorporated-palo-alto </Url> − <ClickUrl> http://local.yahoo.com/info-21401964-thwart-poker-incorporated-palo-alto </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=525+Lincoln+Ave+Palo+Alto+CA&gid1=21401964 </MapUrl> − <Categories> <Category id="96926908">Internet Access Providers</Category> <Category id="96932773">Computer Business Solutions</Category> </Categories> </Result> − <Result id="21574436"> <Title>Blinky's Can't Say Lounge</Title> <Address>1031 Monroe St</Address> <City>Santa Clara</City> <State>CA</State> <Phone>(408) 985-7201</Phone> <Latitude>37.348893</Latitude> <Longitude>-121.94816</Longitude> − <Rating> <AverageRating>5</AverageRating> <TotalRatings>3</TotalRatings> <TotalReviews>3</TotalReviews> <LastReviewDate>1228667811</LastReviewDate> − <LastReviewIntro> Good drinks good prices good people. Who could ask for more..... </LastReviewIntro> </Rating> <Distance>6.39</Distance> − <Url> http://local.yahoo.com/info-21574436-blinky-s-can-t-say-lounge-santa-clara </Url> − <ClickUrl> http://local.yahoo.com/info-21574436-blinky-s-can-t-say-lounge-santa-clara </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1031+Monroe+St+Santa+Clara+CA&gid1=21574436 </MapUrl> − <Categories> <Category id="96926057">All Bars, Pubs, & Clubs</Category> <Category id="96926063">Bars & Pubs</Category> </Categories> </Result> − <Result id="21619987"> <Title>Barbara of Pauline's Cake Decorating Supplies</Title> <Address>1093 Malone Rd</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 978-9740</Phone> <Latitude>37.293702</Latitude> <Longitude>-121.889876</Longitude> − <Rating> <AverageRating>4.5</AverageRating> <TotalRatings>8</TotalRatings> <TotalReviews>8</TotalReviews> <LastReviewDate>1268173462</LastReviewDate> − <LastReviewIntro> I love this store. No matter what it is i am looking for weather it is some thing i remember from my child hood or some thing i saw in a magazine and i need it i know i can find it there. Yes they are a little rough around the edges but that is only because they are trying to get it across to you what will work and what will not. This is an old school store with people who know their stuff and are only trying to help you get the best end result possible. I am 46 years old and i took my class from Barbara when i first came out of high school and believe me she will not try to up sale you or tell you some thing is going to work if it will not. Go in expecting to be overwhelmed by stock and know you are going to get the best prices in town. Take the time to get to know the employees and the store and you will always go back to Paulines. I travel all the way from Livermore to get stuff i know i can only find there. Thanks for all your many years of being in business </LastReviewIntro> </Rating> <Distance>9.52</Distance> − <Url> http://local.yahoo.com/info-21619987-barbara-of-pauline-s-cake-decorating-supplies-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-21619987-barbara-of-pauline-s-cake-decorating-supplies-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1093+Malone+Rd+San+Jose+CA&gid1=21619987 </MapUrl> − <Categories> <Category id="96928859">Wedding Supplies & Services</Category> </Categories> </Result> − <Result id="21602089"> <Title>Carey David Incorporated</Title> <Address>1624 Remuda Ln</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 453-7843</Phone> <Latitude>37.372385</Latitude> <Longitude>-121.908305</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>4.13</Distance> − <Url> http://local.yahoo.com/info-21602089-carey-david-incorporated-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-21602089-carey-david-incorporated-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1624+Remuda+Ln+San+Jose+CA&gid1=21602089 </MapUrl> <BusinessUrl>http://dc-enterprises.com/</BusinessUrl> <BusinessClickUrl>http://dc-enterprises.com/</BusinessClickUrl> − <Categories> <Category id="96928508">Clothing Wholesalers</Category> <Category id="96928509">Clothing Manufacturers</Category> <Category id="96931030">Apparel Manufacturing</Category> </Categories> </Result> − <Result id="30246475"> <Title>Royal Casino Parties</Title> <Address>943 Berryessa Rd, #6</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 213-0904</Phone> <Latitude>37.363563</Latitude> <Longitude>-121.886341</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>4.71</Distance> − <Url> http://local.yahoo.com/info-30246475-royal-casino-parties-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-30246475-royal-casino-parties-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=943+Berryessa+Rd%2C+%236+San+Jose+CA&gid1=30246475 </MapUrl> <BusinessUrl>http://www.royalcasinoparties.com/</BusinessUrl> <BusinessClickUrl>http://www.royalcasinoparties.com/</BusinessClickUrl> − <Categories> <Category id="96925812">Entertainment Production</Category> <Category id="96930362">Gambling</Category> </Categories> </Result> − <Result id="25247620"> <Title>Bay Casino Gaming, Casino Party Rentals</Title> <Address/> <City>San Jose</City> <State>CA</State> <Phone>(408) 747-1977</Phone> <Latitude>37.338475</Latitude> <Longitude>-121.885794</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>6.44</Distance> − <Url> http://local.yahoo.com/info-25247620-bay-casino-gaming-casino-party-rentals-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-25247620-bay-casino-gaming-casino-party-rentals-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=+San+Jose+CA&gid1=25247620 </MapUrl> <BusinessUrl>http://www.baycasinogaming.com/</BusinessUrl> <BusinessClickUrl>http://www.baycasinogaming.com/</BusinessClickUrl> − <Categories> <Category id="96925812">Entertainment Production</Category> <Category id="96925814">Party Rentals</Category> </Categories> </Result> </ResultSet> Hello all, I'm looking for some assistance with some code. I'm trying to put this to bed as it's driving me nuts. The Psuedo code for this would be to 1) Download the rates from the Yahoo API and declare my base rate to my foreign exchange. 2) Store an array of currencies to choose from to compare against the base currency. 3) I then GET the chosen currency and register it in a SESSION to be used on other pages. (I'm unsure if this is correct?) 4) I then calculate the Price of my product which is in GBP to the selected foreign currency. 5) Output the converted price anywhere on the page. My script takes GET values from the URL like so.. .com?c=EUR My code is like so.. 1) First I get the rates from the Yahoo API Code: [Select] session_start(); $from = 'GBP'; $to = '$c'; $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X'; $handle = @fopen($url, 'r'); if ($handle) { $result = fgets($handle, 4096); fclose($handle); } $allData = explode(',',$result); /* Get all the contents to an array */ $PoundValue = $allData[1]; 2) Then I store an array of the currencies. Code: [Select] $currency_array = array ('USD','EUR','RMB','JPY','AUD','CHF') 3) Then I get the chosen currency. Code: [Select] if(isset($_GET['c'])) { $c = $_GET['c']; if(array($currency_array)) { $_SESSION['currency_array'] = $c; } } 4) I then calculate the product price. Code: [Select] $Total = $Price * $currency_array; $outprice = number_format($Total, 2, '.', ','); 5) Then I output on the page Code: [Select] <?php echo .$outprice; ?> So is all my coding logically in the right order? Any help would be greatly appreciated. Thank you. I'm using a simple form to grab an email address and send the person who signs up and automatic response. It was working for a while and now it's not. Not sure what happened. My hosting company told me to look into my headers. Can anyone help? Here is my code. Thanks, Code: [Select] <?php /* Set e-mail recipient */ $subject = "Sign Up"; $headers = "From: admin@xxx.com" . "\r\n" . "CC: admin@xxx.com"; /* Check all form inputs using check_input function */ $sign_up_email_address = check_input($_POST['sign_up_email_address'], "Please enter your email address."); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $sign_up_email_address)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $response_message = "Sample Message"; /* Send the message using mail() function */ mail($sign_up_email_address, $subject, $response_message, $headers); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <?php echo $myError; ?> Thank you, Hello, PHP Freaks, So I have my website built with RapidWeaver, and built a PHP form page, and it works fine with a test host. However, I uploaded to Yahoo Small Business and the submissions aren't getting through. I heard that Yahoo is quite problematic when it comes to PHP...I called their help line and they told me that I needed to include the following in my form: <form name="Form0" method="POST" action="http://us.xx.px.webhosting.yahoo.com/forms?login=YahooID&to=mail@domianname.com&confirm=index.html&error=" onSubmit="return checkForm0()"> However, I have 2 php files, application.php and mailer.php. application.php: Quote <?php // Start session. session_start(); // Set a key, checked in mailer, prevents against spammers trying to hijack the mailer. $security_token = $_SESSION['security_token'] = uniqid(rand()); if ( ! isset($_SESSION['formMessage'])) { $_SESSION['formMessage'] = 'Fill in the form below to submit an application.'; } if ( ! isset($_SESSION['formFooter'])) { $_SESSION['formFooter'] = 'A scholarship is also available, please contact us for more details.'; } if ( ! isset($_SESSION['form'])) { $_SESSION['form'] = array(); } function check($field, $type = '', $value = '') { $string = ""; if (isset($_SESSION['form'][$field])) { switch($type) { case 'checkbox': $string = 'checked="checked"'; break; case 'radio': if($_SESSION['form'][$field] === $value) { $string = 'checked="checked"'; } break; case 'select': if($_SESSION['form'][$field] === $value) { $string = 'selected="selected"'; } break; default: $string = $_SESSION['form'][$field]; } } return $string; } ?><!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> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="robots" content="all" /> <meta name="generator" content="RapidWeaver" /> <title>North Shore Culinary School | Application</title> <link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/styles.css" /> <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/ie6.css" /><![endif]--> <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/ie7.css" /><![endif]--> <link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/colourtag-page4.css" /> <link rel="stylesheet" type="text/css" media="print" href="../rw_common/themes/culinaryschool/print.css" /> <link rel="stylesheet" type="text/css" media="handheld" href="../rw_common/themes/culinaryschool/handheld.css" /> <link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/css/width/900.css" /> <link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/css/header/sunflower.css" /> <link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/css/icons/blue.css" /> <link rel="stylesheet" type="text/css" media="screen" href="../rw_common/themes/culinaryschool/css/sidebar/sidebar_right.css" /> <script type="text/javascript" src="../rw_common/themes/culinaryschool/javascript.js"></script> <!--[if IE 6]><script type="text/javascript" charset="utf-8"> var blankSrc = "../rw_common/themes/culinaryschool/png/blank.gif"; </script> <style type="text/css"> img { behavior: url("../rw_common/themes/culinaryschool/png/pngbehavior.htc"); } </style><![endif]--> </head> <body> <div id="top_bar"> <img src="../rw_common/themes/culinaryschool/images/body_top_bar.png" alt="" width="3000" height="8" /> </div> <div id="container"><!-- Start container --> <div id="top_swirl"> <img src="../rw_common/themes/culinaryschool/images/top_swirl.png" alt="" width="222" height="140" /> </div> <div id="pageHeader"><!-- Start page header --> <div id="logo_overlay"><img src="../rw_common/themes/culinaryschool/images/logo_grad_overlay.png" alt="" width="3000" height="175" /></div> <div id="logo"></div> <h1>North Shore Culinary School</h1> <h2>This is a complete program designed to train today's food service professionals for entry level jobs which may ladder to further opportunities.</h2> </div><!-- End page header --> <div id="contentContainer"><!-- Start main content wrapper --> <div id="navcontainer"><!-- Start Navigation --> <ul><li><a href="../index.html" rel="self">Home</a></li><li><a href="../about.html" rel="self">About</a></li><li><a href="../requirements.html" rel="self" class="currentAncestor">Curriculum</a><ul><li><a href="../curriculum/details.html" rel="self">Details</a></li><li><a href="../curriculum/calendar.html" rel="self">Calendar</a></li><li><a href="application.php" rel="self" id="current">Application</a></li></ul></li><li><a href="../contact.html" rel="self">Contact</a></li></ul> </div><!-- End navigation --> <div id="sidebarContainer"><!-- Start Sidebar wrapper --> <div id="sidebar"><!-- Start sidebar content --> <h1 class="sideHeader"></h1><!-- Sidebar header --> <!-- sidebar content you enter in the page inspector --> <!-- sidebar content such as the blog archive links --> </div><!-- End sidebar content --> </div><!-- End sidebar wrapper --> <div id="content"><!-- Start content --> <div class="message-text"><?php echo $_SESSION['formMessage']; unset($_SESSION['formMessage']); ?></div><br /> <form action="./application_files/mailer.php" method="post" enctype="multipart/form-data"> <div> <label>First Name:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element0'); ?>" name="form[element0]" size="40"/><br /><br /> <label>Last Name:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element1'); ?>" name="form[element1]" size="40"/><br /><br /> <label>Sex:</label> *<br /> <select name="form[element2]"> <option <?php echo check('element2', 'select','Male'); ?> value="Male">Male</option> <option <?php echo check('element2', 'select','Female'); ?> value="Female">Female</option> </select><br /><br /> <label>Birthdate (DD/MM/YYYY):</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element3'); ?>" name="form[element3]" size="40"/><br /><br /> <label>Date of Application (DD/MM/YYYY):</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element4'); ?>" name="form[element4]" size="40"/><br /><br /> <label>Address:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element5'); ?>" name="form[element5]" size="40"/><br /><br /> <label>Apartment Number:</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element6'); ?>" name="form[element6]" size="40"/><br /><br /> <label>Postal Code:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element7'); ?>" name="form[element7]" size="40"/><br /><br /> <label>Home Phone Number:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element8'); ?>" name="form[element8]" size="40"/><br /><br /> <label>Cell Phone Number:</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element9'); ?>" name="form[element9]" size="40"/><br /><br /> <label>Fax:</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element10'); ?>" name="form[element10]" size="40"/><br /><br /> <label>E-mail:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element11'); ?>" name="form[element11]" size="40"/><br /><br /> <label>Alternate e-mail:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element12'); ?>" name="form[element12]" size="40"/><br /><br /> <label>BCID #:</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element13'); ?>" name="form[element13]" size="40"/><br /><br /> <label>BC Driver's License #:</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element14'); ?>" name="form[element14]" size="40"/><br /><br /> <label>Are you of First Nation or Inuit descent?</label> *<br /> <select name="form[element15]"> <option <?php echo check('element15', 'select','Yes'); ?> value="Yes">Yes</option> <option <?php echo check('element15', 'select','No'); ?> value="No">No</option> </select><br /><br /> <label>Were you born in Canada?</label> *<br /> <select name="form[element16]"> <option <?php echo check('element16', 'select','Yes'); ?> value="Yes">Yes</option> <option <?php echo check('element16', 'select','No'); ?> value="No">No</option> </select><br /><br /> <label>If not, what is your country of birth?</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element17'); ?>" name="form[element17]" size="40"/><br /><br /> <label>When did you arrive in Canada? (DD/MM/YYYY)</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element18'); ?>" name="form[element18]" size="40"/><br /><br /> <label>Elementary School Attended:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element19'); ?>" name="form[element19]" size="40"/><br /><br /> <label>High School Attended:</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element20'); ?>" name="form[element20]" size="40"/><br /><br /> <label>DId you receive any extra learning support in school? (e.g. ESL)</label> *<br /> <select name="form[element21]"> <option <?php echo check('element21', 'select','Yes'); ?> value="Yes">Yes</option> <option <?php echo check('element21', 'select','No'); ?> value="No">No</option> </select><br /><br /> <label>If yes, please specify...</label> <br /> <input class="form-input-field" type="text" value="<?php echo check('element22'); ?>" name="form[element22]" size="40"/><br /><br /> <label>Do you have a computer workstation at home?</label> *<br /> <select name="form[element23]"> <option <?php echo check('element23', 'select','Yes'); ?> value="Yes">Yes</option> <option <?php echo check('element23', 'select','No'); ?> value="No">No</option> </select><br /><br /> <label>How will you be travelling to and from school?</label> *<br /> <select name="form[element24]"> <option <?php echo check('element24', 'select','Car'); ?> value="Car">Car</option> <option <?php echo check('element24', 'select','Bus'); ?> value="Bus">Bus</option> <option <?php echo check('element24', 'select','Bike'); ?> value="Bike">Bike</option> <option <?php echo check('element24', 'select','Walking'); ?> value="Walking">Walking</option> <option <?php echo check('element24', 'select','Other'); ?> value="Other">Other</option> </select><br /><br /> <label>Are you receiving any financial assistance? Please specify...</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element25'); ?>" name="form[element25]" size="40"/><br /><br /> <label>Have you received a blood test?</label> *<br /> <select name="form[element26]"> <option <?php echo check('element26', 'select','Yes'); ?> value="Yes">Yes</option> <option <?php echo check('element26', 'select','No'); ?> value="No">No</option> </select><br /><br /> <label>Have you received a TB test?</label> *<br /> <select name="form[element27]"> <option <?php echo check('element27', 'select','Yes'); ?> value="Yes">Yes</option> <option <?php echo check('element27', 'select','No'); ?> value="No">No</option> </select><br /><br /> <label>Do you have any disabilities? Please specify...</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element28'); ?>" name="form[element28]" size="40"/><br /><br /> <label>What is your cultural background?</label> *<br /> <input class="form-input-field" type="text" value="<?php echo check('element29'); ?>" name="form[element29]" size="40"/><br /><br /> <div style="display: none;"> <label>Spam Protection: Please don't fill this in:</label> <textarea name="comment" rows="1" cols="1"></textarea> </div> <input type="hidden" name="form_token" value="<?php echo $security_token; ?>" /> <input class="form-input-button" type="reset" name="resetButton" value="Reset" /> <input class="form-input-button" type="submit" name="submitButton" value="Submit" /> </div> </form> <br /> <div class="form-footer"><?php echo $_SESSION['formFooter']; unset($_SESSION['formFooter']); ?></div><br /> <?php unset($_SESSION['form']); ?> <div class="clearer"></div> </div><!-- End content --> </div><!-- End main content wrapper --> </div><!-- End container --> <div id="footer"><!-- Start Footer --> <div id="footer_swirl"> <img src="../rw_common/themes/culinaryschool/images/footer_swirl.png" alt="" width="502" height="69" /> </div> <p>© 2010 Don Guthro</p> <div id="breadcrumbcontainer"><!-- Start the breadcrumb wrapper --> </div><!-- End breadcrumb --> </div><!-- End Footer --> </body> </html> mailer.php: Quote <?php //start the session session_start(); ////////////////////////////////////////////////////// // Begin variables to be written out by RapidWeaver // ////////////////////////////////////////////////////// //set the return URL $return_url = "../application.php"; //set the users email address $email = "nachapol.d@gmail.com"; //array of fields in form. (In the format "field_name" => "field_label") $form_fields = array( "element0" => 'First Name:', "element1" => 'Last Name:', "element2" => 'Sex:', "element3" => 'Birthdate (DD/MM/YYYY):', "element4" => 'Date of Application (DD/MM/YYYY):', "element5" => 'Address:', "element6" => 'Apartment Number:', "element7" => 'Postal Code:', "element8" => 'Home Phone Number:', "element9" => 'Cell Phone Number:', "element10" => 'Fax:', "element11" => 'E-mail:', "element12" => 'Alternate e-mail:', "element13" => 'BCID #:', "element14" => 'BC Driver\'s License #:', "element15" => 'Are you of First Nation or Inuit descent?', "element16" => 'Were you born in Canada?', "element17" => 'If not, what is your country of birth?', "element18" => 'When did you arrive in Canada? (DD/MM/YYYY)', "element19" => 'Elementary School Attended:', "element20" => 'High School Attended:', "element21" => 'DId you receive any extra learning support in school? (e.g. ESL)', "element22" => 'If yes, please specify...', "element23" => 'Do you have a computer workstation at home?', "element24" => 'How will you be travelling to and from school?', "element25" => 'Are you receiving any financial assistance? Please specify...', "element26" => 'Have you received a blood test?', "element27" => 'Have you received a TB test?', "element28" => 'Do you have any disabilities? Please specify...', "element29" => 'What is your cultural background?' ); $required_fields = array("element0", "element1", "element2", "element3", "element4", "element5", "element7", "element8", "element11", "element12", "element15", "element16", "element19", "element20", "element21", "element23", "element24", "element25", "element26", "element27", "element28", "element29"); $mail_from_name = "element0"; $mail_from_email = "element11"; $mail_subject = "element4"; //uses the email address defined above as the from email. $send_from_users_email = false; //sets the PHP setting 'sendmail_from' for use on a windows server. $windows_server = true; // Set up the error and success messages. $message_success = 'Thank you, your application has been sent.'; $message_unset_fields = "Fields marked with * are required."; //////////////////////////////////////////////////// // End variables to be written out by RapidWeaver // //////////////////////////////////////////////////// // Check key variable from form against session key. if ( ! isset($_POST['form_token']) || $_POST['form_token'] !== $_SESSION['security_token']) { // Set a fixed error message if the keys don't match. redirect($return_url, 'We cannot verify that you are trying to send an email from this form. Please try again.'); } // SPAM checking. If the "comment" form field has been filled out, // send back to form asking to remove content and exit the script. if ($_POST['comment']) { redirect($return_url, 'Please remove content from the last textarea before submitting the form again. This is to protect against SPAM abuse.'); } ///////////////////////// // PROCESS FORM FIELDS // ///////////////////////// $magic_quotes = (bool) get_magic_quotes_gpc(); foreach ($_POST['form'] as $key => $value) { if ($magic_quotes) { $value = stripslashes($value); } $_SESSION['form'][$key] = $value; } /////////////////////////// // CHECK REQUIRED FIELDS // /////////////////////////// //if any of the required fields are empty if (check_required_fields($required_fields) === false) { //return to form with error message. redirect($return_url, $message_unset_fields); } else { /////////////////////////////////// // ALL IS OK, SETUP GLOBAL VAR'S // /////////////////////////////////// //check email address if ( ! check_email($email)) unset($email); //set mime boundry. Needed to send the email. Mixed seperates text from attachments. $mixed_mime_boundary = 'rms-mix-x'.md5(mt_rand()).'x'; //alt seperates html from plain text. $alt_mime_boundary = 'rms-alt-x'.md5(mt_rand()).'x'; //set the from address if user supplied email is invalid use form owners. $submitted_email = ''; if (isset($_SESSION['form'][$mail_from_email])) { $submitted_email = $_SESSION['form'][$mail_from_email]; } if (check_email($submitted_email) && $send_from_users_email === false) { $from = $reply_to = $_SESSION['form'][$mail_from_name].'<'.$submitted_email.'>'; } else { $from = '<'.$email.'>'; $reply_to = check_email($submitted_email) ? '<'.$submitted_email.'>' : $from; } //set the email subject $subject = ''; if (isset($_SESSION['form'][$mail_subject])) { $subject = $_SESSION['form'][$mail_subject]; } //email headers $headers = "From: $from\r\n" . "Reply-to: $reply_to\r\n" . "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; " . "boundary=$mixed_mime_boundary"; //////////////////////////// // CONSTRUCT HTML CONTENT // //////////////////////////// //Construct HTML email content, looping through each form element //Note: When you get to a file attachment you need to use $_FILES['form_element']['name'] //This will just output the name of the file. The files will actually be attached at the end of the message. //Set a variable for the message content $html_content = "<html>\r\n<head>\r\n<title>" . safe_escape_string($subject) . "</title>\r\n</head>\r\n<body>\r\n<p>\r\n"; //////////////////////////// // CONSTRUCT TEXT CONTENT // //////////////////////////// //construct a plain text version of the email. $text_content = ''; //build a message from the reply for both HTML and text in one loop. foreach ($form_fields as $field => $label) { $html_content .= '<b>' . safe_escape_string($label) . '</b> '; $text_content .= "$label "; if (isset($_FILES[$field])) { $string = (isset($_FILES[$field]['name'])) ? $_FILES[$field]['name'] : ''; } else { $string = (isset($_SESSION['form'][$field])) ? $_SESSION['form'][$field] : ''; } $html_content .= nl2br(safe_escape_string($string)) . "<br /><br />\r\n"; $text_content .= "$string\r\n\r\n"; } //close the HTML content. $html_content .= "</p>\r\n</body>\r\n</html>"; ///////////////////////////// // CONSTRUCT EMAIL MESSAGE // ///////////////////////////// //Now we combine both HTML and plain text version of the email into one. //Creating the message body which contains a Plain text version and an HTML version, //users email client will decide which version to display $message = "\r\n--$mixed_mime_boundary\r\n" . "Content-Type: multipart/alternative; boundary=$alt_mime_boundary\r\n\r\n" . "--$alt_mime_boundary\r\n" . "Content-Type: text/plain; charset=UTF-8; format=flowed\r\n" . "Content-Transfer-Encoding: Quoted-printable\r\n\r\n" . "$text_content\r\n\r\n" . "--$alt_mime_boundary\r\n" . "Content-Type: text/html; charset=UTF-8\r\n" . "Content-Transfer-Encoding: Quoted-printable\r\n\r\n" . "$html_content\r\n\r\n" . "--$alt_mime_boundary--\r\n\r\n" . "\r\n\r\n--$mixed_mime_boundary"; ////////////////////// // FILE ATTACHMENTS // ////////////////////// //loop through the $_FILES global array and add each attachment to the form. if (isset($_FILES)) { foreach ($_FILES as $attachment) { $filename = $attachment['name']; //if the file has been uploaded if ($attachment['error'] === UPLOAD_ERR_OK && is_uploaded_file($attachment['tmp_name'])) { $file = fopen($attachment['tmp_name'],'rb'); $data = fread($file,filesize($attachment['tmp_name'])); fclose($file); $data = chunk_split(base64_encode($data)); $message .= "\r\nContent-Type: application/octet-stream; name=\"$filename\"" . "\r\nContent-Disposition: attachment; filename=\"$filename\"" . "\r\nContent-Transfer-Encoding: base64\r\n\r\n$data\r\n\r\n--$mixed_mime_boundary"; } else if ($attachment['error'] !== UPLOAD_ERR_NO_FILE) { //try to provide a useful error message determined from the error code. switch ($attachment['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $error = "File $filename exceeds the " . ini_get('upload_max_filesize') . 'B limit for the server.'; break; case UPLOAD_ERR_PARTIAL: $error = "Only part of the file $filename could be uploaded, please try again."; break; default: $error = "There has been an error attaching the file $filename, please try again."; } redirect($return_url, $error); } } } //finish off message $message .= '--'; //for windows users. if ($windows_server === true) { ini_set('sendmail_from', $email); } //if the mail sending works if (@mail($email, $subject, $message, $headers)) { //set the success message $notice = $message_success; unset($_SESSION['form']); } else { $notice = "I'm sorry, there seems to have been an error trying to send your email. Please try again."; } //redirect to the form redirect($return_url, $notice); } ////////////////////// // GLOBAL FUNCTIONS // ////////////////////// // Redirects back to the form, an optional session message can be defined. function redirect($url, $message = NULL) { if ($message) { $_SESSION['formMessage'] = $message; } header('Location: ' . $url); exit; } // Function to escape data inputted from users. This is to protect against embedding // of malicious code being inserted into the HTML email. // Sample code: safe_escape_string($_POST['form_field']) function safe_escape_string($string) { return htmlspecialchars($string, ENT_QUOTES); } // Function to check the validity of email address. function check_email($email) { return (bool) preg_match('/^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}$/i', $email); } // Function to check the required fields are filled in. function check_required_fields($required_fields) { foreach ($required_fields as $field) { if (( ! isset($_SESSION['form'][$field]) || empty($_SESSION['form'][$field])) && ( ! isset($_FILES[$field]) || empty($_FILES[$field]['name']))) { return false; } } return true; } Now I'm a little bombarded with this code, since I am an amateur web-builder and I don't have much experience modifying PHP. I was just wondering how I can integrate the code given to me into my existing PHP files. The website is www.northshoreculinaryschool.com and my form is under Curriculum > Application. I can provide the files if anyone wishes. Any help is greatly appreciated! If you can help me through this, you're a lifesaver! i am new to curl .and i m trying to create create a script to log into yahoo and click the confermation link in emails. but i am stuck witht he login process only i made the code below . but still i cant make it work. the problem is yahoo is implementing a captcha challange for this kind of automated headers. do you have any idea ho to make it work again without alerting the captcha challange ? the header i caught through the livehttp header is as follows: Content-Length: 347 .tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=in&.bypass=&.partner=&.u=4ls6cr96lbs8e&.v=0&.challenge=W9w31pCrbdazCcY4mH41fVsyxwd8&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fmail.yahoo.com&.pd=ym_ver%3D0%26c%3D%26ivt%3D%26sg%3D&pad=1&aad=1&login=myyahooid&passwd=mypassword&.persistent=y&.save=&passwd_raw= <?php $authUrl = "https: //login. yahoo . com/config/login?"; $userAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0b11) Gecko/20100101 Firefox/4.0b11"; $referer = "http : // my . yahoo . com"; $login = "userid"; $password = "password"; $numPostData = 22; $cookieFileJar = "ycookie.txt"; $cookie = 0; $postData = ".tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=in&.bypass=&.partner=&.u=4ls6cr96lbs8e&.v=0&.challenge=W9w31pCrbdazCcY4mH41fVsyxwd8&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fmail.yahoo.com&.pd=ym_ver%3D0%26c%3D%26ivt%3D%26sg%3D&pad=1&aad=1&login=$login&passwd=$password&.persistent=y&.save=&passwd_raw=" ; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); // Set the referrer curl_setopt($ch, CURLOPT_REFERER, $referer); // Set the authentication url curl_setopt($ch, CURLOPT_URL, $authUrl); // Set number of post fields curl_setopt($ch, CURLOPT_POST, $numPostData); //Set post data in key=value pair such as login=yourusername curl_setopt($ch, CURLOPT_POSTFIELDS, $numPostData); //Set filename for storing cookie information curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFileJar); //Set ffilename for checking the stored cookie information curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFileJar); //Set option for cookie curl_setopt($ch, CURLOPT_COOKIE, $cookie); //set this to output the result as string and not output directly ot browser curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //set this value to 1 if you want to redirect to the url you provided as service url curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); //Set this option if you do not want to verify ssl curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //set this option if you do not want to verify peer's certificate curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //now execute the curl $res = curl_exec($ch); echo $res; //check if the username and password is valid if ((preg_match("/invalid/i", $res)) || (preg_match("/not yet taken/i", $res))) { echo "Invalid Login"; } else { //if CURLOPT_FOLLOWLOCATION is set to 1 then after logging in successfully user is directed to url that is specified as service url echo "Logged In"; } ?> then i have to work for clicking confermation links in mails. please suggest me some ways.i would be very grateful to you With this link http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2 , one can see suggested keywords for a query. The result is like "madonna 4 minutes madonna 4 minutes lyrics". How to put the resulting keywords in a $array, as can be used for further php coding. |