
scottish_jason
Members-
Posts
24 -
Joined
-
Last visited
Everything posted by scottish_jason
-
oh damnit, im very sorry.... the fact I didnt sleep last night pretty much says it all! thanks again!
-
Thankyou very much for the reply but im afraid with that code the page now fails to load, not really sure why as im not really adept with xpath or XML in general to be honest, hehe I have been removing parts to try and find out which line is causing the problem and I cant even get the page to load with only this part in foreach ($discovery->xpath("//host[status/@state='up']") as $ndiscovery) { } endforeach;
-
The XML in question is there on the post, the full XML file is way too large to post up. edit: or if you are asking what the XML data actually is then its output from a linux program called nmap... it is a network discovery application showing ip addresses, mac addresses, open ports etc etc.
-
Hi everyone, I was wondering if anybody could help me with some XML parsing.... I have managed to parse most of the XML into variables but im struggling with one of the nodes where it is a second child : node[1] here is a snippet of the tree ($ndiscovery) SimpleXMLElement Object ( [@attributes] => Array ( [starttime] => 1350215881 [endtime] => 1350215891 ) [status] => SimpleXMLElement Object ( [@attributes] => Array ( [state] => up [reason] => arp-response ) ) [address] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [addr] => 192.168.0.1 [addrtype] => ipv4 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [addr] => A0:21:B7:06:20:67 [addrtype] => mac ) ) ) and a snippet of my code to parse ( where the problem seems to arise ) $discovery = simplexml_load_file('discovery.xml') foreach ($discovery->host as $ndiscovery) if ($ndiscovery->status->attributes()->state == up) { $inum++; $ip[$ipnum]=$ndiscovery->address[0]->attributes()->addr; $mac[$ipnum]=$ndiscovery->address[1]->attributes()->addr; etc... etc... if I remove the $mac line everything is fine, but if I leave it in there it seems to stop the rest of the webpage executing (after the php code finishes) the $mac line does actually work for retrieving the node but it seems to stop the rest of the page executing, very confused at this point. I had to use the [1] because there are 2 node's that are named the same (addr) Anybody have any ideas? thanks very much
-
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
derwert, thanks again. I did read your post and your right, I probably should go down the XML route, thanks for reminding me of that output functionality. On the other hand though I had been working on the regular expression for quite a while and was mostly wanting to learn how you could do it with that method for future programming/regular expression needs, and also it was bugging me! hehe. But anyway, thanks for all the help. Im starting to understand regular expressions but will go down the XML route! -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
Hi derwert, thanks for the reply..... I have managed to get so far with this problem. I am able to get the information I need into array's but one problem now exists. When I do my nmap scan it does not return the mac address for my local machine, which means my IP and mac array's become out of sync because one of the mac addresses are not stored meaning the mac array is one number behind the ip array ( when it gets to the point where my local machine does not return the mac address ). This is what I have tried: $string = shell_exec ('sudo nmap -sP 192.168.0.0/24'); preg_match_all("/\d{1,3{\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $ip); preg_match_all("/((?:[0-9a-f]{2}[:-]{5}[0-9a-f]{2})/i", $string, $mac); print_r($ip); print_r($mac); I get the following arrays out. p.s. I have no idea why it prints the mac array out twice but I dont think that should be a problem. But anyway, as you can see im missing the mac address for 0.8 so my ip and mac arrays are out of sync ie. ip[2] does not refer to mac[2] Array ( [0] => Array ( [0] => 192.168.0.1 [1] => 192.168.0.2 [2] => 192.168.0.8 ) ) Array ( [0] => Array ( [0] => A0:21:B7:06:20:67 [1] => 00:01:29:A4:47:F2 ) [1] => Array ( [0] => A0:21:B7:06:20:67 [1] => 00:01:29:A4:47:F2 )i -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
What about parsing these bold sections into variables... The string can and will change though, depending upon how many host's nmap picks up ( 4 in this case ) and also like in this example the last mac address for 192.168.0.8 was not picked up, but I would need a blank entry for that array so that the ip and mac array numbers correspond. I dont expect an answer, im willing to research and try to figure things out for myself but pointing me in the right direction would be great. for example: $IP[0] = "192.168.0.1" $IP[1] = "192.168.0.2" $IP[2] = "192.168.0.4" $IP[3] = "192.168.0.8" $MAC[0] = "00:00:00:00:00:01" $MAC[1] = "00:00:00:00:00:02" $MAC[2] = "00:00:00:00:00:03" $MAC[3] = " " Starting Nmap 5.21 ( http://nmap.org ) at 2012-10-10 20:53 BST Nmap scan report for 192.168.0.1 Host is up (0.0055s latency). MAC Address: 00:00:00:00:00:01 (Unknown) Nmap scan report for 192.168.0.2 Host is up (0.00019s latency). MAC Address: 00:00:00:00:00:02 (DFI) Nmap scan report for 192.168.0.4 Host is up (0.0043s latency). MAC Address: 00:00:00:00:00:03 (Unknown) Nmap scan report for 192.168.0.8 Host is up. Nmap done: 256 IP addresses (4 hosts up) scanned in 5.37 seconds -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
yeah just thought of that, thanks alot -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
The only problem I have now is that some of the switches contain two -- characters such as " --state " and I seem to be having problems using the likes of : echo "$parsedarray[-state]"; -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
edit: got it thanks -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
yes I have managed to get the array printed out with the correct entries. Just need to call them in the appropriate table cells now. Thanks guys -
Parsing String Into Several Variables
scottish_jason replied to scottish_jason's topic in Regex Help
thanks very much for the reply, im not entirely sure how this code works but I will try it. Will this also work if the string has more switches? and I assume I just call these variables with $args[A] etc? -
hi guys, ive spent a good amount of time researching how to parse linux iptables rules into seperate variables so I can use each variable inside appropriate cells inside a table, but without any luck . For example, a possible string could be: $string = "-A INPUT -s 192.168.0.1 -p TCP -j DROP" I want to be able to put: "192.168.0.1" into a $source variable "TCP" into a $protocol variable "DROP" into a $jump variable I was thinking about doing an explode splitting each word up using the "space" and then doing if $explode[2] = "-s" then $source = $explode[3] type thing but I would have to check for each available switch on every array number (if you know what I mean). Is there a more efficient way of doing this?
-
hi guys, another little problem I am trying to display a list of information inserted into the database in DESC order, but only want to display 20 row's and then a section where the user can go back or forward a page on to the previous 20 or the next 20, if that makes any sense. I got it working to a certain extent by messing around with different things but it would not display the very last stuff on the 1st page but on the 2nd, or also with different code I had it display the newest additions on the first page but in reverse order. Here is my current code mysql_connect("localhost","forum","forum") or die(mysql_error()); mysql_select_db("forum") or die(mysql_error()); $genree = $_GET['genre']; $currentpage = $_GET['page']; $currentpage0 = ($currentpage - 1); $currentpage2 = ($currentpage + 1); $query = mysql_query("SELECT MAX(id) AS maximum FROM mixes"); list ($maxid1) = mysql_fetch_row($query); $maxid2 = (20*$currentpage); $maxid3 = $maxid2 - 20; if ($currentpage == 1) { $maxid2 = 20; $maxid3 = 0; } var_dump ($maxid3); var_dump ($maxid2); //query the db $getmixes = mysql_query("SELECT * FROM mixes WHERE genre='$genree' AND id >= '$maxid3' AND id <= '$maxid2' ORDER by id DESC") or die(mysql_query()); $i = 1; while ($row = mysql_fetch_assoc($getmixes)) { $mixtitle = $row['title']; $id = $row['id']; $poster = $row['poster']; $url = $row['url']; echo "<a href='$url'>$mixtitle"; echo "<br>"; if ($i >= 19) break; $i++; } $genree = $_GET['genre']; $currentpage = $_GET['page']; ?> <a href="http://localhost/mixes.php?genre=<?php echo $genree ?>&page=<?php echo $currentpage0 ?>"><</a><?php echo " page $currentpage ";?> <a href="http://localhost/mixes.php?genre=<?php echo $genree ?>&page=<?php echo $currentpage2 ?>">></a><?php; so what the above currently does is on page 1 displays ID 0-20, page 2 displays ID 20-40 which is kind of right but not quite, I want it display the last ID at the top of page 1 and the very first addition on the last page at the bottom. I was playing around with finding the max ID in the database and then attempting to work out which id chunk that it should output but that got messy. I know im probably doing this the wrong way but im new to PHP and still trying to learn the better methods of doing such things, what would be a good way to do what I require? thanks for your time and help!
-
and then quoting my code? You never mentioned isset()? And you are wrong, no, Booleans are True/False, wether a variable is set or not is entirely different, a variable with no data can return false. Thus, in fact, the only way to check if a variable exists (post data with no data), use isset(), as i said before. Would like to know .. what are you on about? -------------- Jason; Maybe you need to rethink the general structure of your script. It should be something like: If(Session Exists){ // Continue to load page normally }else{ // Show log in page } To make it easier to understand you can use a function checkbbsession() that you make yourself that will check wether the person is logged in or not. and should return true or false respectively. You should also indent your code to make it easier to read and debug mistakes. Also, Oni-Kun, the Session if statement is already outside of the POST check statement? -CB- -CB- Thanks for the help at the moment the page seems to be displaying properly, but I just cant get logged in due to this wrong password thing, once that works I will be able to see if the welcome is displayed properly and if not I will change the structure as you recommended It seems like the hash check function supplied with phpbb is not comparing the hashes properly? When i type in a wrong username it says user does not exist, and when I type in the correct password it says wrong password
-
ok I took out the session check from the loop and its now under it on its own but I am still getting the wrong password error, I dont understand why because its a pre-made phpbb function and the password im putting in is correct
-
oh I see, should I just take out that line? It's not even getting to that line anyway.... because the the check is not true for the password hash compare and its outputting wrong password, i dont know why because its a phpbb function already written
-
But I dont want the log in box to display if they are logged in, only want it to say welcome *user* the code does now run... but im getting a wrong password error even though the password is correct
-
oh sorry I had the wrong database name, doh! it is now saying incorrect password when it is infact the correct password :s
-
This just doesnt make sense, It means both arrays (SESSION and POST) are empty and that some other array is populated with what you want, but you dint echo or print any other array, so youve either typed the result in your self incorrectly or you echoed something else. Assuming the variables shown are found in the POST array: as i said before, use: if(isset($_POST['login'])) (check wether its set), i beleive the default behaviour for if($variable) checks wether $variable is true or false (or 0 or 1 etc). Also, the SESSION variable is empty, what is it supposed to have? phpBB's sessions? use print_r($_SESSION) on a phpBB file somewhere and check the sessions (what they are meant to be), then you can work out what you can do to keep them from page to page. -CB- yes I am sorry I never copied and pasted that section, I just typed it in as im working on a virtual machine and couldnt paste between and I typed it wrong... sorry the username & password are inside the 2nd array (post)
-
actually it is now saying Could not connect to database, strange though because its connecting to the database for my news section with the same username and password
-
this is what I get with that code being used Array ( ) 1 Array ( ) 1 [username] => user [password] => password [login] =>
-
that section is only a snippet of my index.php page, I have this at the top of my index.php <?php ob_start("ob_gzhandler"); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
-
Hi, I cant for the life of me work out why this code is failing to work, i I have an if (isset($_SESSION['username']) at the bottom section to check if somebody is logged in, if they are not display the log in box then I have if ($_POST['login']) below which is supposed to execute once I press the log in button but it doesnt seem to as my test "hello" doesnt seem to appear, when I click on the log in button the page just refreshes and the log in box still stays visible, any suggestions why this is not working? <h2>Log in</h2><br> <?php if ($_POST['login']) { echo "hello"; //connect $error = 'Could not connect to the database'; mysql_connect('localhost','forum','forum') or die($error); mysql_select_db('phpbb') or die($error); //include functions.php phpbb script require 'forum/includes/functions.php'; //get form data $username = addslashes(strip_tags(strtolower($_POST['username']))); $password = addslashes(strip_tags($_POST['password'])); if (!$username||!$password) echo "Please enter a username and password<p />"; else { //find username $find = mysql_query("SELECT * FROM phpbb_users WHERE username_clean='$username'"); if (mysql_num_rows($find)==0) echo "Username not found<p />"; else { while ($find_row = mysql_fetch_assoc($find)) { // grab password hash for user $password_hash = $find_row['user_password']; } $check = phpbb_check_hash($password, $password_hash); if ($check==FALSE) echo "Incorrect password<p />"; else if ($check==TRUE) { $_SESSION['username']=$username; header("Location: index.php"); exit(); } } } } if (isset($_SESSION['username'])) { echo Welcome; } else { echo '<form action="index.php" method="POST"> <input type="text" name="username" size=18> <br><input type="password" name="password" size=18> <br><input type="submit" name="login" value"Log in" size=10>'; } ?>