Jump to content

jacko310592

Members
  • Posts

    222
  • Joined

  • Last visited

    Never

Everything posted by jacko310592

  1. hey guys, does anyone know of a code which will allow me to delete a single line from a txt document? thanks
  2. thanks MatthewJ, i had just realised what was wrong just as i saw your comment xD its because i copyed that number and letter string directly from the net (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789), and the quotation marks surrounding it where the html type (“ and ”), so i replaced them for " ", i didnt see that error on my text editor, its only when i saw the way it had come up on this forum when i realised. $characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  3. hey guys, i have the following code to genorate a random string of upercase and lowercase letters and numbers. the only this is that sometimes it seems to output an unknown symbol(s) as part of the string here is the code: <?php function genRandomString() { $randomLength = mt_rand(10, 20); $length = $randomLength; $characters = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789”; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } echo genRandomString(); ?> output string examples: can anyone suggest a way to prevent this? thank you
  4. thanks a lot (: its works fine now
  5. thanks JAY6390, i removed all the whitespace and it worked. but i needed to then add it to a more of a styled page (so i needed to add <html><head><body> tags etc) which is the following code, which then made the code not work again <?php $thisPage='Admin Login';?> <?php $userName = $_POST['name']; $password = $_POST['pass']; $userInfo = array('user1'=>'pass1', 'user2'=>'pass2'); $randomString1 = "xu5rac9Erub7KAPh"; $randomString2 = "P327efA5ujadRAfa"; if (isset($_COOKIE['MyLoginPage'])){ if ($_GET["logout"] == "true"){ setcookie ("MyLoginPage", "", time() - 3600); unset($_COOKIE['MyLoginPage']); header("Location: ./admin.php"); exit; }} ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Admin</title> <meta name="robots" content="noindex,nofollow"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="stylesheet" href="/css/css_style.css" type="text/css" charset="utf-8" /> </head> <body> <div style="height:100%; width:800px; margin:0 auto;"> <div style="height:25%;"></div> <div id="toplogo" style="margin-bottom:20px;"></div> <div id="head"> <?php echo "$thisPage"; ?> </div> <div id="info"> <?php if (isset($_POST['submit'])){ if ($password != $userInfo[$userName] || empty($password)) { echo '<div id="dataPass">The Username and/or Password you entered was incorrect</div>'; } elseif ($password == $userInfo[$userName]) { setcookie('MyLoginPage', md5($randomString1.$password.$randomString2)); header("Location: ./"); exit; } else { echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>"; } } ?> <?php if (isset($_COOKIE['MyLoginPage'])) {echo 'You are logged in';}?> <form action="#" method="post"><fieldset style="text-align:center;"> <legend>Admin Login</legend> <table style="margin:0 auto"><tr><td><label>Username:</label></td> <td><input type="text" name="name" id="name" /></td></tr> <tr><td><label>Password:</label></td> <td><input type="password" name="pass" id="pass" /></td></tr> <tr><td></td><td><input type="submit" name="submit" id="submit" value="Login" /></td></tr></table> </fieldset></form></div> </div> </body> </html> error: so im asuming ive arranged the code wrongly, can you suggest where? thanks
  6. -- correction: it still doesntwork properly, it seem'd to work once i changed the above, but its just doing the same as before now
  7. oh, seem'd to fix this problem by changing this: <?php $userName = $_POST['name']; $password = $_POST['pass']; $userInfo = array('user1'=>'pass1', 'user2'=>'pass2'); $randomString1 = "xu5rac9Erub7KAPh"; $randomString2 = "P327efA5ujadRAfa"; ?> <?php if ($_GET["logout"] == "true"){ setcookie ("MyLoginPage", "", time() - 3600); unset($_COOKIE['MyLoginPage']); header("Location: ./admin.php"); exit; } ?> to this: <?php $userName = $_POST['name']; $password = $_POST['pass']; $userInfo = array('user1'=>'pass1', 'user2'=>'pass2'); $randomString1 = "xu5rac9Erub7KAPh"; $randomString2 = "P327efA5ujadRAfa"; if ($_GET["logout"] == "true"){ setcookie ("MyLoginPage", "", time() - 3600); unset($_COOKIE['MyLoginPage']); header("Location: ./admin.php"); exit; } ?> can anyone explain to me why it didnt like me ending then starting a new php statment?
  8. hey guys, the following code is for an admin login screen im creating, but currently, when i try to login i get... here is the full code.... <?php $thisPage='Admin Login';?> <?php $userName = $_POST['name']; $password = $_POST['pass']; $userInfo = array('user1'=>'pass1', 'user2'=>'pass2'); $randomString1 = "xu5rac9Erub7KAPh"; $randomString2 = "P327efA5ujadRAfa"; ?> <?php if ($_GET["logout"] == "true"){ setcookie ("MyLoginPage", "", time() - 3600); unset($_COOKIE['MyLoginPage']); header("Location: ./admin.php"); exit; } ?> <?php if (isset($_POST['submit'])){ if ($password != $userInfo[$userName] || empty($password)) { echo '<div id="dataPass">The Username and/or Password you entered was incorrect</div>'; } elseif ($password == $userInfo[$userName]) { setcookie('MyLoginPage', md5($randomString1.$password.$randomString2)); header("Location: ./"); exit; } else { echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>"; } } ?> <?php if (isset($_COOKIE['MyLoginPage'])) {echo 'You are logged in';}?> <form action="#" method="post"><fieldset style="text-align:center;"> <legend>Admin Login</legend> <table style="margin:0 auto"><tr><td><label>Username:</label></td> <td><input type="text" name="name" id="name" /></td></tr> <tr><td><label>Password:</label></td> <td><input type="password" name="pass" id="pass" /></td></tr> <tr><td></td><td><input type="submit" name="submit" id="submit" value="Login" /></td></tr></table> </fieldset></form> can anyone suggest why this is happening? thanks
  9. got it working, realised i didnt need "in_array($userName, $userInfo) && " so now its just if ($password == $userInfo[$userName]) { setcookie('MyLoginPage', md5($randomString1.$_POST['pass'].$randomString2)); header("Location: ./"); exit; }
  10. hey guys, the following code is supposed to set a cookie once a matching user name and password has been entered (from array), but it doesn’t currently recognise a matching set: <?php $userName = $_POST['name']; $password = $_POST['pass']; $userInfo = array('user1'=>'pass1', 'user2'=>'pass2'); $randomString1 = "xu5rac9Erub7KAPh"; $randomString2 = "P327efA5ujadRAfa"; if (isset($_POST['submit'])){ if (in_array($userName, $userInfo) && $password == $userInfo[$userName]) { setcookie('MyLoginPage', md5($randomString1.$_POST['pass'].$randomString2)); header("Location: ./"); exit; } else { echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>"; } } echo '<form action="#" method="post"><fieldset> <legend>Admin Login</legend> <label><input type="text" name="name" id="name" /> Name</label><br /> <label><input type="password" name="pass" id="pass" /> Password</label><br /> <input type="submit" name="submit" id="submit" value="Login" /> </fieldset></form>'; ?> can anyone help with this? thanks
  11. thanks for the help guys
  12. hey guys, how would i use OR to say NOT equal to 'value01' OR 'value02' within an IF statment this is what i have so far which doesnt currently work: if ($_SESSION['trackBrowsing'] != "value01" || "value02"){ thanks
  13. with me having a Dynamic IP, doing what you suggested wouldnt always work as my IP may change at times, but i could go with a page for creating a session based on the url like you said in your previous post (sorry if thats what you where getting at in the first place, i just re-read your previous post, dont think i read i correctly first time) thanks again Desmond
  14. thanks for the suggestion Desmond, that way may be a little tricky to impliment with my pages though as i already use sessions on some pages and rewritten URLs, so it would take quite a bit of re-coding. thanks again for the post though
  15. well my IP seems to completly change most days (every time my router is reset); and i havnt ever seen anyone with the same IP as one which i have had in a log could this code be used when i tested it on my local host, it gave my PC name, is this what i would also get once it was added to the site online?
  16. hey guys, is there anyway in which i can identify my PC using PHP so that i can exclude myself from my log files on my website when testing. i have a Dynamic IP address therefore i cannot use that to identify it. thanks
  17. thanks ignace, i hadnt heard of 'HTTP_ACCEPT_LANGUAGE' before, just replaced the 'HTTP_USER_AGENT' for it and it works perfectly now (with the extra spaces removed which i added before the language codes) thanks again (:
  18. --UPDATE-- i added a space before every language code, (eg: 'English (United Kingdom)' => ' en-gb', 'English (United States)' => ' en-us',) which made it work fine in Chrome and Safari as usually with all useragents there will be a single space before the language code to seperate it from the previous part of the useragent string. my problem is now that IE doesnt show the correct language, it shows 'Malay - ms', but then i had a look at my useragent string for IE, and i dont actually see any language code within it anyway so is it even possible to find the user language code through IE?
  19. hey guys, within the site logger i created for my site, i have a piece of code which is supposed to use the Useragent to find the users prefared language, this works fine in Firefox, IE, Opera, but not in Safari or Chrome. this is the code: <?php $languageList = array ( 'Afrikaans' => 'af', 'Albanian' => 'sq', 'Arabic (Algeria)' => 'ar-dz', 'Arabic (Bahrain)' => 'ar-bh', 'Arabic (Egypt)' => 'ar-eg', 'Arabic (Iraq)' => 'ar-iq', 'Arabic (Jordan)' => 'ar-jo', 'Arabic (Kuwait)' => 'ar-kw', 'Arabic (Lebanon)' => 'ar-lb', 'Arabic (libya)' => 'ar-ly', 'Arabic (Morocco)' => 'ar-ma', 'Arabic (Oman)' => 'ar-om', 'Arabic (Qatar)' => 'ar-qa', 'Arabic (Saudi Arabia)' => 'ar-sa', 'Arabic (Syria)' => 'ar-sy', 'Arabic (Tunisia)' => 'ar-tn', 'Arabic (U.A.E.)' => 'ar-ae', 'Arabic (Yemen)' => 'ar-ye', 'Arabic' => 'ar', 'Armenian' => 'hy', 'Assamese' => 'as', 'Azeri' => 'az', 'Basque' => 'eu', 'Belarusian' => 'be', 'Bengali' => 'bn', 'Bulgarian' => 'bg', 'Catalan' => 'ca', 'Chinese (China)' => 'zh-cn', 'Chinese (Hong Kong SAR)' => 'zh-hk', 'Chinese (Macau SAR)' => 'zh-mo', 'Chinese (Singapore)' => 'zh-sg', 'Chinese (Taiwan)' => 'zh-tw', 'Chinese' => 'zh', 'Croatian' => 'hr', 'Czech' => 'cs', 'Danish' => 'da', 'Divehi' => 'div', 'Dutch (Belgium)' => 'nl-be', 'Dutch (Netherlands)' => 'nl', 'English (Australia)' => 'en-au', 'English (Belize)' => 'en-bz', 'English (Canada)' => 'en-ca', 'English (Ireland)' => 'en-ie', 'English (Jamaica)' => 'en-jm', 'English (New Zealand)' => 'en-nz', 'English (Philippines)' => 'en-ph', 'English (South Africa)' => 'en-za', 'English (Trinidad)' => 'en-tt', 'English (United Kingdom)' => 'en-gb', 'English (United States)' => 'en-US', 'English (Zimbabwe)' => 'en-zw', 'English' => 'en', 'English (United States)' => 'us', 'Estonian' => 'et', 'Faeroese' => 'fo', 'Farsi' => 'fa', 'Finnish' => 'fi', 'French (Belgium)' => 'fr-be', 'French (Canada)' => 'fr-ca', 'French (Luxembourg)' => 'fr-lu', 'French (Monaco)' => 'fr-mc', 'French (Switzerland)' => 'fr-ch', 'French (France)' => 'fr', 'FYRO Macedonian' => 'mk', 'Gaelic' => 'gd', 'Georgian' => 'ka', 'German (Austria)' => 'de-at', 'German (Liechtenstein)' => 'de-li', 'German (Luxembourg)' => 'de-lu', 'German (Switzerland)' => 'de-ch', 'German (Germany)' => 'de', 'Greek' => 'el', 'Gujarati' => 'gu', 'Hebrew' => 'he', 'Hindi' => 'hi', 'Hungarian' => 'hu', 'Icelandic' => 'is', 'Indonesian' => 'id', 'Italian (Switzerland)' => 'it-ch', 'Italian (Italy)' => 'it', 'Japanese' => 'ja', 'Kannada' => 'kn', 'Kazakh' => 'kk', 'Konkani' => 'kok', 'Korean' => 'ko', 'Kyrgyz' => 'kz', 'Latvian' => 'lv', 'Lithuanian' => 'lt', 'Malay' => 'ms', 'Malayalam' => 'ml', 'Maltese' => 'mt', 'Marathi' => 'mr', 'Mongolian (Cyrillic)' => 'mn', 'Nepali (India)' => 'ne', 'Norwegian (Bokmal)' => 'nb-no', 'Norwegian (Nynorsk)' => 'nn-no', 'Norwegian (Bokmal)' => 'no', 'Oriya' => 'or', 'Polish' => 'pl', 'Portuguese (Brazil)' => 'pt-br', 'Portuguese (Portugal)' => 'pt', 'Punjabi' => 'pa', 'Rhaeto-Romanic' => 'rm', 'Romanian (Moldova)' => 'ro-md', 'Romanian' => 'ro', 'Russian (Moldova)' => 'ru-md', 'Russian' => 'ru', 'Sanskrit' => 'sa', 'Serbian' => 'sr', 'Slovak' => 'sk', 'Slovenian' => 'ls', 'Sorbian' => 'sb', 'Spanish (Argentina)' => 'es-ar', 'Spanish (Bolivia)' => 'es-bo', 'Spanish (Chile)' => 'es-cl', 'Spanish (Colombia)' => 'es-co', 'Spanish (Costa Rica)' => 'es-cr', 'Spanish (Dominican Republic)' => 'es-do', 'Spanish (Ecuador)' => 'es-ec', 'Spanish (El Salvador)' => 'es-sv', 'Spanish (Guatemala)' => 'es-gt', 'Spanish (Honduras)' => 'es-hn', 'Spanish (Mexico)' => 'es-mx', 'Spanish (Nicaragua)' => 'es-ni', 'Spanish (Panama)' => 'es-pa', 'Spanish (Paraguay)' => 'es-py', 'Spanish (Peru)' => 'es-pe', 'Spanish (Puerto Rico)' => 'es-pr', 'Spanish (United States)' => 'es-us', 'Spanish (Uruguay)' => 'es-uy', 'Spanish (Venezuela)' => 'es-ve', 'Spanish (Traditional Sort)' => 'es', 'Sutu' => 'sx', 'Swahili' => 'sw', 'Swedish (Finland)' => 'sv-fi', 'Swedish' => 'sv', 'Syriac' => 'syr', 'Tamil' => 'ta', 'Tatar' => 'tt', 'Telugu' => 'te', 'Thai' => 'th', 'Tsonga' => 'ts', 'Tswana' => 'tn', 'Turkish' => 'tr', 'Ukrainian' => 'uk', 'Urdu' => 'ur', 'Uzbek' => 'uz', 'Vietnamese' => 'vi', 'Xhosa' => 'xh', 'Yiddish' => 'yi', 'Zulu' => 'zu', 'Unknown Language' => '()' ); foreach($languageList as $CurrLanguage=>$Match) { if (eregi($Match, $_SERVER['HTTP_USER_AGENT'])) { break; } } ?> the useragent strings i have go as follows: from those useragents, its comming back with my language code being 'af - Afrikaans' before grabbing the 'en-US', all i can think of is that the array is being matched with the 'af' from 'safari' first; but as thats at the end of the string, shouldnt it find the 'en-US' first? can anyone please help with this? thanks guys
  20. ahh, problem solved, for some reason, it was also adding files within the same directory which didnt have the .txt ext, so i changed this line "$logFiles = glob("*.txt", GLOB_NOSORT);" to "$logFiles = glob("logFile *.txt", GLOB_NOSORT);" thanks for your help Buddski
  21. hmm, i got a total of 75 using the same example you did below
  22. hi Buddski, your code seems to random vaues close to the correct value, but i arent sure whats going wrong. for example
  23. ---correction, it only outputs the value of the last file found, rarther than all the values added together
  24. thanks again crabfinger, but that code seems to just output a value of "1" no matter what. =/ any ideas guys?
  25. hey, thanks for anyother post crabfinger, i tried your code, and i got this error message "Fatal error: Unsupported operand types in E:\xampp\htdocs\logs\index.php on line 143 ", which is refaring to this line: "$logHitsT = $logHitsT + $value;". and just before you posted, the code which i manged to do was just: $logFiles = glob("*.txt", GLOB_NOSORT); for ($i=0; $i<count($logFiles); $i++) { $logFile = $logFiles[$i]; sscanf($logFile, '%*[^[][%[^]]', $hits); echo' '.$hits.''; } which with logFiles such as outputs: 20 15 10 but im not sure how to make it add these values together..? any ideas for either code? thanks guys
×
×
  • 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.