Jump to content

davil

Members
  • Posts

    39
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

davil's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. eff it, for now I just replaced it with $errors++;TryAgain(); and removed the increment from the function. it makes no sense why it wouldn't work, but the site isn't mission critical so I don't need to spend too much time on it. Thanks anyway for all your help
  2. This is strange, seems it works fine as standalone PHP but when included into my project at large, it doesn't work as expected. I've checked and there are no other references to $errors, I even changed to $errorz, still no luck... I'll bet there's an easy fix for this but I'm lost for the moment, will keep trying..
  3. Thanks Keith. perhaps it is my server software (uniform server) - I will look into it. What version PHP and Apache you using ? if you're using Apache at all that is?
  4. Yes that's very true. here's the code in its entirety (I've moved the function to the very top of the code now outside the else statement but it's still not working) <?php$errors=0; // set at 0 at the very start {doesn't seem to help though}function TryAgain(){global $errors; //reference the global variable instead of just internal$errors++; //increment the $errors variable;echo '<br/><br/>Please try again <a href="index.php?locate=admin&sub=add_admin">here</a>';echo "<br/>errors=[$errors]";}?><h1>Add a new Administrator Account</h1><?phpif (!isset($_REQUEST['frubmit'])){//check who's logged in$currentuser=$_SESSION["login"];ECHO <<<HEREZ<br/>Here is a list of the current users:<br/><table class='userlist2'><tr>HEREZ;$sql="SELECT `login` FROM `users`";$result = mysql_query($sql) or die (mysql_error());while ($row = mysql_fetch_array($result)){foreach ($row as $key => $value){$$key = stripslashes($value);}echo "<td>$login</td>";}echo <<<HEREZ</tr></table><form enctype="multipart/form-data" method="post" action="index.php"><input type="hidden" name="locate" value="admin"><input type="hidden" name="sub" value="add_admin"><br/>Add a new username:<input type='text' name='newuser' /><input type='submit' name='frubmit' /></form>HEREZ;}else{//NEW USER NAME HAS BEEN SUBMITTED, CHECK IT OUT AND THEN ADD IF OKAY$newuser=$_REQUEST['newuser'];echo "<br/>Trying to add user: $newuser<br/><br/>";if ($newuser){}else{// field was left blank, report this to user and give them option to try againecho '<br/>Field was left empty, you must pick a username.';TryAgain();}if (strlen($newuser)<5){echo 'Username should be at least 5 characters.';TryAgain();}if (!$errors){echo "continue to SQL for adding a user [errors=$errors]";}}?> Basically I don't want it to continue to the SQL stuff (not written yet) unless $errors evaluates to false (or 0). I increment $errors in the TryAgain() function, but for some reason in the above code it doesn't stick. The way I check this is I'm echoing out the value of $errors within the function and outside the function. If you set $newuser to something like 'abc' it echoes out that it is too short, and echoes out $errors as 1 , but then outside the function it reverts back to 0
  5. also the code I posted above seems to work fine on its own but not within my program in an Else{ } block, this must be the key, I'll probably figure it out now any second.
  6. ah I have noticed that the way global variables worked in PHP4 has changed kinda since PHP5, as a security measure - is this right? Here's some info http://wiki.lunarpages.com/PHP_and_Register_Global_Variables unfortunately that applies to POST and GET stuff and I'm just wondering about within a function? should it not still work? I'm hesitant to change the setting in PHP.ini in case this is a seperate thing altogether.
  7. $errors=0; //NEW USER NAME HAS BEEN SUBMITTED, CHECK IT OUT AND THEN ADD IF OKAY $newuser=$_REQUEST['newuser']; function TryAgain(){ global $errors; $errors++; echo '<br/><br/>Please try again <a href="index.php?locate=admin&sub=add_admin">here</a>'; echo "<br/>errors=[$errors]"; } echo "<br/>Trying to add user: $newuser<br/><br/>"; if ($newuser){ }else{ // field was left blank, report this to user and give them option to try again echo '<br/>Field was left empty, you must pick a username.';TryAgain(); } if (strlen($newuser)<5){echo 'Username should be at least 5 characters.';TryAgain();} if (!$errors){echo "continue to SQL [errors=$errors]";} what is wrong with this code? For some reason if I increment $errors with $errors++ within the function it doesn't increment outside the function's scope. even though I declare it as a global at the start of the function. I know I'm doing something stupid here but can somebody please tell me what it is? Thanks
  8. Also I've just noticed that reading the file into a string and then changing it to an array was an unnecessary step - anybody wanting to do similar code to the above should use file() function rather than fread() and use the foreach function to step through the array rather than a 'for' up to the counted number of lines in the file - the script should be far more efficient that way. I was just throwing that one together and learned quite a bit about my bad coding practices so far.
  9. Perfect!! I new it would be something simple. Thanks very much ignace!!
  10. I used to always be able to write to windows text files and create newlines with a simple \r\n but now the text files are being written and \r\n appears in the textfile instead of a newline. I've also tried just \r or just \n but to no avail. I need to edit the services file on multiple XP machines here and add a line, but only if it hasn't been added before. My Code is far from finished but I want to be able to log the process to a text file. also the services file that I'm trying to append to is also adding the \r\n instead of a newline. Here's my code: <?php $windir=getenv('WINDIR'); $dcserver=getenv('LOGONSERVER'); $hostname=getenv('COMPUTERNAME'); $logfile="$dcserver\\NETLOGON\\sap_update_2010\\logs\\$hostname.txt"; $svcfile="$windir\\system32\drivers\\etc\\services"; $logfileHandle = fopen($logfile, 'w'); //OPEN LOG FILE FOR OUTPUT $inputfileHandle = fopen($svcfile, 'r'); //OPEN SERVICES FILE FOR READING (WILL WRITE TO THIS LATER) fwrite($logfileHandle, 'Log File Start... \r\n Test Line 2'); // MORE LOGGING TO COME LATER BUT FOR THE MOMENT I CAN'T GET NEWLINE TO WORK //LOAD IN SERVICES FILE FOR CHECKING $number_of_lines=count(file($svcfile)); //set a variable for amount of lines in services file if ($number_of_lines>10){ //If the file is normal length & no issues $data1 = fread($inputfileHandle, filesize($svcfile)); //read all the lines into a large variable fclose($inputfileHandle); //once read into an variable, we can now close the file handle $array1 = explode("\r\n", $data1); // Explode all Data into an array - line by line for ($a=0;$a<= $number_of_lines-1;$a++){ //step through line by line searching for the sapmsPR2 string if (strstr($array1[$a],'sapmsPR2')){ $done=1; } } if (!$done){ // If the line hasn't already been added, we need to add this line to the file $addline='\nsapmsPR2 3600/tcp #SAP PORT - ROLLED OUT BY SCRIPT'; // This is the line to be added to services file $outp1 = fopen($svcfile, 'a'); //OPEN SERVICES FILE FOR OUTPUT [append] fwrite($outp1,$addline); // WRITE THE LINE TO THE FILE [at the end] fclose($outp1); // CLOSE WHEN FINISHED //ALSO WE NEED TO COPY THE SAPLOGON.INI file to the machine if (!copy($inifile, $newinifile)) { fwrite($logfileHandle, 'Error - failed to copy SAPLOGON.INI across...\n'); }else{fwrite($logfileHandle, 'SAPLOGON.INI copied successfully to Windows folder...\n');} } } //Finish up by closing the log file fclose($logfileHandle); ?> Oh yes, I suppose an important thing to note here is that I'm trying to compile a simple windows CLI exe. to do this I've tried the following with no luck: bamcompile [http://www.bambalam.se/bamcompile/], PHC [http://wiki.swiftlytilting.com/Phc-win#Download] But I've a feeling it's not the compilers because even my WAMP setup is doing the same thing now, whereas before \r\n was fine. I know when reading in files and 'exploding' the data into an array - \r\n works fine, do I need to output to a file differently? Another stupid Question - Is it because I upgraded my own machine to Windows 7 since I last tried something like this - does Win7 treat files differently? I tried to figure out how to do this in binary but I've a feeling it might be easier than all that. If anybody can help me out I'd really appreciate it because I'm on a deadline and don't want to have to re-write this in nasty Autohotkey script or freebasic. and I'm no good at any other decent scripting languages. P.S. just in case anybody wonders, I've been running this EXE as an administrator on my win7 machine so as to give access to services file, but will wrap it in proper admin credentials later for running on the XP machines.
  11. In the end I figured out the way to set the proxy before using PHP's proper curl, and it worked. sorry. The following code reads the info into a variable , $x $ch = curl_init("http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=gen&ServiceTag=$serial&~tab=2&~wsf=tabs"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, "http://10.10.10.10:80"); // Where 10.10.10.10 is the proxy IP and 80 is the port curl_setopt($ch, CURLOPT_PROXYPORT, 80); // Dunno why port 80 is set twice, but I copied this code and it works great curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "myusername:mypassword"); $x = curl_exec($ch);
  12. Hi all, I'm having a problem retrieving some information from the Dell website. I want to write the PHP to go through a text file and grab down warranty info etc from the Dell website for each service tag, I can parse the list no problem but first I want to make sure I can get info down for just one machine, I can do it in my browser like so: IF YOU JUST WANT TO GET INFO FROM TAB1 [WARRANTY INFO], USE THIS (replace ABCDEFG with whatever service tag): http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=gen&ServiceTag=ABCDEFG&~wsf=tabs IF YOU JUST WANT TO GET INFO FROM TAB2 [ORIGINAL SYSTEM CONFIGURATION], USE THIS (replace ABCDEFG with whatever service tag): http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=gen&ServiceTag=ABCDEFG&~tab=2&~wsf=tabs but when I use curl.exe (I'm on Windows) it just gives me HTML of a page requesting the service tag again. As you will see in my code I tried spoofing my user agent, but with no luck. <?php // spoofing Useragent $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; $useragent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.9 (KHTML, like Gecko) Chrome/6.0.400.0 Safari/533.9"; $useragent="Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"; //I've tried all of these strings, but to no avail $serial='abcdefg-replacewithyourownserialnumber'; $url="http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=gen&ServiceTag=$serial&~tab=2&~wsf=tabs"; $stringtosend="curl --user-agent \"$useragent\" -0 $url"; $txt=shell_exec($stringtosend); echo $txt; ?> also the reason I'm using curl.exe and not PHP's curl classes is because I'm behind a proxy and was able to use "proxifier" to re-route curl.exe requests but couldn't get PHP working the same way (tried php.exe , should I have tried apache.exe? ) anyway if anybody knows why the page would react differently to curl than it would in browser , any help is much appreciated. Thanks
  13. Yes you are right I haven't yet checked the link, but I did say I'd check out sockets (fsockopen) - I'm posting on my iPod last couple of days as I'm at an Arts festival, give a guy a chance lol. Thanks for ur help though, didn't mean to be rude bout the acronym thing it was just that I posted my train of thought rather than changing the post after I figured out the CLI thing
  14. Yeah I might just learn a bit bout sockets, I'm okay with Php but network protocols never were my forte
  15. I can ping them using "ping", I am unfamiliar with CLI. Hold on, A quick google tells me CLI means command-line interface. strange I never heard that acronym in 16 years of usings PCs lol but I presume you mean command prompt / terminal or whatever. anyway, to get back to the point, yep they'll ping no problem. I'm not sure if it's vlan1 (about 75% sure) or whatever but it's a fairly basic setup on most of the switches yes.
×
×
  • 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.