PHP - Grabbing An Array From A Function
Hello Guys,
I have a question I have the following function that is located in a different file. I want to be able to use the $lat and $long in my main page how would I code it? Code: [Select] function toCoordinates($all_address) { $bad = array( " " => "+", "," => "", "?" => "", "&" => "", "=" => "" ); $all_address = str_replace(array_keys($bad), array_values($bad), $all_address); $data = new SimpleXMLElement(file_get_contents("http://maps.google.com/maps/geo?output=xml&q={$all_address}")); $coordinates = explode(",", $data->Response->Placemark->Point->coordinates); return array( "latitude" => $coordinates[0], "longitude" => $coordinates[1] ); } Tried this but it didn't work $all_address2 = toCoordinates($all_address); echo "$all_address2; Please advise... Thanks, Dan Similar TutorialsHi guys really need some help. i have got this function. I am learning codeignitor. function uploadify() { $file = $this->input->post('filearray'); $data['json'] = json_decode($file); print_r($data); $name = $json->{'file_name'}; $this->files->add($name); $this->load->view('uploadify',$data); } this is the result i get from the print_r(). Array ( [json] => stdClass Object ( [file_name] => footer-icpn229.jpg [real_name] => footer-icpn2.jpg [file_ext] => .jpg [file_size] => 1.75 [file_path] => /home/codeig/public_html/files/footer-icpn229.jpg [file_temp] => /home/codeig/tmp/phpSupCpi ) ) What i am trying to do is pull the value filename out off the array and pass it into another vairable in the fucntion which is what i am trying to do with these two lines of code. $name = $json->{'file_name'}; $this->files->add($name); I keep getting this error what am i doing wrong? Undefined variable: json Hey guys, I am having issue with understanding/implementing an array. Currently my code does the following it displays an array of values to the user as a note and allows the user to enter in values if they wish. This is done through using a select a statement which displays those values through a while loop.I then use a line like so:-<textarea name=Details[detailsno] value="'.$Text.'">"'.$Text.'"... which passes the input from the user into an array. Underneath this I have a checkbox that allows the user to select particular notes to update.<input type=checkbox name=update[] value=Update>. This passes over the values correctly. The problem im currently having is grabbing the values that the user has entered for those particular detailsno so that I can implement an insert statement. i was wondering if you knew how to do this? Thank you for taking your time to even read this or even help its much appreciated. Hello. Basically the issue I am having is my feedback form is not grabbing the Company Name and ID from the URL. I have the php code set in place where it's supposed to post, but it's not getting it. Can someone please help me out? I'm pretty new with php, so I'm kind of at the brink of my knowledge. Thanks, Jess. Code: [Select] <?php //Modified because only email is required //if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) { if (empty($_POST['email'])) { $error_msg .= "E-mail is a required field. \n"; } elseif (strlen($_POST['name']) > 15) { $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; } elseif (!ereg("^[A-Za-z' -]*$", $_POST['name'])) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($_POST['email']))) { $error_msg .= "That is not a valid e-mail address. \n"; } elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url'])) $error_msg .= "Invalid website url."; if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Feedback for " . $_POST['Company']; $message = "You received this e-mail message through your website: \n\n"; foreach ($_POST as $key => $val) { $message .= ucwords($key) . ": $val \r\n"; } $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n"; $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n"; $message .= 'Spam points: '.$points; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: $yourEmail \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } else { $headers = "From: $yourWebsite <$yourEmail> \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } if (mail($yourEmail,$subject,$message,$headers)) { echo '<p>Thank you for taking the time to send us your feedback. Your comments are appreciated and help us provide the most current and accurate information possible.</p> <p>If you require further assistance, please visit our <a href="http://www.domain.com/" target="_blank">contact us</a> page.</p>'; $sentmail = 1; echo ' <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("analyticscode"); pageTracker._setDomainName(".domain.com"); pageTracker._trackPageview(); </script> '; } else { echo '<p>Your mail could not be sent this time.</p>'; } } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } ?> <?php foreach( $_POST as $checkbox ){ echo $checkbox .'<br />'; $checkbox = array("WebsiteLinkIsNotAccurate", "TelephoneNumberIsNotAccurate", "FaxNumberIsNotAccurate", "CompanyIsOutOfBusiness", "CompanyIsNoLongerAtThisLocation", "CompanyDoesNotProvideTheProductOrServiceAsFeatured", "Other(PleaseExplainBelow)"); } ?> <?php // DISPLAY ERROR MESSAGE - CHECK TO SEE IF USER HAS SUBMITTED THE FORM SUCCESSFULLY if ($error_msg != NULL) { echo '<p><strong style="color: red;">ERROR:</strong><br />'; echo nl2br($error_msg) . "</p>"; } if($sentmail == 0){ ?> <form id="feedback" name="feedback" method="post" action="feedback.php" onSubmit="return CheckForm()"> <noscript> <p><input type="hidden" name="nojs" id="nojs" /></p> </noscript> <input type="hidden" name="CompanyID" id="CompanyID" value="<?php echo $_POST['companyid']; ?>"> <input type="hidden" name="Company" id="Company" value="<?php echo $_POST['companyname']; ?>"> <p><strong>If you have different information about <u><?php echo $_POST['companyname']; ?></u>, or were unable to contact them, please let us know by completing the form below.</strong></p> ... I am having some problems getting a query correct. Basically I have two tables, one with listings and another with categories. In the listings table I have a column called shortdescription. I am trying to pull the shortdescription from the listings table with the query $shortdesc = array_shift(mysql_fetch_row(mysql_query("select shortdescription from links where category = '".$scat->id."' "))); The shortdecription display properly on the pages display the listings, however I am getting the following error on any pages that only display the parent categories Warning: array_shift() [function.array-shift]: The argument should be an array in /home/...path/file.php on line 1462 The listings id numbers begin at 75+ because the initial parent category id ends at 74. The query seems to be searching for listing ids below 75 and spitting out an error because it is not finding them. Any ideas on how to eliminate this error and/or stop the query from looking for non-existant data? I want to define a function instead of repeating query in all my php pages. I call a function by passing an $id value and from that function i have to get all the info related to that id, like name, description and uom.
I am trying to do this, but i dont know how to get these values seperately.
here is my function
function items($item_id) { $details = array(); $result = mysql_query("select item_id, name, uom, description from items where item_id=".$item_id."") or die (mysql_error()); while($row = mysql_fetch_array($result)) { $details[] = array((stripslashes($row['name'])), (stripslashes($row['uom'])), (stripslashes($row['description']))); } return $details; }and i call my function like this $info = items($id);Can somebody guide me in this I think this belongs here, but my $_POST['gender'] won't grab the gender that was submitted through a form. I am using AJAX so the page doesn't have to reload so it can go in a smooth transition, but the AJAX is grabbing the value perfectly fine. I have a feeling the $_POST isn't grabbing the value because the page isn't reloading.. but I don't want to reload it. These codes are all on the same page. Here is my Javascript: Code: [Select] <script> function chooseGender() { var gender = $('input[name=gender]:checked', '#submitgender').val(); if(gender) { $.ajax( { type: "POST", url: window.location.pathname, data: gender, success: function() { alert("You have chosen to be a " + gender); //It's grabbing it perfectly fine! $("#submitgender").hide(); //It hides the gender table so they can't choose a gender since they already have chosen one. $("#rest").fadeIn(); //Shows the other table that's labeled "rest" as it's ID so they can choose what base, eyes, etc for that specific gender they've chosen. } }); } else { alert('Select a gender.'); } } $(function tabs() { $( "#tabs" ).tabs(); }); </script> But here is the PHP inside the #rest table: Code: [Select] <?php $gender = $_POST['gender']; $sql = "SELECT * FROM habases WHERE gender='".$gender."'"; $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); print_r($sql); while ($row = mysqli_fetch_assoc($result)) { $baseimage = $row['image']; $baseskin = $row['skin']; echo "<img src=\"http://www.elvonica.com/".$baseimage."\" value=\"".$baseskin."\">"; } ?> And this is what I'm getting for the print_r: Quote SELECT * FROM habases WHERE gender='' Currently I am using this very popular code to get all the football scores: Code: [Select] $title = $params->get('title'); $fontc = $params->get('fontc'); $fonts = $params->get('fonts'); //this array contains sports and their URLs $sports = array( "NFL" => "http://sports.espn.go.com/nfl/bottomline/scores"); $results = array(); foreach ( $sports as $sport => $url ) { //get the page pointed to by $url $page = file_get_contents($url); //grab all variables out of the page preg_match_all("/&([^=]+)=([^&]+)/", urldecode($page), $foo); //loop through all the variables on the page foreach ( $foo[1] as $key => $value ) { //debug output, you can delete this next line //echo "{$value} = {$foo[2][$key]}\t<br />\n"; //this chain of IF/elseif statements is used to determine which pattern to use //to strip out the correct data, since each sport seems to have its own format //for the variables you'd "want" if ( $sport == "NFL" && preg_match("/s_left\d+/", $value) ) { $results[$sport][] = $foo[2][$key]; } } } //calculate the sport with the most number of rows $limit = 0; foreach ( $results as $countMe ) { $limit = max($limit, count($countMe)); } //spit out the table with the right headers echo "<td><b> $title </b></td><br><BR>"; "<table border=4 cellpadding=10><tr><th>" . implode("</th><th>", array_keys($sports)). "</th></tr>" ; //loop until you reach the max number of rows, printing out all the table rows you want for ( $p = 0; $p < $limit; $p++ ) { foreach ( array_keys($sports) as $sport );{ $change = str_replace('^','<font color=green><b>W</b> </font>' ,$results[$sport][$p]); $final = str_replace('(FINAL)','<font color=red>(FINAL)', $change); echo "<td><font color=$fonts size=$fontc><b>$final</b></font></td><br>"; } echo "</tr>"; } //kill the table echo "</table>"; and it works fantastically well however.... I'd only like to get certain data say like the Cowboys game info and nothing more... NOT too sure how to do this, I'm just not really sure how to read the page, grab only that data. Help would be greatly appreciated! Thank you. I am trying to have a search bar and this is the search results page. However when they search they have the option to type in anything and it will search the entire directory for what ever they type in so if they type in "Dog" I want dog to be searched for in the database under title and author this is the code I have now...can anyone help me?? Code: [Select] // Build SQL Query $query = "select * from videos where title like \"%$trimmed%\" order by id DESC"; // EDIT HERE and specify your table and field names for the SQL query Php Whizzes!
Need to grab geo ip. Why these 2 show data differently ? http://www.geoplugin.net/json.gp?ip=19.117.63.253 http://www.geoplugin.net/php.gp?ip=19.117.63.253 Which one you like ? I like 1st one.
Anyway, is this code any good ? Will it misfire ?
<?php //https://stackoverflow.com/questions/12553160/getting-visitors-country-from-their-ip function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; } echo ip_info("119.30.32.215", "Country"); ?><br><?php echo ip_info("119.30.32.215", "Country Code"); ?><br><?php echo ip_info("119.30.32.215", "State"); ?><br><?php echo ip_info("119.30.32.215", "City"); ?><br><?php echo ip_info("119.30.32.215", "Address"); ?><br><?php print_r(ip_info("119.30.32.215", "Location")); // Array ( [city] => Menlo Park [state] => California [country] => United States [country_code] => US [continent] => North America [continent_code] => NA ) ?>
What you say ? Lemme see your sample code.
Thanks! I have this setup, but for some reason it displays the stats from user where it should display user1. Code: [Select] <?php $user = "S U O M I"; $user1 = "Tezz"; if(isset($_GET['user'])) { if(!empty($_GET['user'])) { $user = $_GET['user']; } } if(isset($_GET['user1'])) { if(!empty($_GET['user1'])) { $user1 = $_GET['user1']; } } //Skill Grabs $order = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "Dungeoneering"); $get = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user"); $get = explode("\n", $get); $i = 0; foreach ($order as $key => $value) { $value = strtolower($value); $temp = explode(",", $get[$i]); $temp = array("rank" => $temp[0], "level" => $temp[1], "exp" => $temp[2]); $stats[$value] = $temp; $eval = "\$$value = array(\$temp[\"rank\"], \$temp[\"level\"], \$temp[\"exp\"]);"; eval($eval); $i++; } //End Skill Grabs $order1 = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "Dungeoneering1"); $get1 = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user1"); $get1 = explode("\n", $get1); $i1 = 0; foreach ($order1 as $key1 => $value1) { $value1 = strtolower($value1); $temp1 = explode(",", $get[$i1]); $temp1 = array("rank1" => $temp1[0], "level1" => $temp1[1], "exp1" => $temp1[2]); $stats1[$value1] = $temp1; $eval1 = "\$$value1 = array(\$temp1[\"rank1\"], \$temp1[\"level1\"], \$temp1[\"exp1\"]);"; eval($eval1); $i1++; } //End Skill Grabs echo "<h2>".$user."</h2>"; echo "<table border='1' cellpadding='5'>"; echo "<tr>"; echo "<td><b>Skills</b></td>"; echo "<td><b>Rank</b></td>"; echo "<td><b>Level</b></td>"; echo "<td><b>XP</b></td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Overall</b></td>"; echo "<td>".$overall[0]."</td>"; echo "<td>".$overall[1]."</td>"; echo "<td>".$overall[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Attack</b></td>"; echo "<td>".$attack[0]."</td>"; echo "<td>".$attack[1]."</td>"; echo "<td>".$attack[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Defence</b></td>"; echo "<td>".$defence[0]."</td>"; echo "<td>".$defence[1]."</td>"; echo "<td>".$defence[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Strength</b></td>"; echo "<td>".$strength[0]."</td>"; echo "<td>".$strength[1]."</td>"; echo "<td>".$strength[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Constitution</b></td>"; echo "<td>".$hitpoints[0]."</td>"; echo "<td>".$hitpoints[1]."</td>"; echo "<td>".$hitpoints[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Ranged</b></td>"; echo "<td>".$ranged[0]."</td>"; echo "<td>".$ranged[1]."</td>"; echo "<td>".$ranged[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Prayer</b></td>"; echo "<td>".$prayer[0]."</td>"; echo "<td>".$prayer[1]."</td>"; echo "<td>".$prayer[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Magic</b></td>"; echo "<td>".$magic[0]."</td>"; echo "<td>".$magic[1]."</td>"; echo "<td>".$magic[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Cooking</b></td>"; echo "<td>".$cooking[0]."</td>"; echo "<td>".$cooking[1]."</td>"; echo "<td>".$cooking[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Woodcutting</b></td>"; echo "<td>".$woodcutting[0]."</td>"; echo "<td>".$woodcutting[1]."</td>"; echo "<td>".$woodcutting[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Fletching</b></td>"; echo "<td>".$fletching[0]."</td>"; echo "<td>".$fletching[1]."</td>"; echo "<td>".$fletching[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Fishing</b></td>"; echo "<td>".$fishing[0]."</td>"; echo "<td>".$fishing[1]."</td>"; echo "<td>".$fishing[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Firemaking</b></td>"; echo "<td>".$firemaking[0]."</td>"; echo "<td>".$firemaking[1]."</td>"; echo "<td>".$firemaking[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Crafting</b></td>"; echo "<td>".$crafting[0]."</td>"; echo "<td>".$crafting[1]."</td>"; echo "<td>".$crafting[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Smithing</b></td>"; echo "<td>".$smithing[0]."</td>"; echo "<td>".$smithing[1]."</td>"; echo "<td>".$smithing[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Mining</b></td>"; echo "<td>".$mining[0]."</td>"; echo "<td>".$mining[1]."</td>"; echo "<td>".$mining[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Herblore</b></td>"; echo "<td>".$herblore[0]."</td>"; echo "<td>".$herblore[1]."</td>"; echo "<td>".$herblore[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Agility</b></td>"; echo "<td>".$agility[0]."</td>"; echo "<td>".$agility[1]."</td>"; echo "<td>".$agility[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Thieving</b></td>"; echo "<td>".$thieving[0]."</td>"; echo "<td>".$thieving[1]."</td>"; echo "<td>".$thieving[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Slayer</b></td>"; echo "<td>".$slayer[0]."</td>"; echo "<td>".$slayer[1]."</td>"; echo "<td>".$slayer[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Farming</b></td>"; echo "<td>".$farming[0]."</td>"; echo "<td>".$farming[1]."</td>"; echo "<td>".$farming[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Runecrafting</b></td>"; echo "<td>".$runecraft[0]."</td>"; echo "<td>".$runecraft[1]."</td>"; echo "<td>".$runecraft[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Hunter</b></td>"; echo "<td>".$hunter[0]."</td>"; echo "<td>".$hunter[1]."</td>"; echo "<td>".$hunter[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Construction</b></td>"; echo "<td>".$construction[0]."</td>"; echo "<td>".$construction[1]."</td>"; echo "<td>".$construction[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Summoning</b></td>"; echo "<td>".$summoning[0]."</td>"; echo "<td>".$summoning[1]."</td>"; echo "<td>".$summoning[2]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Dungeoneering</b></td>"; echo "<td>".$dungeoneering[0]."</td>"; echo "<td>".$dungeoneering[1]."</td>"; echo "<td>".$dungeoneering[2]."</td>"; echo "</tr>"; echo "</table>"; echo "<h2>".$user1."</h2>"; echo "<table border=1 cellpadding=5>"; echo "<tr>"; echo "<td><b>Dungeoneering</b></td>"; echo "<td>".$dungeoneering1[0]."</td>"; echo "<td>".$dungeoneering1[1]."</td>"; echo "<td>".$dungeoneering1[2]."</td>"; echo "</tr>"; echo "</table>"; What is wrong with this code? Hi guys...
I was at home and doing some coding and stumbled across and API for a computer game called Battlefield 4
http://api.bf4stats....ApRiL&output=js;
I was checking it out and it is a LOT of data. I was wondering if its possible to only pull certain data from the API, say for instance you only want to pull your user name, ID, and what game you are playing (those are the top 3 things). How would you pull only those 3 stats and display that information on say a webpage for you?
thanks guys
JL
Hi guys. I'm very new to PHP, and I'm trying to create a simple mail script. Mail a friend A user will click an image on the site which will open a pop up box. They input their name and the email of the friend that they want to send the current URL to. The email will send the current URL via email and display a confirmation message once it has sent successfully. The friend will receive an email with a link to the URL. The problem The email part works fine, it's the URL in the message that is the issue. When the user clicks the 'Email a friend' it opens a popup box - which is where the URL is being grabbed from and emailed. Is there a way to grab the URL from the page before the popup? Here is my (rather amateur) code. Also, feel free to let me know if I can make improvements to it if anything seems a bit strange! The popup link: <a onclick="window.open(this.href,'win2','width=400,height=350,menubar=yes,resizable=yes'); return false;" title="E-mail" href="mailform/form.html">Send to a friend</a> The popup form: <html> <body> <form method="post" action="code.php"> Friends Email: <input name="email" type="text" /><br /> Your Name: <input name="name" type="text" /><br /> <input type="submit" /> </form> </body> </html> The PHP code: <?php // Declaring Variables $email = $_REQUEST['email'] ; $name = $_REQUEST['name']; $geturl = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $message = "Hello. $name has suggested a page for you to view on our website. Please click the following link: $geturl"; // Email Settings mail( $email, "Send page to a friend", $message, "From: Timaru District Council" ); header( "Location: http://www.c4clever.com/sandbox/mailform/sent.html" ); // Confirmation page (Change this to appropriate URL) ?> Feel free to test it out if you want to (http://www.c4clever.com/sandbox) Looking forward to replies, thanks in advance! Hi guys, hopefully someone can help walk me through this.
Basically I want to:
1) Send parameters to remote sites form
2) Receive information/failsafe
3) display data
Sounds easier than it is, can someone explain to a php newb how this can be done?
Site will be given appropriate credit.
Hello, I'm new to this website so forgive me if I'm posting in the wrong section. I just need to know if there is a way that I can retrieve php script that is stored in a database? for example, in my database in table: <? echo"Hello World"; ?> and in my php file, I call that using: <? mysql_connect("asdas","asdas","asd"); mysql_select_db("asdasda"); $result = mysql_query("select * from somedatabse"); while($r=mysql_fetch_array($result)) { $table=$r["table"]; } echo"$table"; ?> i know its confusing, i just hope i made sense and that someone understands what im trying to do. any help will be appreciatedddd thank you : ) I'm new to the PHP world and trying to work my way through a problem. I've gone down many roads, but can't seem to find the answer. I'm not even sure this is so much a PHP question at this point as a host configuration issue. I'm trying to grab an XML file from a remote server. My first try was to try to shell out a wget as follows: exec("wget -q -O status.xml - http://$username:$password@$hostname:$port/cgi-bin/status.xml",$xmlget,$err); This didn't work. Not a surprise since doing it directly from SSH gave: Connecting to mydomain.com|99.99.99.99|:8080... failed: Connection refused. [Note that the port 8080 above is, I think, key] I've since tried method using both file_get_contents and cURL. Similar results for all. I won't clutter this up with the code unless you ask. It's all very straightforward. [file_get_contents complains 'Connection refused' and curl_error says 'couldn't connect to host']. With all of the methods, I'm able to grab, say, google.com AND a page from mydomain.com (default port 80), just not from port 8080. I've set 'allow_url_fopen = on' in php.ini and in my code for good measure. Also, the XML file that lives at 8080 is retrieved fine through a browser. I'm hosted at GoDaddy on their "deluxe shared linux" plan. Is there something obvious I'm missing that would allow all this to work over port 80, but not 8080? Thanks is advance! Greg Hi, Im trying to grab some data from a XML generated by an external server. I know how to grab from XML without attributes, but I cant seem to wrap my head around the structure of this file. What would be easiest way to get the value of the "dbnr" field? Part of the XML file: Code: [Select] <data> <location> <field name="id" format="Long">xxxxxx</field> <field name="dbnr" format="Long">xxxxxx</field> <field name="jobnr" format="Long">xxxxxx</field> <field name="job_type" format="String" maxlen="50">xxxxxx</field> <field name="job_category" format="String" maxlen="50">xxxxxx</field> </location> </data> So I'm trying to grab values from a specific table id in html in PHP possibly using `DOMElement` or something else? I want to add my index.php page to a variable, search for a certain table id ( in this case, "shades" ), then grab JUST the values from inside that table & print it out in an echo. Here's what i have. for some reason I'm getting Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity <?php $HTML = [ ]; $stream = fopen ( "index.php", "r" ); $string = stream_get_contents ( $stream ); HTML [ 0 ] = $string; // Our HTML goes here $innerHTML = implode ( ',', $HTML ); // Create a new DOMDocument based on our HTML $document = new DOMDocument; $document -> loadHTML ( $innerHTML ); // Get a NodeList of any table "id", "shades" $cells = $document -> getElementsByTagName ( "id" ); // Cycle over each <td>, adding its HTML to $innerHTML foreach ( $cells as $cell ) { $innerHTML = $document -> saveHTML ( $cell ); } // Output our glorious HTML echo $innerHTML; fclose ( $stream ); ?>
Hi Everyone, I have seen on the web that you can purchase some server monitoring applications, which mainly run using PHP. Because I don't necesserally need something so powerful, I just want to monitor memory usage and cpu usage. Is there anyway that I can do this using PHP? I have SMNP enabled if that helps? Thanks Matt Let's say I have the string "Bob is my friend. Bob likes to eat apples. Goodbye!". I give a function that string, and the two strings "Bob" and "apples". It returns "Bob likes to eat apples". I seem to have trouble making this function. If I wanted it to return "Bob is my friend. Bob likes to eat apples" that would be much simpler, but I am trying to get the smallest amount of characters between the two strings. I tried doing this, but seem to either get stuck on an infinite loop or return the entire inputted string. Code: [Select] function between($strIn, $str1, $str2){ $pos2 = stripos($strIn, $str2); $pos = 1; $strStore = ""; while($pos>0 && $pos<$pos2){ $pos = stripos($strIn, $str1); $strStore = substr($strin, $pos, $pos2-$pos); $strIn = substr_replace($srtIn, $strtemp, ""); } return $strStore; } What it does it finds the first occurrence of "apples" ($str1) and then keeps finding and deleting every occurrence of "Bob" ($str2) until the position of "Bob" surpasses the position of "apples". As you can tell, it doesn't work. Could anyone help me out, or tell me what I am doing wrong? |