PHP - Cookie Priority With Common Names
If I have three files such as the following, and put session_start() in each, the session cookie will be domain: "mydomain.com" and path "/". As such, the session will be shared between all three files.
http://mydomain.com/index.php http://mydomain.com/folder1/index.php http://mydomain.com/folder1/folder2/index.phpIf I want the cookie to be unique to each file, then it seems I have several options. I could use session_name() to give the cookie a unique name for each file. I could use session_set_cookie_params() to set a unique path for each (/, /folder1, /folder1/folder2), however, the index files in the children directories will also be sent the root directories session cookie, right? Will this cause problems? Should both approaches be implemented? Or is there another approach? Thanks Similar TutorialsThe default PHP Session name on my webspace server is PHPSESSID. Does that mean that the session cookie will be called PHPSESSID? The reason i ask is that in a couple of places i can't use PHP to update the information in the session cookie (because PHP is parsed before the webpage loads) and so i need to use Javascript to update a cookie which i would prefer to be the session cookie used by PHP. I guess i'm asking what the name of the cookie is, how i would refer to it in Javascript (if that is even possible) so that i can update it and whether this would cause any issues with the info already stored in the session cookie by PHP. Cheers NM My Php Buddies, I have mysql tbl columns these:
id: Now, I want to display their row data by excluded a few columns. Want to exclude these columns: date_&_time account_activation_code account_activation_status id_verification_video_file_url password
So, the User's (eg. your's) homepage inside his account should display labels like these where labels match the column names but the underscores are removed and each words' first chars CAPITALISED:
Id: 1
For your convenience only PART 1 works. Need help on Part 2 My attempted code:
PART 1 <?php // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query to get columns from table $query = $conn->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'members' AND TABLE_NAME = 'users'"); while($row = $query->fetch_assoc()){ $result[] = $row; } // Array of all column names $columnArr = array_column($result, 'COLUMN_NAME'); foreach ($columnArr as $value) { echo "<b>$value</b>: ";?><br><?php } ?> PART 2 <?php //Display User Account Details echo "<h3>User: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php $excluded_columns = array("date_&_time","account_activation_code","account_activation_status","id_verification_video_file_url","password"); foreach ($excluded_columns as $value2) { echo "Excluded Column: <b>$value2</b><br>"; } foreach ($columnArr as $value) { if($value != "$value2") { $label = str_replace("_"," ","$value"); $label = ucwords("$label"); //echo "<b>$label</b>: "; echo "$_SESSION[$value]";?><br><?php echo "<b>$label</b>: "; echo "${$value}";?><br><?php } } ?> PROBLEM: Columns from the excluded list still get displayed. Edited November 19, 2018 by phpsaneHey guys im looking to do a drop down menu which is pretty basic however, in this drop down menu it uses an array of 4 values eg Orange, Apples, Bananas, Strawberry's. For this menu if a user has previously chosen an Orange which is stored on the db then then when the drop down menu is loaded it should move Orange to the top of the list, the same applies for the other values. How could I do this? I know how to do the select statement and place the values in an array. from there I dont know quite how to approach it. () Thank you. I have a list of x,y coordinates. (drill positions) I have Three Primary x,y co-ords. (station positions) I want to assign drill positions to stations based on how close they are and the priority of the station(1, 2 or 3). I also want the option of making all stations have a priority or 1 so they divide equally.(for drill positions that are close to two stations) I have absolutely no idea how to tackle this. Is there a formula anyone is aware of? Can anyone even attempt to show me how to tackle this. I am 100% lost. i am storing my menu in the database, i want to be able to output it by priority, heres so far what i have. I have no idea were to start. Database dump: -- -- Table structure for table `menu` -- CREATE TABLE IF NOT EXISTS `menu` ( `menu_access_lvl` int(2) NOT NULL, `priority` int(11) NOT NULL, `name` varchar(200) NOT NULL, `comment` text NOT NULL, `location` text NOT NULL, `creator_id` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `menu` -- INSERT INTO `menu` (`menu_access_lvl`, `priority`, `name`, `comment`, `location`, `creator_id`) VALUES (0, 1, 'Home Page', 'Home page', 'index.php', 'admin'), (0, 3, 'Contact', 'Contact', 'index.php?PG=contact', 'admin'), (0, 2, 'Events & Meetings', 'Events & Meetings', 'index.php?PG=events', 'admin'), (0, 4, 'About', 'About', 'index.php?PG=about', 'admin'), (2, 5, 'Admin', 'Admin', 'index.php?PG=admin', 'admin'); And here is the php code displaying it //gets the role of the user if set, otherwise role = 0 if(isset($_SESSION['SESS_MEMBER_ID']))$lvl = $_SESSION['SESS_ROLE']; else $lvl = 0; // this loads the menu buttons that correspond to the users role $menuqry="SELECT * FROM menu WHERE menu_access_lvl<='$lvl'"; $menuresult=mysql_query($menuqry); while($row = mysql_fetch_array($menuresult)){ echo "<li class=\"menuitem\"><a href=\"".$row['location']."\">".$row['name']."</a></li>"; } What this currently displays: Home Contact Events & meetings About I want it to be according to priority in the menu like: Home Events & meetings Contact About i want to sort the available words by the "searched word"...is there any way ? Code: [Select] <?php $query = "SELECT * FROM ce_cour_chap WHERE nom LIKE'%$find%' ORDER BY nom"; $result = mysql_query($query); while($search = mysql_fetch_array( $result )) { echo $search['nom']." - ".$search["chid"]."<br/>"; } ?> Hi All, I have a table, the column type is an attribute that items in this table share. A simple explanation would be if the field was colour and the items could be one of the colours. I am struggling with a for each loop to get the items out of this table grouped by this value. I am wanting to create a dopdown where the item_type is a header. This is what i have so far which obviously doesnt work: unction getRentalItems($display){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(' SELECT i.id, item, it.type, price_GBP, price_USD, price_CAD FROM items i LEFT JOIN item_type it on i.type = it.id '); $stmt -> execute(); $stmt -> bind_result($id, $item, $type, $gbp, $usd, $cad); if($display == 'Options'){ $out = ''; while($stmt -> fetch()){ $out .= '<optgroup label="$type">'; $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; } } return $out; } I would like the optgroup to be first whenever the type changes. I hope this explanation makes sense - there is an image to show what i mean - the bold text should only appear once per instance. Edited October 10, 2020 by Adamhumbug In my mysql database i have a field that records peoples details one part of the details is their county/region they live in. It records the county in a normal varchar field however i need a simple php script that searching the database and finds the most common county so i can then return to the screen where the most popular region for my members. Thank you for reading. Eventually I will have around 5 or 6 queries that will be replicated in several different pages, albeit with a slight difference in each (generally just a change in the WHERE part). I have been thinking about placing these common queries in a separate file and calling that file with an 'include' on the pages the query is needed. My two questions are.... Would this be more beneficial than place the query in the page itself and would there be any downside (as in loading times) if I placed all of these queries in one external file (ie. would this cause all the queries to load each time. Thanks in advance for any advice. Steve Hello, I have two arrays: $questions, which has 'question_id' as one of its keys and $assignment_questions which is a subset of $questions, pulled off my database. Using php, I'd like to construct a 3rd array which takes my $questions array and removes from it any question that has a question_id which can be found in both $questions and $assignment_questions, in addition to the other values associated with a particular question_id. For example, $questions has: question_id, solution, author (and other keys). Is there any way to check if a particular key matches and then zap out all of the corresponding fields (solution, author, etc.)? Thanks! I have wizard that asks several predefined questions to find-out user needs. at the end it must offer some items based on user answers. all of available items have some properties in common and one or two specific properties. what is the best way or algorithm to do this in JavaScript? e.g: Item 1 Properties: Name Weight Color Size Item 2 Properties: Name Size Weight Item 3 Properties: Name Color Size Thanks. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321735.0 Hi,
I have the following query
SELECT user_details.User_club_ID, user_details.fname, user_details.lname, user_details.email, user_details.club_No club.CLUBCODE, club.club_id FROM user_details, club WHERE club_id = $cid AND user_details.club_No = club.CLUBCODE AND user_status = 'active'";which I converted to a prepared statement as SELECT user_details.User_club_ID, user_details.fname, user_details.lname, user_details.email, user_details.club_No club.CLUBCODE, club.club_id FROM user_details, club WHERE club_id = ? AND user_details.club_No = club.CLUBCODE AND user_status = ?";Please note that user_status is a field in the table user_details. The original query (non -PDO) works correctly. I want to know if this is correct and that the comparison in the WHERE clause i.e. user_details.club_No = club.CLUBCODE is security safe. If not then how should this be modified. Also if there is a better way to write this statement, kindly show that as well. Thanks Thanks all ! Edited by ajoo, 11 December 2014 - 02:35 AM. I'm showcasing user avatars and nicknames on the page, the mistake I did was I used session variables for that which are being set after login, now obviously those will be deleted as soon as the session is over. So I thought of inserting the values into scalar variables instead of session variables. The problem I'm encountering is, how to make those variables available at the necessary spots on other pages? Let's say I fetch data off the database after login inside login.php and I put the data into scalar variables, what would be common practice to make those scalar variables accessible in index.php? Is this solution a good solution at all to make the avatar and nickname of the user permanent visible? What would be common practice? Currently, I am trying to make my URL shortener script able to track UTM variables from Google Analytics. I also want to provide my own (campaign/keyword/source/etc...) variables. I am trying to sift through $_GET, pick out "approved" key/value pairs and set each key with the condition that UTM variables take higher precedence (I only want to store one value in the database). My code is currently: Code: [Select] //Parse $_GET and only get the key/pairs that we need and store them in global $url_params for use through out the script function set_url_params($allowed=NULL) { // $allowed is arg to add new values in future dev global $url_params; $allowed = array( 'l', // Redirect key (e.g http://example.com?l=a1dFd7) 'utm_campaign', 'campaign', 'utm_source' , 'source', 'utm_medium', 'medium', 'utm_term', 'term', 'keyword', 'kw', ); $approved = array_intersect_key($_GET, array_flip($allowed)); foreach($approved as $key => $value) { strip_tags(urldecode(trim($value))); $url_params[$key] = $value; } //Assign variables to global $url_params variable so other functions can use them. //NOTE: Google Analytics UTM parameters take precedence over script values. $url_params['l'] = isset($approved['l']) ? $approved['l'] : NULL ; $url_params['campaign'] = isset($approved['utm_campaign']) ? $approved['utm_campaign'] : $approved['campaign']; $url_params['source'] = isset($approved['utm_source']) ? $approved['utm_source'] : $approved['source']; $url_params['medium'] = isset($approved['utm_medium']) ? $approved['utm_medium'] : $approved['medium']; $url_params['term'] = isset($approved['utm_term']) ? $approved['utm_term'] : $approved['term']; $url_params['keyword'] = isset($approved['keyword']) ? $approved['keyword'] : $approved['kw']; // Just in case $url_params doesn't have a 'keyword' set, we will use 'term' instead. $url_params['keyword'] = isset($url_params['keyword']) ? $url_params['keyword'] : $url_params['term']; } I basically want to find a cleaner way of doing this without all the isset()'s. I also get NOTICE errors (running in E_ALL) for undefined variables that I would like to unset so I don't get those errors. Any help would be appreciated. Thanks. Hello I have a from that updates a few things in the db, and uses "<?php echo $PHP_SELF;?>". The form does update everything fine, however that page does not reflect it. If I refresh the page manually I can see the new values. Is this a common thing, and can anything be done to fix this? Hi guys, I am currently stuck in a situation. I have duplicated names in my form. View duplicated.jpg for a reference. What exactly went wrong? Any help will be greatly appreciate! How do I eliminate the duplicated names. Thanks!! And my $count is currently not working as well, it is supposed to be 5 columns per row. Code: [Select] <?php /***Pre-School Level***/ echo '<input name="level[]" type="checkbox" id="level_1" value="1">'; echo '<span class="zone_text_enlarge"><label for="level_1">Pre-School</label></span><br/>'; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); $query = "SELECT sl.subject_level_id, sl.level_id, sl.subject_id, tl.level_name AS level_name, ts.subject_name AS subject_name " . "FROM tutor_subject_level AS sl " . "INNER JOIN tutor_level AS tl USING (level_id) " . "INNER JOIN tutor_subject AS ts USING (subject_id) " . "ORDER BY subject_level_id ASC LIMIT 7"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT subject_level_id FROM tutor_overall_level_subject WHERE tutor_id = '" . $_GET['tutor_id'] . "'"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); $selected_subjects = array(); while ($row = mysqli_fetch_array($sql1)) { array_push($selected_subjects, $row['subject_level_id']); } echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } foreach($selected_subjects as $selected_subject) { if ($data['subject_level_id'] == $selected_subject) { echo '<td><input name="subject_level[]" class="subject_a" type="checkbox" checked="checked" id="subject_level_'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="subject_level_'.$data['subject_level_id'].'" class="subject_1">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } else { echo '<td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="subject_level_'.$data['subject_level_id'].'" class="subject_1">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } } } echo '</tr></table><br/>'; //Close your last row and your table, outside the loop ?> This is the end result of the HTML code, through 'view page source' in web browser Code: [Select] <input name="level[]" type="checkbox" id="level_1" value="1"> <span class="zone_text_enlarge"><label for="level_1">Pre-School</label></span><br/> <table><tr></tr> <tr> <td><input name="subject_level[]" class="subject_a" type="checkbox" checked="checked" id="subject_level_1" value="1"/> <label for="subject_level_1" class="subject_1">Mathematics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_1" value="1"/> <label for="subject_level_1" class="subject_1">Mathematics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_2" value="2"/> <label for="subject_level_2" class="subject_1">English</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_2" value="2"/> <label for="subject_level_2" class="subject_1">English</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_3" value="3"/> <label for="subject_level_3" class="subject_1">Chinese</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_3" value="3"/> <label for="subject_level_3" class="subject_1">Chinese</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_4" value="4"/> <label for="subject_level_4" class="subject_1">Tamil</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_4" value="4"/> <label for="subject_level_4" class="subject_1">Tamil</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_5" value="5"/> <label for="subject_level_5" class="subject_1">Malay</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_5" value="5"/> <label for="subject_level_5" class="subject_1">Malay</label></td> </tr> <tr> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_6" value="6"/> <label for="subject_level_6" class="subject_1">Phonics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" checked="checked" id="subject_level_6" value="6"/> <label for="subject_level_6" class="subject_1">Phonics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_7" value="7"/> <label for="subject_level_7" class="subject_1">Creative Writing</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_7" value="7"/> <label for="subject_level_7" class="subject_1">Creative Writing</label></td></tr> </table><br/> Hey , I'm looking for functions names from the GD directory. 1.function that open image. 2.function that getting pixel color. 3.function that changing pixel color. thanks. |