Jump to content

benphp

Members
  • Posts

    336
  • Joined

  • Last visited

Everything 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. OK -thanks! Yes, that works. But what if I did this: SELECT Courses.CourseTitle, Events.EventDate FROM Courses LEFT JOIN Events on (Events.CID = Courses.CID) Distinct wouldn't work, right?
  4. 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!
  5. I found the trouble. I'm using Notepad++, and I replaced all carriage returns with new line (replaced \r with \n). I'm not sure how the \r got in there.
  6. 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.
  7. 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?
  8. Strange behavior - so when I hover over the link in the Outlook email, the url shows all lower case. But if I click the link, it goes to the right web page with correct upper/lowercase text.
  9. $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.
  10. For example, can I do: if ($test == "yes") $myOp = ">"; } else { $myOp = "<"; } I know this doesn't work, but is there a way to do this with curly brackets? And then: if (($img == "0" && $textCount $myOp 1000) || $img == "") { //do this }
  11. 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!
  12. 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 -
  13. This is an easy one for you masters. I find it a PIA - http://myserver/calendar/events.php I want: http://myserver/calendar/ or http://myserver/calendar ?
  14. mac_gyver and others - yes - you have found the problem. The page is being loaded twice. For what reason I have no idea.
  15. 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
  16. 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; } ?>
  17. 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; } ?>
  18. Tried POST with the same results. I just rebooted my server too, just for good measure.
  19. There's no loops - no multiple submits. It's a straight GET method from one page to another. No paraphrasing. I know - it's driving me nuts. The only thing I can think of is the parameters for sqlsrv_query aren't clear to me. Looking into the options: SQLSRV_CURSOR_KEYSET, etc. to see if that makes a difference. I think the answer may lie there.
  20. 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.
  21. I have two tables: Classes CLID | CLDate ClassDetail CLID | Description | Instructor I'm trying to figure out a single SQL statement that would return all CLIDs that exist in ClassDetail but NOT in Classes. I'm in the process of fudging it in PHP, but I know there's a better way... Thanks!
  22. 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.