KyokoHunter Posted November 21, 2008 Share Posted November 21, 2008 Evening all (if you're in the UK, at least!). I'm working on a PHP script that reads text from an RSS feed and superimposes text from it onto an image. The script works fine when the URLs for the RSS feed/image are declared as variables in the PHP script itself. However, I'd like to open up the script for others to use by having their own feed/image links in the URL to the PHP thread (for example, http://www.kyokohunter.net/myanimelistuserbartest2.php?feed=http%3A%2F%2Fmyanimelist.net%2Frss.php%3Ftype%3Drw%26u%3DKyokoHunter ). Here's the code in it's current state (messy...): <?php //$feedurl = "http://myanimelist.net/rss.php?type=rw&u=KyokoHunter"; $feedurl = $_GET['feed']; $endgame = false; $textwidth = 50 / 100; $fontsize = 9; $margin = 5; // Get header info // //$imgFeed = $_GET['imgfeed']; // Detect the type of image and create image variable to suit $im = imagecreatefrompng("MyAnimeList-Dynamic-Userbar.png"); header("Content-type: image/png"); //$orange = imagecolorallocate($im, 220, 210, 60); //$im = imagecreatetruecolor(350, 19); //imagefilledrectangle($im, 0, 0, 349, 18, $orange); // Get image data $imx = imagesx($im); $imy = imagesy($im); // Process RSS feed $rssFeeds = array ($feedurl); foreach ($rssFeeds as $feed) {readFeeds($feed);} $font_file = 'visitor1.ttf'; // Limit length of sentence to 50% of image width // This code constrains the text length to fit within a // certain percentage of the total image width. If the // text is truncated, '...' is appended to indicate // missing text. for ($i = 1; $i <= strlen($string); $i++) { $outstring = substr($string, 0, $i) . "..."; $bbox = imageftbbox($fontsize, 0, $font_file, $outstring); $x = $margin + $bbox[4]; if ( ($x) > ($imx / $textwidth)) { $outstring = substr($string, 0, ($i - 1)); $outstring = trim($outstring) . "..."; break; } $outstring = substr($string, 0, $i); } // Calculate x and y position for placement of text. $bbox = imageftbbox($fontsize, 0, $font_file, $outstring); // Horizontal position: Right $x = $bbox[0] + $imx - $margin - $bbox[4]; // Vertical position: Center $y = $bbox[1] + ($imy / 2) - ($bbox[5] / 2) + 1; $black = imagecolorresolve($im, 0, 0, 0); imagefttext($im, $fontsize, 0, $x, $y, $black, $font_file, $outstring); imagepng($im); imagedestroy($im); // ------------------ FUNCTIONS --------------------- function startElement($xp,$name,$attributes) { global $item,$currentElement; $currentElement = $name; if ($currentElement == 'ITEM') { $item = true; }} function endElement($xp,$name) { global $item,$currentElement,$endgame,$string,$title; if (($name == 'ITEM') and ($endgame != true) ) { $string = "Watching " . trim($title); $title = ''; $item = false; $endgame = true; }} function characterDataHandler($xp,$data) { global $item,$currentElement,$title; if ($item) { //Only add to the globals if we're inside an item element. switch($currentElement) { case "TITLE": $title .= $data; // We use .= because this function may be called multiple // times for one element. break; } }} function readFeeds($feed) { $fh = fopen($feed,'r'); // open file for reading $xp = xml_parser_create(); // Create an XML parser resource xml_set_element_handler($xp, "startElement", "endElement"); // defines which functions to call when element started/ended xml_set_character_data_handler($xp, "characterDataHandler"); while ($data = fread($fh, 4096)) { if (!xml_parse($xp,$data)) { $string = "Feed error"; return 'Error in the feed'; } }}?> I've taken the smallest of steps, and changed //$feedurl = "http://myanimelist.net/rss.php?type=rw&u=KyokoHunter"; to $feedurl = $_GET['feed']; from the working file, and fed it the example the example URL back at the beginning of the topic. The response I get is... "Forbidden You don't have permission to access /myanimelistuserbartest2.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/1.3.41 Server at kyokohunter.net Port 80" Now, I'm not sure if this a PHP issue or a security issue (to do with access). Any advice would be helpful, including pointing towards tutorials on security settings if that's the case. My host is Dataflame, PHP version is 5.2.5, Apache is 1.3.41 (Unix) and the website panel is cPanel X. (edited by kenrbnsn to change the [tt][/tt] tags to ) Link to comment https://forums.phpfreaks.com/topic/133702-403-error-from-using-_get/ Share on other sites More sharing options...
KyokoHunter Posted November 23, 2008 Author Share Posted November 23, 2008 I'm also getting the same problem with this script... looks like something isn't configured properly on the server, right? <?php $to = "[email protected]"; $status = 0; $outputtouser = ""; $statustext = array("","Your message was successfully sent.","Your message was not sent because one or more of the fields contained invalid characters.","There was a problem sending the message."); $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; if (isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['message'])) { //update function to accept multiple variables function checkOK($field) { global $status; if (eregi("\r",$field) || eregi("\n",$field)){ $status = 2; } } checkOK($name); checkOK($email); checkOK($subject); checkOK($message); if ($status != 2) { $message="$name just filled in your comments form. They said:\n$message\n\nTheir e-mail address was: $email"; if(mail($to,"Comments From Your Site: $subject",$message,"From: $email\n")) { $status = 1; } else { $status = 3; } } } ?> <!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>kyokohunter.net - Contact</title> <link rel="stylesheet" type="text/css" href="common/common.css" /> <link rel="stylesheet" type="text/css" href="common/contact.css" /> </head> <body> <span class="pagebackground"><img src="common/images/kyokonet.jpg" width="594" height="401" alt="Background Image" /></span> <span class="span2"> <table class="contentbackground" align="center" cellspacing="0"> <tr> <td class="aligntop"></td> </tr> </table> </span> <span class="span2"> <table class="contentforeground" align="center" cellspacing="0"> <tr> <td class="aligntop bodytext"> <?php if ($status == 0) { ?> Contact Me<br /><br /> <form action="contact.php" method="post"> <input class="entry" type="text" name="name" value="Your Name" /> <br /> <input class="entry" type="text" name="email" value="Your Email Address" /> <br /> <input class="entry" type="text" name="subject" value="Subject" /> <br /> <textarea name="message">Please write your message here.</textarea> <br /> <input class="button" type="submit" value="Send" /> </form> <?php } else { $outputtouser = $statustext[$status]; if ($status > 1) { $outputtouser .= " Please check that you filled in the form correctly and try again."; echo "<span style=\"width: 100%; text-align: center;\">" . $outputtouser . "<br /><br /><a href=\"contact.php\">Back to Contact form</a></span>"; } } ?> </td> </tr> </table> </span> </body> </html> (edited by kenrbnsn to change the [tt][/tt] tags to tags) Link to comment https://forums.phpfreaks.com/topic/133702-403-error-from-using-_get/#findComment-697193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.