Jump to content

papaface

Members
  • Posts

    1,437
  • Joined

  • Last visited

    Never

Posts posted by papaface

  1. Hey

     

    I wonder if someone can help be debug a script that is giving me a right headache. The script receives data from an API.

     

    I have this code:

    	$message="<html><head><style>
    body,td { font-family: verdana; font-size: 11px; font-weight: normal; }
    a { color: #0000ff; }
    </style></head><body>".$message."</body></html>";
    echo "hello";
    $Users=getClients();

     

    getClients() function:

    function getClients(){
    
    global $count,$INCREMENT;
    
    $url = "http://URLapi.php";
    
    $username = "dev";
    
    $password = "password";
    
    
    
    $postfields["limitstart"] = $count;
    
    $postfields["limitnum"] = $INCREMENT;
    
    $postfields["action"] = "getclients";
    
    $postfields["username"] = $username;
    
    $postfields["password"] = md5($password);	
    
    
    
    
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    curl_setopt($ch, CURLOPT_POST, 1);
    
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    
    $data = curl_exec($ch);
    
    curl_close($ch);
    echo $data;
    
    $xml = simplexml_load_string($data);
    
    $Xml = simpleXMLToArray($xml,true,true,true);
    
    
    
    return $Xml;
    
    }
    

     

    If you look in the first bit of code you'll see

    echo "hello";

    If I remove this the data from the cURL request outputs to the screen via my echo $data; code.

    If I keep echo "hello"; it stops processing and nothing is displayed.

     

    What could be causing this?

  2. Hi there

     

    I'm trying to work out how I'd go about searching my database for URLs that have been submitted by users that are duplicates.

    Now this isn't as simple as http://www.example.com/something.php and http://www.example.com/something.php oh no!

     

    People have entered links such as http://www.example.com//something.php or http://www.example.com///something.php

     

    The script (I didn't write it) currently see's these links as unique, but they're not. They function exactly the same way.

     

    Anyone have any advice on how to weed these out?

     

    I was thinking maybe a straight forward LIKE '%//%' in the mySQL syntax, but this will bring all URLs up due to the http:// aspect of the link

     

    Any feedback would be appreciated!

  3. Hi

     

    I have the following HTML:

    																	<div class="categories">
    			<a href="http://www.domain.com/asp-tutorials" class="catTitle">
    			<img src="http://www.domain.com/img/29.jpg" alt="ASP Tutorials"></a>
    			<a href="http://www.domain.com/asp-tutorials" class="floatLeft catTitle">ASP Tutorials</a><a href="http://www.domain.com/asp-tutorials/rss/categories.php?chid=29" title="RSS Feed for all ASP Tutorials!" class="rss"><img src="http://www.domain.com/images/rss_icon.gif" width="28" height="12" alt=""/></a>
    			</div>

     

    I am trying to retrieve the href in this line using regex:

    <a href="http://www.domain.com/asp-tutorials" class="catTitle">

     

    I have this:

    $expr = '/<div class="categories">.*?<a href="(.*?)" class="catTitle">.*?<img src=".*?" alt=".*?"><\/a>.*?<\/div>/s';
    preg_match_all($expr,$file,$info,PREG_SET_ORDER);
    
    print_r($info);

    But it is returning no results.

    There are a few categories on the page which I'm trying to retrieve the links for.

    Anyone have any idea why?

  4. Hey

     

    I have a string that looks like the following:

    top-php-tutorials-2.html

     

    I have a script that cycles through each page. The 2 in the quote above is the page number.

     

    How can I extract the number between the - and the .html and replace it with another number?

     

    I've tried

    substr($engine->selectedcaturl, 0,-6).$v.".html"

    But then I realised this only works for numbers that are 1 digit long :(

     

    Any input would be appreciated :)

  5. I have a script that runs for quite a while (about 700 second per video).

    When it is run, it outputs some information for a cURL session.

     

    Once the cURL process is initiated php starts downloading a large file to a directory. The file is around 65mb.

    When the file is finished downloading through curl I have the following code:

    echo "Downloaded <br />";
    
    $sw->runDBQuery("UPDATE `videoinfo` SET `videoDownloaded` = '1' WHERE `videoStorageKey`= '".$videostoragekey."' ");

    The problem I am having is that the script is NOT outputting "Downloaded" in SSH or in the browser BUT the SQL query is being run correctly, and in the background the script moves onto the next file to download (i can see this by monitoring the download directory) but I see no output at all!

     

    This leads me to come to two conclusions.

     

    Apache is not timing out the request as in SSH, apache is not involved.

    The browser is not at fault, as I am using Putty.

     

    So what could be causing this issue?

     

    I am TOTALLY stuck. I cannot work out what the issue could be, it is driving me insance.

     

    Any help would be appreciated.

  6. Hi

     

    I'm currently writing a script that basically downloads videos from a specific page.

    I am downloading with cURL however with some files, they're so large cURL is timing out.

     

    This is causing either

    a) PHP to timeout

    b) PHP memory to run out

    c) cURL to stop once defined timeout limit is reached

     

    This means that some files are only partitially downloaded as some files are over 100mb and some are only 20mb

     

    I have

    set_time_limit(0);

    and

    ini_set("memory_limit","500M");

    set but is there a way to make it so PHP will not timeout and the cURL session will not timeout until the file is downloaded?

  7. <?php
    session_start(); 
    if	($_SESSION['basic_is_logged_in'] == true)
    {
    echo "you are logged in";	
    }
    else
    {
    	if(isset($_POST['btnLogin']) || isset($_POST['addpost'])){
    	$txtUserId = $_REQUEST['txtUserId'];
    
    	$txtPassword = $_REQUEST['txtPassword'];
    
    	if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
    
    
    
    
    	if ($_POST['txtUserId'] === 'admin' && $_POST['txtPassword'] === 'abc123') {
    
    
    
    
    	$_SESSION['basic_is_logged_in'] = true;
    
    	echo "you are logged in";
    
    	}
    
    	elseif (empty($txtUserId) || empty($txtPassword))
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    	{
    
    
    
    
    
    
    
    
    
    
    
    	echo "fill in username and password";
    
    
    
    
    
    
    
    
    
    
    
    	}  
    	elseif ($_POST['txtUserId'] != 'admin'){
    
    
    
    
    	echo "wrong username";
    
    
    
    
    	}
    
    	elseif ($_POST['txtPassword'] != 'abc123'){
    
    
    
    
    
    
    
    
    
    	echo "wrong password";
    
    
    
    
    
    
    
    
    
    
    	}
    	}
    	}
    	?>
    	<?php
    	//if (!isset($_SESSION['basic_is_logged_in']) 
    	//   || $_SESSION['basic_is_logged_in'] !== true) 
    	  
    	?>
    
    
    	<html>
    	<head>
    	<title>Main User Page</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    	</head>
    
    	<body>
    
    	<form method="post" name="frmLogin" id="frmLogin" action="main.php">
    	<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
    	<tr>
    	<td width="150">User Id</td>
    	<td><input name="txtUserId" type="text" id="txtUserId"></td>
    	</tr>
    	<tr>
    	<td width="150">Password</td>
    	<td><input name="txtPassword" type="password" id="txtPassword"></td>
    	</tr>
    	<tr>
    	<td><input type="submit" name="btnLogin" value="Login"></td>
    	</tr>
    	<tr>
    	<td><input type="submit" name="addpost" value="add post" /></td>
    	</tr>
    	<tr>
    	<td><input type="submit" name="showstat" value="Show visitors log" /></td>
    	</tr>
    	<tr>
    	<td><input type="submit" name="blogg" value="To blog (logout)" /></td>
    	</tr>
    
    	</table>
    	</form>
    
    
    	</body>
    	</html>
    <?php
    }
    ?>

  8. Hey

     

    I am wondering if someone could please give me the regex to retrieve the

     

    <div class="category-thumb"> <a href="/categories/php" onClick="pageTracker._trackEvent('Coding Tutorials','Click Here');"><img src="http://www.domain.com/img/phpcode.jpg" alt="PHP" /></a> <h6><a href="/categories/php" onClick="pageTracker._trackEvent('Coding Tutorials','Click Here');">PHP</a></h6><span>5 tutorials</span></div>

     

    I am trying to obtain this part of the block:

    >PHP</a>

    There are mutliple blocks like this on the page so I am building up an array with

    preg_match_all($expr,$this->html,$info,PREG_SET_ORDER);

     

    Any help would be appreciated!

  9. also this bothers me: $info['Pages'][] = $v2; the code is looping over the array $info['Pages'] and modifying the array at the same time.

    Thats right.

    It needs to do this so that it automatically goes through all the elements/pages.

    Do you think it'd be better to do:

    while (count($info['pages']) > 0)

    ?

  10. Removed it and it stops in the same place. Except it just has more items in the info[pages] array

    $info['Pages']:Array ( [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 )
    mappedpagenumbers:Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 ) 

  11. foreach($info['Pages'] as $k => $v)
    {
    
    	$returned = $km->fetchCatPageInfo($km->selectedcaturl."?page=".$v,array("Page"=>array('<div class="pagination">','>></a></li> </ul></div>')             ));	
    	?>
    	Page <?php echo $v;?>:<textarea><?php print_r($returned['HTML']); ?></textarea>
    	<?php
    	$km->mappedpagenumbers[] = $v;
    
    	foreach	($returned['Pages'] as $k2 => $v2)
    		{
    		if	(!in_array($v2,$km->mappedpagenumbers) && !in_array($v2,$info['Pages']))
    			{
    			$info['Pages'][] = $v2;
    			}
    		}
    	unset($info['Pages'][$k]);
    
    
    }

    Please see above

  12. Hey

     

    I wonder if you could help me.

    I have a script that scans a given webpage for the pagination numbers.

     

    Firstly I scan the page and load all the page numbers into $info['page'] as an array.

     

    I then setup a foreach loop, to go through each element (page number in the array).

     

    So the result is like:

    Array
    (
        [1] => 2
        [2] => 3
        [3] => 4
        [4] => 5
        [5] => 6
        [6] => 7
        [7] => 8
        [8] => 9
        [9] => 10
    )
    

     

    Element 1 is page 2 etc.

     

    In the foreach loop I get it to scan page 2 of the webpage and return the page numbers. I am careful to not add a page number to the array if it already exists, and I also have another array that holds all the page numbers that has been scanned. I have this working fine.

     

    The problem I have, is that it is only looping up to page 10, despite the $info['page'] array having

    ( [9] => 10 [10] => 11 [11] => 12 [12] => 13 ) 

    left in it.

    Why is this?

     

    Any help would be appreciated.

  13. What does  $image_name print out? Use this code

    <?php require_once('Connections/localhost.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    $query_Recordset1 = "SELECT Images FROM testimonials WHERE Testimonial_Id=%s";
       
       $img_dir = 'uploaded_images/';
         $image_name = $row_RecordSet1['Images'];
    echo $image_name; die();
    if ((isset($_GET['del'])) && ($_GET['del'] != "")) {
       unlink($img_dir . $row['Images']);
    // unlink($img_dir.$image_name);
    
      $deleteSQL = sprintf("DELETE FROM testimonials WHERE Testimonial_Id=%s",
                           GetSQLValueString($_GET['del'], "int"));
    
      mysql_select_db($database_localhost, $localhost);
      $Result1 = mysql_query($deleteSQL, $localhost) or die(mysql_error());
    
      $deleteGoTo = "index.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $deleteGoTo));
    }
    
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $maxRows_Recordset1 = 10;
    $pageNum_Recordset1 = 0;
    if (isset($_GET['pageNum_Recordset1'])) {
      $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
    }
    $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
    
    mysql_select_db($database_localhost, $localhost);
    $query_Recordset1 = "SELECT * FROM testimonials ORDER BY SortOrder ASC";
    $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
    $Recordset1 = mysql_query($query_limit_Recordset1, $localhost) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    
    if (isset($_GET['totalRows_Recordset1'])) {
      $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
    } else {
      $all_Recordset1 = mysql_query($query_Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
    }
    $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
    
    
    ?>
    <!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>Sub-Lime Renovations Admin Area - View Testimonials</title>
    
    
    
    </head>
    
    <body>
    <div align="center">
      <h1><strong>Sub-Lime Renovations Administration Area</strong></h1>
    </div>
    <p align="center"><a href="index.php">Admin Home</a> | <a href="add_testimonials.php">Add Testimonials</a></p>
    <p> </p>
    <p> </p>
    <table border="1" align="center" cellpadding="1" cellspacing="1">
      <tr>
        <td>Customer Name</td>
        <td>Town</td>
        <td>Testimonial</td>
        <td>Sort Order</td>
        <td>Images</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php echo $row_Recordset1['CustomerName']; ?></td>
          <td><?php echo $row_Recordset1['Town']; ?></td>
          <td><?php echo $row_Recordset1['Testimonial']; ?></td>
          <td><?php echo $row_Recordset1['SortOrder']; ?></td>
         <td><img width ="100" height="100" src="/AdministrationAreaSublime/<?php echo $row_Recordset1['Images']; ?>" alt="" /></td>
          <td><a href="edit_testimonials.php?Testimonial_Id=<?php echo $row_Recordset1['Testimonial_Id']; ?>">Edit</a></td>
          <td><input type="button" name="del" id="del" value="Delete" onClick="document.location.href='testimonials.php?del=<?php echo $row_Recordset1['Testimonial_Id']?>'" /></td></tr>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <p> </p>
    </body>
    </html>
    <?php
    
    mysql_free_result($Recordset1);
    ?>

  14. Could try

    <?php
    
    $info = @getimagesize("http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs349.snc4/41540_772137439_5612219_q.jpg");
    if	(isset($info["mime"]))
    echo "yay it exists" . "<br />";
    else
    echo "nope it doesnt exist" . "<br />";
    
    
    $info = @getimagesize("http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs349.snc4/41540_772137439_5612219_qXXX.jpg");
    if	(isset($info["mime"]))
    echo "yay it exists" . "<br />";
    else
    echo "nope it doesnt exist" . "<br />";
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.