Development Adding CR to end of PHP string.

Discussion in 'Software' started by exile, 29 Mar 2004.

  1. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    How do I add a CR to the end of a PHP string?
     
  2. ST8

    ST8 What's a Dremel?

    Joined:
    14 Feb 2003
    Posts:
    596
    Likes Received:
    0
    \n ?
    \r for line return
     
  3. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    Has to be in "double quote" though, not 'single ones'.
     
  4. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    <?php
    $sHTTPa = "GET /frontend/Xskin/mail/doaddpop.html?email=anewuser&domain=wrjournal.net&password=mynewpass&quota=2 HTTP/1.0\r\nAuthorization: Basic d3J364bitpass9yZDE=\r\n";

    $hSocket = fsockopen("www.wrjournal.net", 2082);

    fputs($hSocket, $sHTTPa);

    fclose($hSocket);
    ?>


    Dont work, and i dont know how to see what is happening. :sigh:
     
  5. mookie

    mookie very nawty<br><img src="http://mookie.org/i/avatar

    Joined:
    30 Jun 2002
    Posts:
    639
    Likes Received:
    1
    Try this:
    PHP:
    <?php
    $sHTTPa 
    "GET /frontend/Xskin/mail/doaddpop.html?email=anewuser&domain=wrjournal.net&password=mynewpass&quota=2\r\n";
    $sHTTPa .= "HTTP/1.0\r\n";
    $sHTTPa .= "Authorization: Basic d3J364bitpass9yZDE=\r\n\r\n";
    // Broke it up into lines for easier reading

    $hSocket fsockopen("www.wrjournal.net"2082$errno$errstr30); 
    if (!
    $hSocket ) {
        print (
    "$errstr ($errno)<br>");
        
    // Tells you if there are any errors with the connection
    } else {
        
    fputs($hSocket$sHTTPa);
        
    /* Other stuff in here, etc */
    }
    fclose($hSocket);
    ?>
     
  6. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    I know it is different depending on who is receiving it, but I've always used just the newline escape "\n" without the carriage return "\r"

    so maybe
    Code:
    <?php 
    $sHTTPa = "GET /frontend/Xskin/mail/doaddpop.html?email=anewuser&domain=wrjournal.net&password=mynewpass&quota=2\n"; 
    $sHTTPa .= "HTTP/1.0\n"; 
    $sHTTPa .= "Authorization: Basic d3J364bitpass9yZDE=\n\n"; 
    // Broke it up into lines for easier reading 
    
    $hSocket = fsockopen("www.wrjournal.net", 2082, $errno, $errstr, 30); 
    if (!$hSocket ) { 
        print ("$errstr ($errno)<br>"); 
        // Tells you if there are any errors with the connection 
    } else { 
        fputs($hSocket, $sHTTPa); 
        /* Other stuff in here, etc */ 
    } 
    fclose($hSocket); 
    ?> 
    
    Come to think of it, I've never used \r, even in http headers and whatnot, but I have read that it is neccessary in some cases.
     
  7. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    So you have successfully used \n in http headers?
    i cant try it right now where i am, but i will in 5-8 hrs.
     
  8. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    Actually I just realized I was thinking back on some mail headers I did a few weeks ago for all that carbon copy, blind carbon copy, text format, etc...
    The only time I've done something like what you're doing I copied the code... it was for paypals Instant Purchase Notification, which hasn't worked for me yet :(

    But yes, they used \r\n for each of the carriage returns:
    PHP:
    <?php
    $header 
    .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " strlen($req) . "\r\n\r\n";
    $fp fsockopen ('www.paypal.com'80$errno$errstr30);
    ?>
    Since I don't know much about fsockopen and fgets and all that good stuff yet, I'm not sure how well it works... I need to straighten out the script a bit before I'm sure if it works or not.
     
  9. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    I have been working with it, with NO success. I need to say i want the HTTP /1.0 after the GET because I know it works there. I have successfully done it through telnet many times.

    PHP:
    <?php 
    $sHTTPa 
    "GET /frontend/Xskin/mail/doaddpop.html?email=anewuser&domain=wrjournal.net&password=mynewpass&quota=2 HTTP/1.0\r\n"
    $sHTTPa .= "Authorization: Basic d3J364bitpass9yZDE=\r\n\r\n"
    // Broke it up into lines for easier reading 

    $hSocket fsockopen("www.wrjournal.net"2082$errno$errstr30); 
    if (!
    $hSocket ) { 
        print (
    "$errstr ($errno)<br>"); 
        
    // Tells you if there are any errors with the connection 
    } else { 
        
    fputs($hSocket$sHTTPa); 
        
    /* Other stuff in here, etc */ 

    fclose($hSocket); 
    ?> 

    If anyone has anyother methods of just loading a page/sending headers, i am open, i dont care that i use fsockopen. Its not important, all that is important, is i find someway to work with the HTTP Protocal, in php. :wallbash: Whys the world of php so cruel?

    O ya, OneSeventeen: How does the headers get sent in your code? You know much about paypal? I will be working with that in a few weeks if i ever get this to work.
     
    Last edited: 31 Mar 2004

Share This Page