Jump to content

benphp

Members
  • Posts

    336
  • Joined

  • Last visited

Posts posted by benphp

  1. CURL is a dll on my Windows server - I don't know how to run that from CMD - unless I download the standalone curl.exe.

     

    If I wait half an hour or so I finally get an error from fie_get_contents:

     

    Warning: file_get_contents(http://www.google.com) [ function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

     

    My intuition is that there's some server or network setting that is denying the HTTP request from the server.

  2. I can use both file_get_contents and CURL to fetch the contents of a file on my server, but when I attempt to read a file from outside the server, both just spin forever, never reading the file.

     

    I'm on IIS7 - and Curl is installed and running. I can browse to the locations with no trouble, but if I attempt to fetch the files using PHP, I get nothing. 

     

    Is there some other setting in IIS that I need to enable or disable?

     

    What am I missing? 

     

    Neither works:

    $sourceLink = "http://www.google.com";
    $sourcePageHTML = file_get_contents($sourceLink);
    print $sourcePageHTML;
    
    
    $ch = curl_init("http://www.google.com");   
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec($ch);
    print($data);
     
    Both work:
    $sourceLink = "http://myserver/myfile.php";
    $sourcePageHTML = file_get_contents($sourceLink);
    print $sourcePageHTML;
    
    
    $ch = curl_init("http://myserver/myfile.php");   
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec($ch);
    print($data);

     

  3. I want to fetch the titles from the Courses table, but I only want the Course Title to return once when I join Events.

     

    Courses

    CID | CourseTitle 

     1  | Course A

     2  | Course B

     3  | Course C

     

    Events

    EID | CID | EventDate 

    1   |  1  | 2016-02-22

    2   |  1  | 2016-02-23

    3   |  2  | 2016-02-24

    4   |  3  | 2016-02-25

    5   |  3  | 2016-02-26

     

    If I use a JOIN, 

     

    SELECT Courses.CourseTitle FROM Courses 

    LEFT JOIN Events on (Events.CID = Courses.CID)

     

    then I get

    Course A

    Course A

    Course B

    Course C

    Course C

     

    But what I want is

    Course A

    Course B

    Course C

     

    Because ultimately, I'm going to select an Event date range, and I want to see just the courses with the event date range.

     

    Thanks!

  4. And if there's a space in front of the comment? Or a lone semicolon?

     

    [edit] And while I'm here, how are these files being executed? And what do you get if you do

    <?php
    //my comment
    //my comment
    //my comment
    //my comment
    //my comment
    echo "<pre>\n"; print_r(file(__FILE__)); echo "\n</pre>\n";
    ?>

    Results:

    Array
    (
        [0] =>  //my comment
    
        [2] => //my comment
    
        [3] => //my comment
    
        [4] => //my comment
    
        [5] => //my comment
    
        [6] => echo "\n"; print_r(file(__FILE__)); echo "\n\n";
    
        [7] => ?>
    )
    
    
  5. This is new. For some reason, the PHP errors are not counting my //commented lines.

     

    Example:

    <?php
    //my comment
    :
    ?>
    

    Parse error: syntax error, unexpected ':' in D:\www\myscript.php on line 2

     

    The error is on line 3. If I add more comments, the error is the same:

    <?php
    //my comment
    //my comment
    //my comment
    //my comment
    //my comment
    :
    ?>
    

    Parse error: syntax error, unexpected ':' in D:\www\myscript.php on line 2

     

    Where is this setting?

    Thanks.

  6. I wrote a text encryption function that uses a combination of looped base64_encode, mcrypt_encrypt, and random-ish str_replace that produces a fairly meaningless chunk of text.

     

    How strong is this encryption? For example, how long would it take for the Chinese government to crack it?

  7. $strEvalLink = "<p><a href='http://myserver/evals.php?CLID=3717&INID=93' target='_NewEval'>Please click here to fill out the evaluation for Test</a>.</p><p>Your feedback is important to us.</p><p>Thank You!</p>";
    
    $headers = "Message-ID: <". time() .rand(1,1000). "@".$_SERVER['SERVER_NAME'].">". "\r\n";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "$from_email" . "\r\n";
    mail($to_email, $strEmailSubject, $strEvalLink, $headers);
    

    The result is an email with the link to:

    http://myserver/evals.php?clid=3717&inid=93

    I even print the HTML on the page after sending the mail, and the HTML shows the correct Uppercase values.

  8. PHP v5.2.17

    IIS v7.5

     

    I have a script that hits a MS SQL db that is authenticated via Windows. If I run the script on the local server (localhost for example), it recognizes my Windows logon and passes the logon to MS SQL Server and all is well.

     

    However, when I run the page from another PC, the script fails with: "Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON' ".

     

    I have the page Authentication set so Anonymous Authentication is Disabled, and Windows Authentication is Enabled. This is the correct setting. I know. So why is it that the server isn't authenticating me via the web and passing along the authentication "impersonating" me for MS SQL?

     

     

    I've tried setting fastcgi.impersonate to 0, but that doesn't help at all. Here's my PHP.INI settings:

    default_socket_timeout = 60
    upload_tmp_dir="C:\Windows\Temp"
    session.save_path="C:\Windows\Temp"
    error_log="C:\Windows\temp\php-errors.log"
    cgi.force_redirect=0
    fastcgi.impersonate=1
    fastcgi.logging=0
    cgi.fix_pathinfo = 1

    Any tips, help appreciated!

  9. Using mssql_query to hit a MS SQL db that has a table with "ntext" as the datatype for "MLTEXT"

     

     

    SELECT

      MLID,

      CAST(MLTEXT AS TEXT )
    FROM ANSWER
    WHERE
      NID = 1201

     

    Returns only 110 chars of the MLTEXT. I tried modifying the PHP.INI file to set the max text length, but that didn't seem to make a difference. I tried:

     

    ini_set ( 'mssql.textlimit' , '2147483647' );
    ini_set ( 'mssql.textsize' , '2147483647' );
    mssql_query("SET TEXTSIZE 2147483647");

     

    as well, but still the same results. Is there a better way to fetch the data? Is it the db that's limiting the text length?

     

    Thanks -

     

  10. Yes. I presume the select statement finds no records, because if it did, the IF statement wouldn't allow the insert. So the select finds 0 records, the IF statement allows the INSERT, then somehow the result is 1 record found. The script does insert a record, so that much works. But it's as though the select is done twice: once before the insert and once after the insert - or as others have suggested, the page is refreshed - which isn't happening.

     

    What SHOULD happen is 1) select finds no record. 2) Insert done 3) "You are now enrolled" displays. 4) exit

     

    What IS happeing is 1) select finds no record. 2) Insert done 3) "There are rows" displays. 4) exit

  11. I apolgize for submitting this question on another thread - it occurred to me that it's more of a SQL Server problem.

     

    This script is somehow inserting a row then returning to the SELECT statement and re-SELECTING the row. How do I prevent that from happening? I need to 1) select to make sure the record doesn't exist, then INSERT if it doesn't or post a message saying "already there" if it exists.

     

    I've been pulling my hair out all day on this one. No matter what I do, I can't get it to say "You are now enrolled!". Instead, it always finds rows...

     

    <?php
    $serverName = "myserv";
    $mainDb = "mydb";
    $connectionInfo = array( "Database"=>"mydb");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    if( !$conn ) {
         echo "Connection could not be established.\n";
         die( print_r( sqlsrv_errors(), true));
    }
    
    /////ENROLL SINGLE MANUAL
    if(isset($_POST['btnEnrollMe'])) {
    	$CLID = $_POST['CLID'];
    	$EID = $_POST['EID'];
    	$month = $_POST['month'];
    	$year = $_POST['year'];
    	
    	$classTitle = $_POST['classTitle'];
    	
    	$sqlSelect = "
    	Select 
    		$mainDb.dbo.Class_Students.EID
    	FROM 
    		$mainDb.dbo.Class_Students 
    	WHERE 
    		$mainDb.dbo.Class_Students.EID = $EID 
    	AND
    		$mainDb.dbo.Class_Students.CLID = $CLID
    	";
    
    	$params = array();
    	$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
    	$stmt = sqlsrv_query( $conn, $sqlSelect , $params, $options );
    	$numrows = sqlsrv_num_rows($stmt);
    	sqlsrv_free_stmt($stmt);
    	$stmt = NULL;
    	
    	print "found:$numrows";
    	if ($numrows > 0) {
    		echo "<p>There are rows. </p>";
    	} else {
    		$sqlInsert = "
    		INSERT INTO $mainDb.dbo.Class_Students 
    		($mainDb.dbo.Class_Students.EID, $mainDb.dbo.Class_Students.CLID) VALUES ('$EID', '$CLID')
    		";
    		$stmt = sqlsrv_query($conn, $sqlInsert);
    		print "<P style=\"color:green\">You are now enrolled! <P>";
    		sqlsrv_free_stmt($stmt);
    	}
    	sqlsrv_close($conn);
    	exit;
    }
    ?>
    

     

  12. Been struggling with this for hours now. Can't figure out - looks like the select is done, finds no records, inserts a record, then finds 1 record.

     

    Here's another attempt:

     

    <?php
    $serverName = "myserv";
    $mainDb = "mydb";
    $connectionInfo = array( "Database"=>"mydb");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    if( !$conn ) {
         echo "Connection could not be established.\n";
         die( print_r( sqlsrv_errors(), true));
    }
    
    /////ENROLL SINGLE MANUAL
    if(isset($_POST['btnEnrollMe'])) {
    	$CLID = $_POST['CLID'];
    	$EID = $_POST['EID'];
    	$month = $_POST['month'];
    	$year = $_POST['year'];
    	
    	$classTitle = $_POST['classTitle'];
    	
    	$sqlSelect = "
    	Select 
    		$mainDb.dbo.Class_Students.EID
    	FROM 
    		$mainDb.dbo.Class_Students 
    	WHERE 
    		$mainDb.dbo.Class_Students.EID = $EID 
    	AND
    		$mainDb.dbo.Class_Students.CLID = $CLID
    	";
    
    	$params = array();
    	$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
    	$stmt = sqlsrv_query( $conn, $sqlSelect , $params, $options );
    	$numrows = sqlsrv_num_rows($stmt);
    	sqlsrv_free_stmt($stmt);
    	$stmt = NULL;
    	
    	print "found:$numrows";
    	if ($numrows > 0) {
    		echo "<p>There are rows. </p>";
    	} else {
    		$sqlInsert = "
    		INSERT INTO $mainDb.dbo.Class_Students 
    		($mainDb.dbo.Class_Students.EID, $mainDb.dbo.Class_Students.CLID) VALUES ('$EID', '$CLID')
    		";
    		$stmt = sqlsrv_query($conn, $sqlInsert);
    		print "<P style=\"color:green\">You are now enrolled! <P>";
    		sqlsrv_free_stmt($stmt);
    	}
    	sqlsrv_close($conn);
    	exit;
    }
    ?>
    
  13. I have a script that looks for a record in the SQL Server db first before INSERTing. Trouble is, once it inserts, it always returns a row count of 1. I cannot figure this one out.

     

    I have the same trouble no matter what I do. I orignially thought it was some problem with sqlsrv_num_rows($stmt), which is why I used the counter.

     

     

    The following script will return "You are now enrolled! 1" whether there's a record in the table or not. I'm doing something dumb and I can't see it...

     

    <?php
    
    $sqlSelect = "
    Select EID 
    FROM Class_Students 
    WHERE Class_Students.CLID = '1234'
    ";
    
    $stmt1 = sqlsrv_query( $conn, $sqlSelect );
    $numrows = 0;
    while($row = sqlsrv_fetch_array($stmt1)) {
    	$EID = $row[0];
    	$numrows++;
    }
    sqlsrv_free_stmt($stmt1);
    
    //if not already in the table, then insert them
    if ($numrows > 0) {
    	$msg = "<p>You are already enrolled in this class. $numrows</P>";
    } else {
    	$sqlInsert = "INSERT INTO Class_Students (EID, CLID) VALUES ('5555', '1234')";
    	$stmt2 = sqlsrv_query( $conn, $sqlInsert );
    	$msg = "<P>You are now enrolled! $numrows<P>";
    	sqlsrv_free_stmt($stmt2);
    }
    print $msg;
    sqlsrv_close($conn);
    ?>
    

    If I comment out the insert, I can at least get it to print "You are now enrolled", but if I allow the insert, it always counts 1 record - even when the count comes BEFORE the insert.

  14. Found it. Add this to the HTML -

     

    <!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">
    <html>
    <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
    <meta name=ProgId content=Word.Document>
    <meta name=Generator content="Microsoft Word 9">
    <meta name=Originator content="Microsoft Word 9">
    <title>My Title Here</title>
    <LINK href="common/style.css" type=text/css rel=stylesheet>
    <style>
    @page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
    div.Section1 {page:Section1;}
    @page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
    div.Section2 {page:Section2;}
    </style>
    </head>
    <body>
    <div class=Section2>
    stuff here
    </div>
    </body>
    </html>
    

     

    Thanks Barand for sparking my memory!

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