Jump to content

Mal1

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by Mal1

  1. I've tried header in the past (unless I'm using it the wrong way or putting it in the wrong place) I'm getting: Warning: Cannot modify header information - headers already sent by (output started at /homepages/33/d440142155/htdocs/LuxuryLiving/member/logout.php:12) in /homepages/33/d440142155/htdocs/LuxuryLiving/member/logout.php on line 33
  2. I've got login script which seems to be working as I want if apart from when you log out. It is logging out fine but I've made a button at the top of the site which says login (if no session is logged in) or logout (if they are logged in). On logging out this button doesn't change until you go to another page or refresh the browser. Is there a way of forcing a refresh or is there something else I should be doing? Logout code here: <? if(!isset($_REQUEST['logmeout'])){ echo "<center>Are you sure you want to logout?</center><br />"; echo "<center><a href=logout.php?logmeout>Yes</a> | <a href=javascript:history.back()>No</a>"; } else { session_destroy(); if(!session_is_registered('first_name')){ echo "<center><font color=red><strong>You are now logged out!</strong></font></center><br />"; echo "<center><strong>Login:</strong></center><br />"; include 'login_form.html'; } } ?> Code I'm using in my header.php is: <? if (isset($_SESSION['first_name'])) { include $_SERVER['DOCUMENT_ROOT'] . '/layout/logout.php'; } else include $_SERVER['DOCUMENT_ROOT'] . '/layout/signin.php'; ?>
  3. But would this not mean placing the session start at the top of each page? It doesn't seem right.
  4. I'm trying to start a session in my header.php file so it's included on every page so that I can have a "Log in | Register" button if people are signed in or a "Logout" button if people are already signed in. I'm getting the message: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /homepages/33/d440142155/htdocs/LuxuryLiving/index.php:14) in /homepages/33/d440142155/htdocs/LuxuryLiving/layout/header.php on line 3 As far as I'm aware this is caused by the session start not being the first line of code? I could place <?php session_start(); ?> On each individual page but A) would this not be attempting to start the session over and over again on every page (I'm sure it would ignore secondary attempts but this can't be the right way to do it?) and B) it just doesn't seem like the right way to do it. The code I have is as follows: Index page (similar for all pages)... <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>The Luxury Living Network - Scotland</title> <link href="/css/network.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" href="/images/network.ico" type="image/x-icon" /> </head> <body> <div id="container"> <?php include('layout/header.php'); ?> <div id="content">... Within the header.php... <?php session_start();?> <? $page = $_SERVER['SCRIPT_NAME']; ?> <div id="header"> <div id="logo"> <a href="http://www.luxurylivingscotland.co.uk"> <img src="http://www.luxurylivingscotland.co.uk/images/logo.jpg" alt="Luxury Living Logo" name="luxurylivinglogo" id="luxurylivinglogo" /> </a> </div> <? if (isset($_SESSION['first_name'])) { include ('layout/logout.php'); } else include ('layout/signin.php') ?> </div> <div id="menu" align="center"> <ul> <li><a href="/index.php">Home</a></li> <li><a href="/about.php" <?php if ($page == "/about.php"){ echo "class='active'";} ?>>About Us</a></li> <li><a href="/categories.php" <?php if ($page == "/categories.php"){ echo "class='active'";} ?>>Categories</a></li> <li><a href="/member/offers.php" <?php if ($page == "/member/offers.php"){ echo "class='active'";} ?>>Offers</a></li> <li><a href="/members.php" <?php if ($page == "/members.php"){ echo "class='active'";} ?>>Member's Area</a></li> <li><a href="/contact.php" <?php if ($page == "/contact.php"){ echo "class='active'";} ?>>Contact Us</a></li> </ul> </div> Any ideas what I'm doing wrong?
  5. Is there any sort of diagnostic tool or check I could do to try to at least find out what would be causing it? At least then if we were to get a programmer we'd know where to direct them.
  6. I'll state that I'm a complete amateur when it comes to programming in case I'm not clear or I say something that doesn't make sense. I have two websites which have evolved over the years with different programmers at different times - www.little-persia.com and www.love-rugs.com. I look after both cosmetically and have worked out various issues with javascript, php etc. over the years by just researching and teaching myself/using common sense/problem solving. However I'm stumped. Little-Persia is really fast when it comes to searches (page changes in under 2 seonds and images load within another second) yet Love-Rugs is unbearably slow (I hit search and the page hangs for about 12 seconds before doing anything). I think I've worked it out as having little to do with page sizes/image load times etc. and more to do with number of queries. Load times are at their worst for a blank search - if I put in a few filters in an advances search the load times become bearable (although still not great or anywhere near the same speed as Little-Persia). The two websites have different tables with Love-Rugs loading information on stock levels/size and price from one and general details from another. Little-Persia is all individual products (don't come in a variety of sizes/prices) so all their info is stored on one table. I'm trying to obviously figure out how to speed it up and/or remove unnecessary queries but to do that I need to find out where they're originating. Is there a way to do this?
  7. I think the problem was my logic was based on "if it's checking to see if it's not set then it must be checking to see if it's set" which it clearly wasn't. Hard to think the way the code works as we so often go from A to C skipping out B.
  8. Working! Thanks you're a legend! (Had to change "session" to "SESSION" or at least I think that's why it's now working)
  9. Thanks, no typos as far as I can see but doing this seems to set the variable to GBP. I don't know if the problem is the forms are resubmitting (blank) every time a new page is loaded?
  10. Ok, so I've got the form I'm using to work for the three different currencies. It switches between them without issue while on the page: <div id="country-flags"> <form enctype="multipart/form-data" action="" method="post"> <input type="hidden" name="currency" value="GBP"/> <input type="submit" name="GBP" value="" id="GBP-flag"/> </form> <form enctype="multipart/form-data" action="" method="post"> <input type="hidden" name="currency" value="EUR"/> <input type="submit" name="EUR" value="" id="EUR-flag"/> </form> <form enctype="multipart/form-data" action="" method="post"> <input type="hidden" name="currency" value="USD"/> <input type="submit" name="USD" value="" id="USD-flag"/> </form> </div> This, as far as I can tell posts the session variable to the index.php. Using an IF statement to determine which price to display based on the session variable being GBP, EUR or USD. The code I'm using in the index.php is: $_SESSION['currency'] = $_POST['currency']; if(!isset($_SESSION['currency'])) $_SESSION['currency'] = "GBP"; So this is working (until the user clicks one of the buttons to post a currency GBP is being used, as no currency variable is set) until they navigate to the new page where it appears to lose the variable. Printing the variable on the page shows nothing without the !isset line of code being used or GBP when it is in place. So I seem to be losing the variable when I navigate to the next page. I feel like it's either something simple or trivial I'm missing or I'm trying to do something impossible. Any ideas?
  11. Sorry, this has been moved to: http://forums.phpfreaks.com/index.php?topic=363470.0
  12. Ok so that's working. Thanks for the help... one final question: is there a way to set the variable default as GBP but then use $_POST['currency']; thereafter?
  13. Got it working... simply had to change my session variable from $_SESSION['currency'] = "GBP"; To: $_SESSION['currency'] = $_POST['currency']; And use the form method rather than the images.
  14. I have of course replaced the img src. The href link should either be to index.php (where the session variable is stored) or the current url "<?php echo $_SERVER['REQUEST_URI'];?>?currency=USD" I'm not sure which? Not quite sure how to set up the $_GET['currency'] variable? Think I'm getting confused over all the different methods. Or are you saying no longer use session variables?
  15. That doesn't seem to work. Just takes me back to the home page and then when I go back to product pages the prices are still in GBP (the $_Session['currency'] hasn't been altered).
  16. I don't know if that would work with the approach I was taking... I have three different DIVs set up for Euro, GBP and USD. They look like this: <?php if ($_SESSION['currency'] == "GBP") { ?> <span><p class="info">Price:</p>... So only the div that corresponds to the set session variable will show. What I'm trying to do is change the session variable by clicking on flags which will in turn change what type of currency is displayed on the page. Maybe what I'm attempting isn't possible. It was on someone else's suggestion.
  17. Sorry how would I use the Get variable? The images look like this: <img src="http://www.little-persia.com/images/flags/Flag_UK.gif" alt="GBP Currency" border="0" id="GBP" /> I've also tried this (using CSS to display the forms as images) but it doesn't seem to work: <form enctype="multipart/form-data" action="" method="post"> <input type="hidden" name="$_SESSION['currency']" value="EUR"/> <input type="submit" name="EUR" value="" id="EUR-flag"/></form>
  18. I'm now thinking I should have used url variables rather than session variables? I can't seem to figure out how to modify the session variable by clicking on the link/image. I know it's something to do with sessions not being client side... have tried setting the images as forms with hidden post values to no avail.... Any pointers?
  19. I've got a script which converts currencies based on up to date information and have coded my page so that prices switch between pound, dollar and euro depending on a session variable in the index called currency (defaults as "GBP"). If this changes to "USD" then the dollar price is shown and "EUR" the euro price is displayed. This all works fine but I've got 3 flags for the images and I want to link them so that when they are clicked on it changes the session variable in index.php from: $_SESSION['currency'] = "GBP"; to: $_SESSION['currency'] = "USD"; or: $_SESSION['currency'] = "EUR"; How do/should I go about this? (probably really easy I just don't come from a coding background) ***EDIT*** Also, just thinking, when one of these images/buttons is clicked the page would probably need to refresh with the new session variable - is there a way to do this?
  20. Ah yeah! Thanks, as I said complete newbie at this - I just look at existing code and work things out based on what's already there. Got it working now (the double == and wasn't opening and closing the php if clause the way it was wanting). Just need to add in the code for Euros and Dollars now and put flags on my page and work out how to point them to change the session info to EUR/USD and I'll be done!
  21. Sorry... I have this in my index.php: $_SESSION['currency'] = "GBP"; And then this on the page I want to use it on (I've not added the flags etc. yet to actually change the session info): <?php if ($_SESSION['currency'] = 'USD'); ?> <span> <p class="info">Price:</p> <p class="txt"><strong><?php if ($rug->data['sold']) { ?><p class="price"><?php } ?><?php if ($rug->data['sold']) { ?>Sold</p><?php } else echo '£'.$rug->data['price']; ?></strong></p> </span> <?php if (!$rug->data['sold'] && $rug->data['special_offer']): ?> <span> <p class="info">Now:</p> <p class="now">£<?php echo $rug->data['discount_price']; ?></p> </span> <span> <p class="info">You Save:</p> <p class="price">£<?php echo $rug->data['price'] - $rug->data['discount_price']; ?> (<?php echo round(($rug->data['price'] - $rug->data['discount_price']) / $rug->data['price'] * 100) ?>%)</p> </span> <p> <?php endif; ?> So I was trying to test as it should NOT show the Price data as at this moment $_SESSION['currency'] does not equal "USD".
  22. Sorry, wasn't sure if it was a Javascript issue or CSS (or sessions). I've added a session called currency and defaulted it as GBP. Tried to test using <?php if ($_SESSION['currency'] = 'USD'); ?> (which should not include the code within as the session should = GBP yet it's still showing. Any ideas?
  23. I'm using a script which converts currency between GBP and EUR and USD etc and uses up to date exchange rates and it's working fine. But I want to display prices based on which option the user selects (e.g. using flags). Right now I'm having to display each currency I want to display one under the other but am looking to be able to select a flag and it to only use the code/div/span for that currency. Not sure which type of code this would be? Any pointers to similar code? I'm a complete self-taught beginner but I'm pretty confident that I'd be able to modify a similar piece of code to my needs. Could I do something whereby the flags add something to the URL then the Divs are echoed or not echoed based on what is contained in the URL. ***Whatever I use would need to be permanent (into the URL or something) so that all the prices on the website are converted not just one page.***
  24. Apply promotion checks to see if there is a promotion active and if it applies to an item. Use Quantity is a field we have to determine whether something needs to be in stock or can be ordered from a supplier - if UseQuantity is active then the number of stock items if finite and once they are gone the item is removed from search results. Ignore Quantity (opposite of UseQuantity) treats the item as if it has unlimited stock - the stock counter ticks down if things are in stock but once it hits zero the item remains active and customers can purchase as many as they like.
  25. Here's more of the code, this is the preceding part of that which was posted earlier. There is a lot of inter-twined functions but as far as I can see this is how the code fetches the results (the first part is how the code opens up, the second where I believe the search results are generated (all this is in the one file - I've added and closed the php tags just so it displays properly in code view: Opening code (important but not the code that displays/fetches search results as far as I'm aware) <?php class Database { var $pages, $error, $query_count; function Database($db_user, $db_pass, $db_name, $db_host) { $this->query_count = 0; $this->error = 0; if (!mysql_connect($db_host, $db_user, $db_pass) || !mysql_select_db($db_name)) $this->error = 1; } function query($sql_query) { //echo $sql_query.'<br />'; $this->query_count++; $result = mysql_query($sql_query); $rows = array(); if(@mysql_num_rows($result) > 0){ while ($row = mysql_fetch_assoc($result)) $rows[] = $row; } return $rows; } function escape($escape_string) { if (get_magic_quotes_gpc()) return mysql_escape_string($escape_string); else return $escape_string; } function execute($sql_query) { mysql_query($sql_query) or die("EXECUTE: ".mysql_error()." SQL: ".$sql_query); // echo "TSDXX: $sql_query"; // die(); return mysql_insert_id(); } function save($table, $fields) { $pairs = array(); foreach ($fields as $field => $value) // do not quote NULLs if ( $value == "NULL" ) $pairs[] = "`$field`=".$this->escape($value); else $pairs[] = "`$field`='".$this->escape($value)."'"; $sql = "UPDATE `$table` SET ".join(",", $pairs)." WHERE `id`='{$fields['id']}'"; // echo $sql; // die(); // print_r($fields); // die(); $this->execute($sql); } function randomRugs($page=1) { global $search_results_per_page; echo "Test"; if (!isset($_SESSION['random_rugs']) || !is_array($_SESSION['random_rugs'])) $_SESSION['random_rugs'] = $this->query("SELECT `id` FROM `rugs` WHERE `active`='1' AND `deleted`='0' ORDER BY RAND()"); $this->pages = ceil(count($_SESSION['random_rugs'])/$search_results_per_page); $page = intval($page); if ($page > $this->pages) $page = $this->pages; if ($page < 1) $page = 1; $current_ids = array_slice($_SESSION['random_rugs'], ($page-1)*$search_results_per_page, $search_results_per_page); $ids = array(); foreach ($current_ids as $current_id) $ids[] = "`id`='".$current_id['id']."'"; //return $this->query("SELECT * FROM `rugs` WHERE ".join(" OR ", $ids)); $rugs=array(); foreach($ids as $id) { $rugs=array_merge($rugs, $this->query("SELECT * FROM `rugs` WHERE ".$id.";")); } return $rugs; } ?> Here is where it's getting the search results. <?php function findRugs($conditions, $page=1, $sort="") { global $search_results_per_page, $current_user, $pages; if ($current_user != NULL){ $search_fields = array("id", "active", "type", "mod_trad", "shape", "rug_type", "fabric", "design", "make", "age", "origin", "name", "pattern", "colour"); }else{ $search_fields = array("id", "active", "type", "mod_trad", "shape", "rug_type", "fabric", "design", "make", "age", "origin", "name", "pattern", "colour"); } $pairs = array(); $ignore_rs = $this->query("SELECT LOWER(name) as name FROM rug_search_ignore_words WHERE id <> 0 AND active = 1"); $ignore_list = array(); foreach ( $ignore_rs as $ignore ){ $ignore_list[] = $ignore['name']; } require("inc_search.php"); // collect entire result set for refine area //$rugs_all = $this->query($sql); //$rugs_search_all = $this->query($sql); $sql_all = $sql; $rugs_all = array(); foreach ( $rugs_search_all as $rug ) { $tmp = new Rug($rug['id']); $rugs_all[] = $tmp->data; } //echo "rug_count: ".count($rugs_all)."<br />"; //echo "<br />---FULL---".$sql; $page_count = $this->query($count_sql); $pages = ceil(array_shift(array_shift($page_count)) / $search_results_per_page); $search_results_per_page = 10; if(isset($_GET['page'])) { $cur_page = intval($_GET['page'])-1; if($cur_page==0) { $sql .= " LIMIT 0, $search_results_per_page"; } else { $sql .= " LIMIT ".($search_results_per_page * $cur_page).", $search_results_per_page"; } } else { $sql .= " LIMIT 0, $search_results_per_page"; } //echo $sql; // page the result set $rugs_search = $this->query($sql); $rugs = array(); foreach ( $rugs_search as $rug ) { $tmp = new Rug($rug['id']); // apply promotions $tmp->applyPromotion(); if(!isset($_GET['admin-search']) OR (isset($_GET['admin-search']) && $_GET['admin-search'] == 0)){ // eliminate rugs without any stock if ( $tmp->useQuantity() ) { $stock = 0; // look for active stock foreach ( $tmp->data['stock']->data as $stock => $values ) { if ( $values['active'] == '1' && $values['stock'] > 0 ){ $stock += $values['stock']; } } if ( $stock > 0 ){ $rugs[] = $tmp->data; } }else{ $rugs[] = $tmp->data; } }else{ $rugs[] = $tmp->data; } } return array( 'this' => $rugs, 'all' => $rugs_all, 'sql' => $sql_all) ; } ?>
×
×
  • 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.