Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Posts posted by GingerRobot

  1. but i still dont quite undestand how white spaces are sent  i mean we indent code writing any programming language so does that white spaces sent to the browser ????

     

    No, that wouldn't send whitespace to the browser because it would be interpreted(or, more accurately, ignored) by the PHP engine. You get whitespace in any HTML that you might send to the browser. One of the important things to recognise is that anything not contained within PHP tags is considered HTML. So the following code fragment would send a line of whitespace:

     

    <?php
    //code
    ?>
    
    <?php
    //more code
    ?>
    

     

    As would the following code (which is often the cause of the header error):

     

    
    <?php
    //code
    ?>
    

     

    It's more difficult to spot, since it's at the top of the code. Further, in included files, you shouldn't have any whitespace after the closing PHP tag, as this could cause you troubles.. Indeed, it's valid (and recommended by some coding standards) to leave off the last closing PHP tag of a file if there's no HTML to follow to avoid this problem.

     

     

  2. Yes, it should have been called twice, and that just causes an error

     

    Or, more specifically, a notice. Which a lot of people don't realize exists, owing to their error reporting level. In any case, the second call is ignored.

  3. Well I assume you should move this line:

     

    $pdftext = pdf2txt('C:\Users\Mike\Desktop\Athy Database\Athy Register.pdf');

     

    To outside of all the functions. Not having written or looked at the code, I can't guarantee that will work for you, however.

  4. ...please, for the love of God, type correctly, and ask a question.

    I'm sorry, but I'm at my breaking point.

     

    If you're annoyed by that, i wouldn't stick around. We get much worse  ::) Don't forget that English might not be everyone's first language. That said, you do have a point....nirVaan, you should really try to make more effort to punctuate your posts.

  5. The first thing i notice which could be wrong is that you're not providing a cookie jar. The request to the login will, no doubt, set a cookie. However, you're following location and the home page will no doubt check the existence of said cookie. It wont be there, so it'll redirect you to the login page.

     

    There could be other things wrong, however. Have you checked carefully about what data is POSTed to the login page? The firefox Live HTTP Headers extension is pretty useful for this...

  6. so my problem is isnt before the header("Content-Type: image/jpeg") is called other html tags have been outputed to the browser like < td > Enter text seen in this image < br/ >

     

    No, that header is sent on a separate request to the webserver. Headers (amongst other things) tell the browser what kind of data is being sent. When you load the page with the form on, your browser makes a request to the webserver, which serves the webpage. You may or may not have sent a header with this response and, if you haven't, the browser will guess that it's supposed to be HTML. One of the things the page contains is an image. The browser must then fetch that image also, which is a separate request. A different request may, of course, be for different content.

     

    and another question is how exactly does a white space or empty lines out putted to the browser

     

    Whitespace in your PHP/HTML code are output to the browser, although they don't "do" anything. That is why you'll not see them unless you view the source of the webpage in your browser or output the php code to a file/stream.

  7. I don't know. You still haven't really told us what the problem is. Why don't you take a little more care over your posts and explain things more fully?

     

    As before, I can continue to stab in the dark...my next guess (without any more information) is that your query is failing and you have the display of errors turned off. Add the following two lines to the top of your script:

     

    error_reporting(E_ALL);
    ini_set('display_errors','On');
    

     

    And add some debugging to your query. Replace this line:

     

    $query = mysql_query("SELECT * FROM members WHERE picture='$picture'");
    

     

    With:

     

    $query = mysql_query("SELECT * FROM members WHERE picture='$picture'") or trigger_error(mysql_error(),E_USER_ERROR);
    

     

  8. Well the syntax error is due to the lack of braces around your if/else statements. Try:

     

    <?php
    session_start();
    
    if ($_SESSION['username']){
    
       echo "Welcome, ".$_SESSION['username']."!<br><a href='Logout.php'>Log Out</a>";
       
       $stacks = array("
    
          <form enctype='multipart/form-data' action='insert.php' method='post' name='changer'>
    
    <p align='center'><input name='image' value='image' type='text'>   <br>
    <input type='text' name='hyperlink'value='hyperlink'>  <br>
    <input type='text' name='currency' value='currency'> <br>
    <input type='text' name='name' value='name'> <br>
    <input type='text' name='info' value='info'> <br>
    <input type='text' name='keywords' value='keywords'> <br>
    <input type='text' name='type' value='type'> <br>
    <input type='submit' value='Submit'><br></p> ");
    
    
    
    
    }else{
       die("You must be logged in!");
    }
    
    
    
    ?>
    <?php
      <form enctype='multipart/form-data' action='Admin.php' method='post' name='changer'>
      <input type='submit' value='duplicate'>
    $button = $_GET['duplicate'];
       if(!$button)
         array_push($stack, $stack);
       echo $stack;
    
    

     

    Though i'm afraid things aren't quite as simple as you've got there. You'll need to name all your input fields as arrays. Each time the "duplicate" button is clicked, you'll have to loop through each field and echo out the value if it exists -- otherwise you'll get your new input fields, but you'll lose all the data. Here's an old script where i did something similar:

     

    <?php
    
    $userid = $_SESSION['uid'];
    
    $done = FALSE;
    
    if(isset($_POST['makepayments'])){
    
    $inserts = array();
    
    foreach($_POST['category'] as $x=> $category){
    
    	if(!empty($_POST['amount'][$x]) && $_POST['amount'][$x] > 0){
    
    		$amount = mysql_real_escape_string($_POST['amount'][$x]);
    
    		$date = mysql_real_escape_string($_POST['date'][$x]);
    
    		$details = mysql_real_escape_string($_POST['details'][$x]);
    
    		$inserts[] = "('".mysql_real_escape_string($category)."','$details','$amount','$date',$userid)";
    
    	}
    
    }
    
    $insert = implode(',',$inserts);
    
    if(count($inserts) > 0){
    
    	$sql = "INSERT INTO items (cat_id,description,price,purchase_date,uid) VALUES $insert";
    
    	mysql_query($sql) or trigger_error(mysql_error().'<br />Query Was: <br />'.$sql,E_USER_ERROR);
    
    }
    
    $done = TRUE;
    
    $doneamount = count($inserts);
    
    $_POST = array();
    
    
    
    }
    
    ?>
    
    <h3>Make Payment</h3>
    
    <?php
    
    if($done===TRUE){
    
    echo $doneamount. ' payment(s) successfully added<br /><br />'."\n";
    
    }
    
    $sql = "SELECT COUNT(*) FROM categories WHERE uid=$userid";
    
    $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
    
    if(mysql_result($result,0)==0){
    
        echo 'Before you can add a payment, you need to add some categories. Go to <a href="index.php?page=admin">the administration page</a> to add some.';
    
    }else{
    
    ?>
    
    <form method="post">
    
    Reload with
    
    <select name="numfields" />
    
    <option value="1">1</option>
    
    <option value="2">2</option>
    
    <option value="3">3</option>
    
    <option value="4">4</option>
    
    <option value="5">5</option>
    
    <option value="10">10</option>
    
    </select>
    
    field(s)
    
    <input type="submit" name="reload" value="Reload" />
    
    <br />
    
    <br />
    
    <table>
    
    <tr>
    
    <th>Details</th>
    
    <th>Spent On</th>
    
    <th>Date</th>
    
    <th>Amount</th>
    
    </tr>
    
    <?php
    
    if(isset($_POST['reload'])){
    
    $numfields = (int) $_POST['numfields'];
    
    }else{
    
    $numfields = 1;
    
    }
    
    for($x=0;$x<$numfields;$x++){
    
    echo "<tr>\n";
    
    echo '<td><input type="text" name="details['.$x.']" value="';
    
    echo (isset($_POST['details'][$x])) ? $_POST['details'][$x] : '';
    
    echo '" /></td>'."\n";
    
    echo '<td>'."\n";
    
    echo '<select name="category['.$x.']">'."\n";
    
    $sql = "SELECT id,name FROM categories WHERE uid=$userid ORDER BY id ASC";
    
    $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
    
    while(list($id,$name) = mysql_fetch_row($result)){
    
    	$selected = '';
    
    	if(isset($_POST['category'][$x]) && $_POST['category'][$x] == $id){
    
    		$selected = 'selected="selected"';
    
    	}
    
    	echo '<option value="'.$id.'" '.$selected.'>'.$name.'</option>';
    
    }
    
    echo '</select>';
    
    echo '</td>'."\n";
    
    echo '<td>'."\n";
    
    echo '<input type="text" name="date['.$x.']" value="';
    
    echo (isset($_POST['date'][$x])) ? $_POST['date'][$x] : date('Y-m-d');
    
    echo '" />'."\n";
    
    echo '</td>'."\n";
    
    echo '<td><input type="text" name="amount['.$x.']" value="';
    
    echo (isset($_POST['amount'][$x])) ? $_POST['amount'][$x] : '';
    
    echo '" /></td>'."\n";
    
    echo '</tr>';	
    
    }
    
    ?>
    
    
    
    </table>
    
    <br />
    
    <input type="submit" name="makepayments" value="Make Payments" />
    
    </form>
    
    <?php
    
    }
    
    ?>
    

     

    Lastly, you could have this work a lot nicer with Javascript -- the page wouldn't have to reload each time you add fields. It's pretty easy to accomplish with the jQuery framework too.

  9. By blank you mean a completely blank page? Do you have any other output that's supposed to be displayed? If so, chances are you have an error and have display errors turned off. Otherwise, is the while loop even running? Perhaps there are no rows in the result set.

  10. Hence I want a code-remodification that can validate these forms without tampering with the hidden fields.

     

    Just because a field is hidden, you cannot rely on it. A malicious user could still tamper with the data. You need to validate hidden fields also

  11. I guess that's why I was wondering if it's more simple to just grab each section of text which is between the tags <h1> and </h1>

     

    Yeah, it probably is:

     

    <?php
    
    $mytext = "<h1>Title One</h1><br>This is text one<br><br><br><h1>Title Two</h1><br>This is text two<br><br><h1>Title Three</h1><br>This is text three";
    preg_match_all('|<h1>(.*?)</h1>|s',$mytext,$matches);
    
    foreach($matches[1] as $key => $title){
        echo "<a href=somepage.php?id=" . ($key+1) . ">" . $title . "</a><br>\n";
    }
    ?>
    

  12. Well if the break line tags always come at the end but are variable in number, you could modify my code by using preg_split instead of explode():

     

    $mytext = "<h1>Title One</h1><br>This is text one<br><br><br><h1>Title Two</h1><br>This is text two<br><br><h1>Title Three</h1><br>This is text three";
    $titles = preg_split("|(<br>)+|i",$mytext);
    
    for($x=0;$x<count($titles);$x+=2){
        echo "<a href=somepage.php?id=" . (($x/2)+1) . ">" . strip_tags($titles[$x]) . "</a><br>\n";
    }
    

     

    But it may be that regular expression solution would be neater.

  13. There have been some positive changes recently. For example many music subscription sites now offer files that are not encumbered with draconian DRM technology.

     

    The "information age" has completely broken the model with which content providers have used for decades. They didn't know how to do anything differently. So, they pushed ahead putting whatever measures in place to prevent (so they thought) people from accessing content for which they didn't pay. But, what they have failed to realize is that the only people that were affected by DRM were the people that paid for the content. People who steal music, or other media, do not steal DRM'd content!

     

     

    They also failed to realise that, regardless of the DRM used, there would be a constant cat-and-mouse game of people finding ways around it. So once again, it's the people who wouldn't try and share music who suffer while those that do share music don't.

  14. I'll look into that one.  Right now I am currently enjoying last.fm  It's a free service, supported by ads, as well as revenue based on offering accessibility to buy.  They have a huge database of songs.  You can listen to the full version of songs up to like 5 times per song or something.  After that, you can listen to a 30s clip of it.  They also have radio stations and suggestions etc.. meant to help expose you to other artists/songs you might like, based on what you listen to and how you rate it.  So far I'm loving this site, as I have quickly found a ton of stuff I would have otherwise never heard of.

     

    I've always used last.fm more as a record of the music i've listened to (can be surprising to see what you listen to most!) and as a way of getting recommendations, rather than for actually playing music. I know they have their radio stations and such, but i've never really found it that great to use.

  15. Offering things like subscription based music listening or downloading songs cheaply on an individual basis is a step forward (though not the ultimate ideal solution).

     

    I don't think spotify has been launched yet in the US, but this kind of thing might really work. It's a streaming music service supported by adverts. You can play as much as you like and get an advert around every 8-10 songs, and i think they aim to tie them in with the end of an album if possible. Less adverts than a radio station and you get to choose the music. Or you can pay to have the adverts removed and it becomes more like your regular subscriptions service.

     

    It's certainly enjoying a lot of usage here in the UK. And i'm not surprised really...it's less effort to stream something and start listening instantly than it is to download, the library is pretty large and the adverts really aren't all that intrusive.

     

    I'd imagine there's pretty decent potential for advert revenues too. Targeted advertising is always a better and i'd imagine you could get a fairly accurate idea of a listener's demographic from the music listening history.

×
×
  • 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.