PHP - Moved: Php Header() At Chrome Failed
This topic has been moved to mod_rewrite.
http://www.phpfreaks.com/forums/index.php?topic=320768.0 Similar TutorialsHey! I am trying to get a database table of users but am running into the error: Warning: file_get_contents(http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=68583) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 in get_user_from_parameter(nabble:utilities.naml:890) - <n.get_user_from_parameter.as_user_page.do/> - public v in C:\xampp\htdocs\website4js\stanford\loadUsernames.php on line 32 I have looked it up and it may be a security thing...The urls I am getting are http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=68583 but the error adds an nodes& part that screws it up. Any way around this? Code: [Select] <?PHP $maxPage = 0; $mainPage = "http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=app_people&node=136"; $mainContent = file_get_contents($mainPage); $pattern = "/(?<=\"Page )\d\d+/"; preg_match_all($pattern, $mainContent, $pageNumb); //find the max page for($i=0;$i<sizeof($pageNumb[0]);$i++) { if($pageNumb[0][$i] > $maxPage) { $maxPage = $pageNumb[0][$i]; } } //echo('Max page is: '.$maxPage.'\n'); //Get an array of all the pages $pages = array(); for($i=1;$i<$maxPage;$i++) { $pages[$i] = "http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/template/NamlServlet.jtp?macro=app_people&node=136&i=".($i*20); } //print_r($userPages); //Get personal page urls and add to MySQL mysql_connect("localhost" , "root") or die("Cant connect"); mysql_select_db("protegeusers") or die("Cant find database"); foreach($pages as $url) { $urlContents = file_get_contents($url); $pattern = "/http:\/\/protege-ontology-editor-knowledge-acquisition-system\.136\.n4\.nabble\.com\/template\/NamlServlet\.jtp\?macro=.+;user=\d+/"; preg_match_all($pattern, $urlContents, $personalPage); foreach($personalPage as $user) { for($i=0; $i<sizeof($user);$i++) { [color=green]$userContents = file_get_contents($user[$i]);[/color] $pattern1 = "/user\/SendEmail\.jtp\?type=user.+;user=\d+/"; $pattern2 = "/(?<=\">Send Email to ).+(?=<)/"; preg_match_all($pattern1, $userContents, $userEmail); preg_match_all($pattern2, $userContents, $username); [color=green]print_r($username); print_r($email);[/color] //$query = "INSERT INTO users (username, userurl) values ('$userName','$userUrl')"; //mysql_query($query); } } } ?> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=350027.0 I am trying to figure how to code around this. I have a DOM scraper function that pulls urls from my database, opens the page, scrapes the data, and then moves onto the next URL to scrape. my issue is that if the page fails to load the script bombs and I have to restart it again. Trying to figure out how if the Code: [Select] $html->find('div[class="itemHeader address"]') as $div fails to open the page it just skips the DOM inspection. Here is my error... Failed to open stream: HTTP Request failed. Here is where I am at with my script.... Code: [Select] mysql_select_db("scraped") or die(mysql_error()); $result = mysql_query("SELECT PKEY, URL, HASSCRAPED, SHOULDSCRAPE FROM CRAWLED WHERE SHOULDSCRAPE ='1' AND HASSCRAPED = '0'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { mysql_query("UPDATE CRAWLED SET CRAWLED.HASSCRAPED = '1' WHERE CRAWLED.URL = '" . $row['URL'] . "'"); $html = file_get_html($row['URL']); foreach($html->find('div[class="itemHeader address"]') as $div) { foreach($div->find('a') as $element){ $CleanData = CleanData($element->innertext); if (strlen($CleanData[0]) > 5){ mysql_query("INSERT INTO SCRAPED (ADDR1, CITY, STATE, ZIP, URL, DATE) VALUES ('" . $CleanData[0] . "','" . $CleanData[1] . "','" . $CleanData[2] . "','" . $CleanData[3] . "','". $row['URL'] . "','". date( 'Y-m-d H:i:s ' ) ."')"); } } } $html->clear(); unset($html); unset($CleanData); } function CleanData($data) { $NewData = trim($data); $NewData = str_replace("<em>", "", $NewData); $AddrCityStateZip = explode("</em>",$NewData); $CityStateZip = explode(",",$AddrCityStateZip[1]); $StateZip = explode(' ',$CityStateZip[1]); $NewDataArray = array ($AddrCityStateZip[0], $CityStateZip[0], $StateZip[1], $StateZip[2]); return $NewDataArray; unset($NewData); unset($AddrCityStateZip); unset($CityStateZip); unset($StateZip); } mysql_close($link); echo 'Scraping has compleated without error'; This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319414.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=351832.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=357315.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=316303.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=346255.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321255.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=321605.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=355345.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=328141.0 Chrome is the browser I use, I have it set up so that the script detects safari and chrome as separate entities. When I browse to it, it shows: You are using Windows XP with a Chrome Web Browserwith a Safari Web Browser now I know stristr() is a case-insensitive version of strstr(), which will find the first form of a word in a string. The problem is that when I use it, the rest of the script doesn't work... it goes to the part as if nothing is there, and shows the text on the bottom. I can't figure out why. Can someone help me, is there a chrome/safari level of priority or am I just missing something? Code: [Select] <?php //Booleans to set OS and Browser to False. $os = false; $browser = false; //Booleans for Web Browser & OS Functions. $xp = xp(); $vista = vista(); $win7 = win7(); $ubuntu = ubuntu(); $chrome = chrome(); $safari = safari(); $firefox = firefox(); $ie9 = ie9(); $ie8 = ie8(); //Operating Systems function xp(){return(preg_match("/Windows NT 5.1/", $_SERVER['HTTP_USER_AGENT']));} function vista(){return(preg_match("/Windows NT 6.0/", $_SERVER['HTTP_USER_AGENT']));} function win7(){return(preg_match("/Windows NT 6.1/", $_SERVER['HTTP_USER_AGENT']));} function ubuntu(){return(preg_match("/Ubuntu/", $_SERVER['HTTP_USER_AGENT']));} //Web Browsers function chrome(){return(preg_match("/Chrome/", $_SERVER['HTTP_USER_AGENT']));} function safari(){return(preg_match("/Safari/", $_SERVER['HTTP_USER_AGENT']));} function firefox(){return(preg_match("/Firefox/", $_SERVER['HTTP_USER_AGENT']));} function ie9(){return(preg_match("/MSIE 9.0/", $_SERVER['HTTP_USER_AGENT']));} function ie8(){return(preg_match("/MSIE 8.0/", $_SERVER['HTTP_USER_AGENT']));} // If you have one of the valid Operating System. if($ubuntu){echo 'You are using Ubuntu Operating System ';} if($xp){echo 'You are using Windows XP ';} if($vista){echo 'You are using Windows Vista Operating System ';} if($win7){echo 'You are using Windows 7 Operating System ';} // If you have one of the valid Web Browser. if($chrome){echo 'with a Chrome Web Browser';} if($firefox){echo 'with an Firefox Web Browser';} if($safari){echo 'with a Safari Web Browser';} if($ie8){echo 'with an Internet Explorer 8 Web Browser';} if($ie9){echo 'with an Internet Explorer 9 Web Browser';} //If OS or Browser not found in list. if ($ubuntu || $xp || $vista || $win7) $os = true; if($firefox || $chrome || $safari || $ie9 || $ie8) $browser = true; if(!$browser || !$os){ echo'<strong>'; echo '<br />' . $_SERVER['HTTP_USER_AGENT'] . '<br /><br />Administrator someone in your work force is using an unsupported browser or OS, please email this information to the developer of the NCMR software you are using. It will allow your browser/OS combination to be used correctly. Sorry for the inconvenience.</strong> <br /><br />Please copy and paste the text above and send it to your web administrator. It will explain everything he/she needs to do.<br />';} ?> $body = <<<EMAIL Hello <[fname]>, You've registered and need to activate your account. Click the link below or paste it into the URL bar of your web browser http://blahblah.com/activate.php?id=<[id]>&code=< Code: [Select] > Thanks! Team EMAIL; The <[id]> isn't working. It literally sends out <[id]> in the email. Hello everyone, I'm just starting out with PHP as I need to create an online bookstore for a school project. I'm working by a magazine which should teach you exactly how to do this using PHP, but I've had a bunch of problems with the code they use and I don't really know what's going on. Anyway, this looks really simple and basically what it does is allows you to post a comment on a book, then returns you to the book's page. Problem is, I'm getting the Header may not contain more than a single header, new line detected. error and I can't figure out why. I've tried researching into the matter but all the cases I found had to do with returning to an url, which is not my case. Anyway, here's the snippet of code: The form: Code: [Select] <div style="width:400px; border:1px solid #ffffff; background-color:#F9F1E7; padding:5px"> <b>Adauga opinia ta:</b> <hr size="1"> <form action="adauga_comentariu.php" method="POST"> Nume: <input type="text" name="nume_utilizator"><br><br> Email: <input type="text" name="adresa_email"><br><br> Comentariu: <br> <textarea name="comentariu" cols="45"></textarea><br><br> <input type="hidden" name="id_carte" value="<?=id_carte?>"> <center><input type="submit" value="Adauga"</center> </form> </div> The script adaugare_comentariu.php: Code: [Select] <?php ob_start(); include("conectare.php"); $numeFaraTags=strip_tags($_POST['nume_utilizator']); $emailFaraTags=strip_tags($_POST['adresa_email']); $comentariuFaraTags=strip_tags($_POST['comentariu']); $sql="insert into comentarii (id_carte, nume_utilizator, adresa_email, comentariu) values(".$_POST['id_carte'].", '".$numeFaraTags."','".$emailFaraTags."','".$comentariuFaraTags."')"; mysql_query($sql); $inapoi="carte.php?id_carte=".$_POST['id_carte']; header("location:urldecode($inapoi)"); ob_end_flush(); ?> conectare.php connects to the mysql database. $inapoi is the variable which returns the user to carte.php (the book he posted a comment on), where id_carte is the book's unique id. I'm getting Header may not contain more than a single header, new line detected on line ten, which is the header line. Can anyone help me? I've been stumped on this for a few days now and I've just let it pass and started working on other bits, but it's bugging me too much and I'd like to fix it. Hi for the following product.php page.
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php if (isset($_GET['id'])) { // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); //$id = $_GET['id']; $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "That item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $product_name; ?></title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <p> </p> <p> </p> <p> </p> <p> </p> <table width="100%" border="0" cellspacing="0" cellpadding="15"> <tr> <td width="19%" valign="bottom"><p><img src="inventory_images/<?php echo $id; ?>.jpg" width="104" height="132" alt="<?php echo $product_name; ?>" /></p> <p><br /> <a href="inventory_images/<?php echo $id; ?>.jpg">View Full Size Image</a></p></td> <td width="81%" valign="top"><h3><?php echo $product_name; ?></h3> <p><?php echo "$".$price; ?><br /> <br /> <?php echo "$subcategory $category"; ?> <br /> <br /> <?php echo $details; ?> <br /> </p> <form id="form1" name="form1" method="post" action="cart.php"> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> </form> </td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html>when i click on image link.. i get ReadResponse() failed: The server did not return a response for this request. pl help asap Edited by mac_gyver, 25 September 2014 - 08:21 AM. code tags please Can someone help me with my problem i'm trying to make and thing to update my database so i can update first name last name and login but i get a "query failed" update-exec.php <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); $login = clean($_POST['login']); //Input Validations if($fname == '') { $errmsg_arr[] = 'First name missing'; $errflag = true; } if($lname == '') { $errmsg_arr[] = 'Last name missing'; $errflag = true; } if($login == '') { $errmsg_arr[] = 'login missing'; $errflag = true; } //Create INSERT query $qry = "INSERT INTO members(firstname, lastname, login,) VALUES('$fname','$lname','$login')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: member-index.php"); exit(); }else { die("Query failed"); } ?> <form id="loginForm" name="loginForm" method="post" action="update-exec.php"> First Name<input name="fname" type="text" value="<?php echo $_SESSION['SESS_FIRST_NAME'];?>" class="textfield" id="fname" /> Last Name<input name="lname" type="text" value="<?php echo $_SESSION['SESS_LAST_NAME'];?>" class="textfield" id="lname" /> Login<input name="login" type="text" value="<?php echo $_SESSION['SESS_USERNAME'];?>" class="textfield" id="login" /> <input type="submit" name="Submit" value="Update" /> </form> Hi guys, I'm getting the following error when i try to upload an image: Code: [Select] Warning: copy() [function.copy]: open_basedir restriction in effect. File(C:\Windows\Temp\phpAF5B.tmp) is not within the allowed path(s): (C:\Inetpub\vhosts\truvibefm.com\httpdocs\) in C:\Inetpub\vhosts\truvibefm.com\httpdocs\testarea\imageupload\upload.php on line 25 Out of commonsense i check the open_basedir in php.ini and it is set too: C:\Inetpub\vhosts\truvibefm.com\httpdocs Thanks for you time! J My php script is: Code: [Select] <?php $SafeFile = $HTTP_POST_FILES['ufile']['name']; $SafeFile = str_replace("#", "No.", $SafeFile); $SafeFile = str_replace("$", "Dollar", $SafeFile); $SafeFile = str_replace("%", "Percent", $SafeFile); $SafeFile = str_replace("^", "", $SafeFile); $SafeFile = str_replace("&", "and", $SafeFile); $SafeFile = str_replace("*", "", $SafeFile); $SafeFile = str_replace("?", "", $SafeFile); $uploaddir = "uploads/"; $path = $uploaddir.$SafeFile; if($ufile != none){ //AS LONG AS A FILE WAS SELECTED... if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED... //GET FILE NAME $theFileName = $HTTP_POST_FILES['ufile']['name']; //GET FILE SIZE $theFileSize = $HTTP_POST_FILES['ufile']['size']; if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB $theDiv = $theFileSize / 1000000; $theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces) } else { //OTHERWISE DISPLAY AS KB $theDiv = $theFileSize / 1000; $theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces) } echo <<<UPLS <table cellpadding="5" width="300"> <tr> <td align="Center" colspan="2"><font color="#009900"><b>Upload Successful</b></font></td> </tr> <tr> <td align="right"><b>File Name: </b></td> <td align="left">$theFileName</td> </tr> <tr> <td align="right"><b>File Size: </b></td> <td align="left">$theFileSize</td> </tr> <tr> <td align="right"><b>Directory: </b></td> <td align="left">$uploaddir</td> </tr> </table> UPLS; } else { //PRINT AN ERROR IF THE FILE COULD NOT BE COPIED echo <<<UPLF <table cellpadding="5" width="80%"> <tr> <td align="Center" colspan="2"><font color=\"#C80000\"><b>File could not be uploaded</b></font></td> </tr> </table> UPLF; } } ?> Ok, I'm having some trouble with file_get_contents failing & am trying to make a loop that will sleep & then retry a maximum of 3 times before giving up & moving to the next item. I tried using a while loop but I'm getting unexpected T_WHILE, which I assume is because it's already in a while loop? I found this: Code: [Select] $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { but could use some clarification. Will that only trigger if it failes or do I need to include another if statement like Code: [Select] $myfile = file_get_contents("http://example.com"); if ($myfile === FALSE) { $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { sleep(3); $myfile = file_get_contents("http://example.com"); } else { //continue with script I hope that makes sense...trying to explain it as best I can without having to post my actual source code as I've had it stolen off forums before & now I have a clone to compete with. I'm not great at putting this into words so if I need to clarify, please feel free to ask. I appreciate any & all help given. Thanks! How can I check to see if a query has failed, be it INSERT, UPDATE, DELETE or SELECT? I want to return one value if the query fails, but a different one if it works. For example, if I have a query to delete a row, but somehow this query fails because the row doesn't exist, then I want to check that it's failed and then output a result |