PHP - Urgent Help Needed With Arrays
I have an array and I'd like to find the most popular value in the array. example.
$arr = array(1,1,1,1,2,2,3,4,5,5,5,5,5,5,5,3,4,198,10293,1,2); I would like only display 5 please. Similar Tutorialshi for all am installing php security user mangement but i got some errors during install am using xampp 1.7.7 for windows but when i runed the script for the first time i got this message Warning: require_once(C:/xampp/htdocs/xampp/psumthemes/shared.js.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\xampp\psum\index.php on line 20Fatal error: require_once() [function.require]: Failed opening required 'C:/xampp/htdocs/xampp/psumthemes/shared.js.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\xampp\psum\index.php on line 20() any ideas please my document root is C:/xampp/htdocs I have a shopping cart on my website with some minor errors. When you refresh the page it adds an extra quantity to the item when it shouldn't. Any help the code is below. $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; If you are a PHP expert, then I really your help. I have a question regarding PHP sessions and their security. So here is my story ... I created a login script (login.php) for my website. When a user goes to the login.php page, they see a login form that they must fill with their username and password to login to the members' area and view their profile, etc. On that login page, when the user enters their username and password and then clicks the "Login" button, my script filters the data, sends MySQL query and checks if the login is valid. If the login is NOT valid, then they get a "Login Failed" message. If the login is valid, I register their username and the password in sessions and redirect them to the members.php page. Here is some of my code for my login.php page after mysql confirms the login is valid <?php $query = mysql_query('SELECT * FROM `users` WHERE username='$user' AND password='$pass'"); $numRows = mysql_num_rows($query); if ( $numRows ) { // login is valid $_SESSION['username'] = $user; $_SESSION['pass'] = $pass; // redirect user to members area header('Location: /members.php'); } else { // login is invalid echo "Login failed"; } ?> My question is ... is this login script secured? I mean, I am not generating any session id or any cookie. I am just storing the username and the password in two session variables and those are the things that i will use to display the user's profile, etc. Can attackers attack this script? Is this secured or is there any other way I can make it stronger? Hi All, My goal is to process all redirects serverside and simply return the user to the 'final' URL. Here's my function to get the final URL: PHP Code: function get_final_url($url){ global $final_host; $redirects = get_all_redirects($url); if (count($redirects)>0){ $final_url = array_pop($redirects); if(substr($final_url,0,7) != 'http://' && !empty($final_host)) { $final_url = 'http://'.$final_host.$final_url; } return $final_url; } else { return $url; } Here's the cURL execution: $ch2 = curl_init(); curl_setopt($ch2,CURLOPT_URL,$url); curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch2,CURLOPT_POST,''); curl_setopt($ch2,CURLOPT_POSTFIELDS,''); curl_exec($ch2); curl_close($ch2); For some reason, this works no problem, posts any data over to the URLs serverside, redirects serverside, and passes the client to the final URL, with none of the redirection displayed via HTTPWatch or any similar debug utility. Sometimes, however, it does show phases of redirection. Any insight into what I might be doing incorrectly? Thanks SO much in advance. E I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? hI for all Am developping a script that allow to each user (seperatly ) upload or download his files and list all files in categories (such music or photos...) but i can 't achieve that the main problem is to upload files to server and store them in data base also i have to list for each user his files seperatly when he log in any idea please (I am not an expert or even a begineer at PHP, so sorry if none of this makes sense) Right ok, I have an invitation form built and tested working correctly between a php page and a mysql database and got the mail function to work but now the mail function is throwing all emails into the junk mail folder of outlook. The user of the invitation form has to enter a valid email address (the form has its own validation for each textbox and email has been set to required email address). So I have been asked to set up a mailto instead of using the mail function (dont ask me why...) And I cant, for the life of me, figure out how to get this to work. What I have thought of so far is: Index.html (Invitation page) V sendinvitation.php (previously the page with the mail function) now includes a confirmation of the data being sent to the database and a button to go to the next php V sendmail.php (I want this to be able to get the data from the database and then open up the users email client and pre populate the email with the body text) Is this even possible? If not, is there a reason why the email keeps getting thrown into the junk mail. Please, any help would be most appreciated! EDIT: Let me explain a bit more, just re-read over and its very brief (this probably will be too) I want to invitation form to submit the users data to my database in mysql, then when the form as been submitted, to be able to then grab the data and pre populate an email using variables that are in the php linked to the database (Im guess the php would go from POST to GET?) I am creating a member site and I need help with coding the database. Here go the code Code: [Select] <?php function connect(){ $DB_USER = "root"; $DB_PASSWORD = ""; $DB_HOST = "localhost"; $dbc = mysql_connect ($DB_HOST, $DB_USER, $DB_PASSWORD) or $error = mysql_error(); mysql_select_db("membership") or $error = mysql_error(); mysql_query("SET NAMES `utf8`") or $error = mysql_error(); if($error){echo "<!-- $error -->";}} function disconnect_data(){ @mysql_close($dbc); @mysql_close(); } ?>I am suppose to fill it in with my database info but idk what to fill in! help me please! where do i enter the info! <?php $possibles[]; $alreadychosen[]; for ($i = 0; $i<20;$i++) $possibles =i+1; for (int $i = 0; $i<8; $i++) { $boolean= false; $randIndex=0; do { $randIndex = rand(1,20); for ($j = 0; $j< $i && !$hasInt; $j++) { if ($possibles[$randIndex] == $alreadyChosen[$j]) { $hasInt = true; } } } while ($hasInt); { $alreadyChosen = $possibles[randIndex]; echo($alreadyChosen); } for ($i = 0; $i<8;$i++) { if($alreadyChosen<10) { echo ('<a href="/mp/info130'+$i+'.htm"><img src="/mp/p130'+$i+'-1.jpg" height=180 width=120 align=left hspace=0 vspace=2 border=0 class=TopImages></a>'); } else if($alreadyChosen>10) { echo ('<a href="/mp/info13'+$i+'.htm"><img src="/mp/p13'+$i+'-1.jpg" height=180 width=120 align=left hspace=0 vspace=2 border=0 class=TopImages></a>'); it should select 8 images out of 20 but don't repeat please Please help me with this: with this code i have only fetched out the subjects and i need to fetch out value for the following too from the database 1. GRADE 2. Contious Assessment: 3. Exam Scores: 4. Exam Scores 5. Weighted Average: 6. Last Term Cummulative: 7. Cumulative (c+d)/2: 8. Comment: but now i can only get the foreach work for subject alone.. $l=mysql_query("SELECT * FROM result WHERE school_id='$id' AND student_reg_id='$st'") or die (mysql_error()); if (mysql_num_rows($l) > 0) { while ($row = mysql_fetch_array($l)) {// $pwrlist[$row['ajax_result_id']]=$row['subject']; //$ } $numpwr = count($pwrlist); $thresh = 3; $maxcols = 18; $cols = min($maxcols, (ceil(count($pwrlist)/$thresh))); $percol = ceil(count($pwrlist)/$cols); $powerchk = ''; $i = 0; foreach ($pwrlist as $id => $pwr) { if (($i>0) && ($i%$percol == 0)) { $powerchk .= "</td>\n<td valign='top'>";//echo "<br>"; } $powerchk .= " <table width='280px' class='hovertable'> <tr> <td width='251px' height='34' align='left' valign='middle' bgcolor='#D6DFEB'><span class='style19'><font size=2px>$pwr</font></span></td> <td width='19px' align='left' valign='middle' bgcolor='#D6DFEB'><span class='style1'>GRADE:</span></td> <td width='20px' align='left' valign='middle' bgcolor='#FFFFFF'><span class='style13'>B3</span></td> </tr> <tr> <td height='34' colspan='3' align='left' valign='top' bgcolor='#FFFFFF'><span class='style20'>» (a) Contious Assessment: 80<br /> » (b) Exam Scores: 90<br /> » (c) Weighted Average: 168<br /> » (d) Last Term Cummulative: 78<br /> » (e) Cumulative (c+d)/2: 123 </span></td> </tr> <tr> <td height='20' colspan='3' align='left' valign='top' bgcolor='#FFFFFF'><span class='style17'>Comment: His is a responsible boy</span></td> </tr> </table><br>\n"; $i++; } } This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321874.0 Hello dear friends , I'm under attack huge attack from spam bots and i need your help 1) i've a form with input text and input submit 2) no way to add html cause using js banned any < or > ..ect 3) the spam attack now post html code but it stored into database after automatically < and > removed as i mention in (2) okay add to your note i can't add captcha cuase my website for kids Now please allow me to explain this idea and let me know if it ture or there is another way else more simple 1) i will add hidden input with value shows "IP Number Of Poster" 2) by that way i will know the IP of the spammer 3) i will use php and mysql to create database table and store the IPs of spamming i collect so that when that spammer hit my website again , will not be able to view input form. What do you think ! is it right or bad solution or is there any any way the bad idea is that spam is not sure human cause it is stupid and post something meaningless and not ture and fake urls like this Code: [Select] theuzgfnpbmi, [url=http://gdtuaemvkpif.com/]gdtuaemvkpif[/url], [link=http://rsxtnszcpceq.com/]rsxtnszcpceq[/link], http://awpfgwtvqkdm.com/" theuzgfnpbmi, [url=http://gdtuaemvkpif.com/]gdtuaemvkpif[/url], [link=http://rsxtnszcpceq.com/]rsxtnszcpceq[/link], http://awpfgwtvqkdm.com/" please help if you have any suggestion or method how to stop such spammers thank you so much hello guys I need little help bro, I want to make application in which i want this look, I am from a company where we have over 12 companies license and all are those is renew after every year. so i want to make a application which will inform us 1 month before expireing their license. Mean if any company license is expire on 12 June, our application give us notification on 12 May. Could you please help me how can I do this? Thanks and regards Basically, I have a series of radio buttons (wanted checkboxes) were people select either Latte, Mocha or Cappuccino. I have included a hidden field for a price and using that to bring in the prices and add them up. Code: [Select] <label for"Latte">Latte <br />€ 2.15</label> <br /> <input type="radio" name="coffee" id="Latte" value="Latte"> <input name="LattePrice" type="hidden" value="2.15"> </p> <p> <label>Mocha <br /> € 2.25</label> <br /> <input type="radio" name="coffee" id="Mocha" value="Mocha"> <input name="MochaPrice" type="hidden" value="2.25"> </p> <p> <label>Cappucino <br /> €2.35</label> <br /> <input type="radio" name="coffee" id="Cappucino" value="Cappucino"> <input name="CappPrice" type="hidden" value="2.35"> </p> The next section they choose the size they want Small, Medium or Large. Code: [Select] <p> <label for="latteSmall">Small </label><img src="images/latte.png" alt="Small Latte" width="36" height="36"> <input type="radio" name="size" id="LatteSmall" value="Small"> <input name="SizePrice" type="hidden" value="0.00"> </p> <p> <label for="LatteMedium">Medium <br /> + € 0.25 </label> <img src="images/latte.png" alt="Medium Latte" width="42" height="42"> <input type="radio" name="size" id="LatteMedium" value="Medium"> <input name="SizePrice" type="hidden" value="0.25"> </p> <p> <label for="latteLarge">Large <br /> + € 0.45 </label> <img src="images/latte.png" alt="Large Latte" width="49" height="49"> <input type="radio" name="size" id="LatteLarge" value="Large"> <input name="SizePrice" type="hidden" value="0.45"> </p> I chose radio buttons to limit the users choice to one coffee and one size to make life easier (for myself). Ideally I wanted to use checkboxes but I could not get the php working. So basically, If Latte is selected echo it and the size. Code: [Select] echo "Hi ". $name. ", " . "here is your order:" . "<br /> <br />"; echo "<strong>" . "Coffee:" . "</strong>" . "<br />" . $size . " " . $coffee . "<br /><br />"; That works fine but the pricing is coming out wrong as I was using: Code: [Select] if ($coffee == "Latte") { $TotalCoffeePrice = $LattePrice + $SizePrice; echo "€ " . $TotalCoffeePrice . "<br /> <br />"; } elseif ($coffee == "Mocha") { $TotalCoffeePrice = $MochaPrice + $SizePrice; echo "€ " . $TotalCoffeePrice . "<br /> <br />"; } elseif ($coffee == "Cappucino") { $TotalCoffeePrice = $CappPrice + $SizePrice; echo "€ " . $TotalCoffeePrice . "<br /> <br />"; } What is happening here is if you select Latte and then Small it was adding Small, Medium and Large prices to the Latte. So instead of 2.15 I was getting 2.80 or something like that. Obviously when I recognised this I tried an array but that just went arseways!! Also, at the end of the php I was hoping to total up everything that they chose with: Code: [Select] $TotalPrice = ($TotalCoffeePrice + $SizePrice + $MuffinPrice + $SamboPrice); echo "<strong>" . "Total Price:" . "</strong>" . "<br />" . "€ " .$TotalPrice . "<br /><br />"; However, this was giving a total of 9.80 even when nothing was selected! What is all dependent on PHP?
I mean lets say I removed echo from phps source code.
Then I add function my_echo() which is the exact same code basically, what all would I need to update to allow my_echo() to be implemented correctly
Obviously I would need to modify every one of my php scripts on my webserver to replace echo with my_echo, but is there anything else?
I know i could just append my_echo to phps source, or modify the echo function itself, but this is conceptually and thats not the actual process I'm looking for right now.
Any insight would be greatly appreciated!
hey ive got a page that lists a users bank accounts...when the user chooses to update an account it goes to a new page where they can edit the details...when it goes to this new page it takes the user's ID and the account ID with it in the URL (http://localhost/oswp/bank/updateaccounts.php?id=34&cid=1) so i know these variables are correctly being transferred. now when the user has made their changes and clicked the update button it should update the database and then re-locate back to the original page listing all accounts...to get back to this page and show the correct accounts for that user i thaught i needed to take the ID from the URL...give it a variable...and use it in the URL back to the original page. so for example the variable and update sql and re-locate code would look like this. $cid = $_GET['cid']; //updating the table $result=mysql_query("UPDATE accounts SET accno='$accno', pin='$pin', type='$type', name='$balance', balance='$balance', active='$active' WHERE accid=$id"); header("location:accounts.php?id=$cid"); however currently when the user clicks update and it tries to relocate back to the original page its not getting the variable in the URL. (http://localhost/oswp/bank/accounts.php?id=) and im getting the errors: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\uni\oswp\assignment\bank\accounts.php on line 26 's bank accounts Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\uni\oswp\assignment\bank\accounts.php on line 30 basically saying its expected a number up in the URL and its not finding one...but i dont know why...any ideas please its quite urgent. here is the relevant code for this section: Accounts.php: <a href="adminlogout.php">Logout</a><br /> <?php $id = $_GET['id']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); $result = mysql_query("SELECT * FROM customer WHERE cusid=$id"); $row2 = mysql_fetch_array($result); echo $row2['name'] . "'s bank accounts" . "<br><br>"; $result2 = mysql_query("SELECT * FROM accounts WHERE cusid=$id"); echo "<form method='post' action='accounts.php?id=$id'>"; while($row = mysql_fetch_array($result2)) { echo "<input type='hidden' value='$row[accid]' name='accid'>" . $row['accno'] . $row['name'] . $row['type'] . $row['balance'] . $row['active'] . "<a href='updateaccount.php?id=$row[accid]&cid=$id'>Update</a>" . "<br>"; } echo "</form>"; ?> updateaccounts.php: $id = $_GET['id']; $cid = $_GET['cid']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); if(isset($_POST['update'])) { $accno=$_POST['accno']; $pin=$_POST['pin']; $type=$_POST['type']; $name=$_POST['name']; $balance=$_POST['balance']; $active=$_POST['active']; // checking empty fields //if item field is empty if(empty($accno)) { echo "<font color='red'>account number field is empty.</font><br/>"; } elseif(empty($pin)) { echo "<font color='red'>pin field is empty.</font><br/>"; } elseif(empty($type)) { echo "<font color='red'>account type field is empty.</font><br/>"; } elseif(empty($name)) { echo "<font color='red'>account name field is empty.</font><br/>"; } elseif(empty($balance)) { echo "<font color='red'>balance field is empty.</font><br/>"; } elseif(empty($active)) { echo "<font color='red'>active field is empty.</font><br/>"; } else { //updating the table $result=mysql_query("UPDATE accounts SET accno='$accno', pin='$pin', type='$type', name='$balance', balance='$balance', active='$active' WHERE accid=$id"); header("location:accounts.php?id=$cid"); } } |