Jump to content

Destramic

Members
  • Posts

    960
  • Joined

  • Last visited

Everything posted by Destramic

  1. thank you...ive found a easier way of getting most of the information i need now protected function fetch_data() { $ip = $this->get_ip(); $url = "http://www.geoplugin.net/json.gp?ip=" . $ip; $json = file_get_contents($url); $json = json_decode($json); $this->_ip = $ip; $this->_status = $json->{'geoplugin_status'}; $this->_city = $json->{'geoplugin_city'}; $this->_region = $json->{'geoplugin_region'}; $this->_area_code = $json->{'geoplugin_areaCode'}; $this->_dma = $json->{'geoplugin_dmaCode'}; $this->_country_code = $json->{'geoplugin_countryCode'}; $this->_country_name = $json->{'geoplugin_countryName'}; $this->_continent_code = $json->{'geoplugin_continentCode'}; $this->_longitude = $json->{'geoplugin_longitude'}; $this->_latitude = $json->{'geoplugin_latitude'}; $this->_region_code = $json->{'geoplugin_regionCode'}; $this->_region_name = $json->{'geoplugin_regionName'}; $this->_currency['code'] = $json->{'geoplugin_currencyCode'}; $this->_currency['symbol'] = $json->{'geoplugin_currencySymbol'}; $this->_currency['symbol_UTF8'] = $json->{'geoplugin_currencySymbol_UTF8'}; $this->_currency['exchange_rate'] = $json->{'geoplugin_currencyConverter'}; }
  2. im trying to make a script so i can get users details like longitude, latitude etc but im having trouble matching the html by regular expression here is the html below that im trying to extract the data from: any help or possible any alternative, suggested ways would be greatful thank you <td>Country:</td> <td><img src="/images/dot.gif" class="flag-16 gb" align="absmiddle" width="16" height="16" title="United Kingdom"> United Kingdom (GB)</td> </tr> <tr> <td>City:</td> <td>Newport</td> </tr> <tr> <td>Region:</td> <td>Newport</td> </tr> <tr> <td>Latitude:</td> <td>51.5833</td> </tr> <tr> <td>Longitude:</td> <td>-2.9833</td> </tr> <tr> <td>Timezone:</td> <td>Europe/London</td> <?php $url = "http://smart-ip.net/geoip/2.101.108.124/"; $ch = curl_init(); $timeout = 0; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); if (preg_match('/<td>Country:</td><td>[img](?P<country>\w+)</td>/$', $rawdata, $match)) { $country = $match['country']; } if (preg_match('/<td>City:</td><td>(?P<city>\w+)</td>/$', $rawdata, $match)) { $city = $match['city']; } if (preg_match('/<td>Region:</td><td>(?P<region>\w+)</td>/$', $rawdata, $match)) { $region = $match['region']; } if (preg_match('/<td>Latitude:</td><td>(?P<latitude>\d+)</td>/$', $rawdata, $match)) { $latitude = $match['latitude']; } if (preg_match('/<td>Longitude:</td><td>(?P<longitude>\d+)</td>/$', $rawdata, $match)) { $longitude = $match['longitude']; } if (preg_match('/<td>Timezone:</td><td>(?P<timezone>\w+)</td>/$', $rawdata, $match)) { $timezone = $match['timezone']; } ?>
  3. just what i needed...saved me a lot of time and effort...thank you
  4. hey guys ive been using this regual expression for my configuration files to get the variable and value ie. db_username = blah db_password = blah but im in need of some help on the regular expression so that the value can be any character instead of just A-Za-z0-9_.:\/ this is what im using at the moment '/([A-Za-z0-9_]+) += +([A-Za-z0-9_.:\/]+)/' ive tried altering it to '/([A-Za-z0-9_]+) += +(.*)/' but doesnt seem to work at all any help would be truly greatful...thank you guys
  5. im using dom to tidy up my html but i wondering is there a way to format my html like so <dl> <dd> <label>Condition :</label> <select name="condition"><option value="New">New</option> </dd> </dl> insead of <dl> <dd> <label>Condition :</label> <select name="condition"><option value="New">New</option> </dd> </dl> here is the php im using $dom = new DOMDocument(); $dom->loadHTML($this->_body); $dom->formatOutput = true; echo $dom->saveHTML(); thank you
  6. hey guys...im after a it of advise regarding wrapping html using a decorator...below i have a label class where im able to send attributes to a method and render a <label> tag. but what i'm confused at is the design pattern to wrap the <label> tag... $label = new Label; $label->render(array('for' => 'name', 'label' => 'Destramic')); // returning <label for="name">Destramic</label> but what would be the best way to wrap say a <div> tag around the label?...if anyone could help of have a tutorial on a good way of doing this...thank you <?php namespace Form\View; use HTML\Decorator as Decorator; class Label extends Decorator { protected $_attributes = array('for', 'form'); public function open_tag(array $attributes) { if (array_key_exists('label', $attributes)) { $label = $attributes['label']; } else { $label = " "; } $tag = sprintf("<label %s>%s", $this->create_attributes_string($attributes), $label); return $tag; } public function close_tag() { return "</label>\n"; } public function render(array $attributes) { return $this->open_tag($attributes) . $this->close_tag(); } } decorator <?php namespace HTML; class Decorator { protected $_html; protected $_global_attributes = array('accesskey', 'class', 'contenteditable', 'contenteditable', 'dir', 'draggable', 'dropzone', 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', 'translate'); public static $_placement = "PREPEND"; public function set_html($html) { $this->_html = $html; } public function wrap() { } public function create_attributes_string(array $attributes) { $string = null; $count = count($attributes); $i = 0; foreach ($attributes as $attribute => $value) { $i++; $global_attribute = substr($attribute, 0, 5); if (in_array($attribute, $this->_attributes) || in_array($attribute, $this->_global_attributes) || $global_attribute == "data-") { if ($count == $i) { $string .= $attribute . '=' . '"' . $value . '"'; } else { $string .= $attribute . '=' . '"' . $value . '" '; } } } return $string; } }
  7. hey guys i know there is various script about to locate user (country, latitude and longitude) by ip...but can anyone suggest a good one which is free please? thank you
  8. CASE WHEN @category = 'All' THEN NULL ELSE LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id JOIN categories c ON c.category_id = sc.category_id AND c.name = :category END i think i've tried them all if statements , case, but keeps returning error in those lines....please has anyone any ideas or advise? the only way possible i can see at the moment is to alter the query via a php if statements...thank you
  9. just having problem with syntax in the case now...im hoping this will work SELECT @category = 'Videos', i.item_id, i.title, i.price, i.p_and_p, (i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time`, cu.code AS `seller_currency_code`, cu2.code AS `buyer_currency_code`, cu2.symbol AS `buyer_currency_symbol` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id CASE @category WHEN @category != 'ALL' THEN AND c.name = @category END LEFT JOIN users u ON u.user_id = i.user_id LEFT JOIN currencies cu ON cu.currency_id = u.currency_id LEFT JOIN users u2 ON u2.user_id = '7' LEFT JOIN currencies cu2 ON cu2.currency_id = u2.currency_id AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW() GROUP BY i.item_id
  10. ummm actually it isn't working right...when :category = 'All' it doesn't load all items like i want but just causes a error...probably due to the fact there isn't a category name called All if category ALL i want to load all items regardless of category...but if category = a category then load items within that category =/ help anyone please
  11. LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id JOIN categories c ON c.category_id = sc.category_id AND (c.name = ':category' OR ':category' != 'All') that has seemed to work...so if category is ALL then it will show all regardless of the category...but if category is VIDEOS for instance it will load all VIDEOS...thank you for your help guys
  12. that worked great thank you...any ideas with the case?...i could use a php if statement but surly there must be a way with sql?
  13. lovely...thank you for your help
  14. Destramic

    case help

    hey guys im having a few problems with my query if anyone can please help...the two problems im having is 1.the total price returning as 00106. price = 100.00 and p_and_p = 6.00 in the database...im after a figure that looks like 106.00 2. @category will be a parameter like :category which will be binded to a value like 'al'l, 'videos', 'dvd's', but if the parameter is ALL i dont want to join my categories table allowing it to select all rows regardless of the category any help, pointer would be truly appreciated...thank you SELECT @category := 'Videos', i.item_id, i.title, i.price, i.p_and_p, SUM(i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id CASE @category != 'All' THEN LEFT JOIN categories c ON c.name = 'Videos' END CASE JOIN users u WHERE u.user_id = '7' AND MATCH (i.title, i.description) AGAINST ('bla' IN BOOLEAN MODE) AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW() GROUP BY i.i
  15. thank you guys for your input so in essence dont use add/strip_slashes and mysqli_real_esapce_string() but with every input ($_POST from user i should use htmlspecialchars() ? thank you agian
  16. hey guys i was generally wondering...is it good practice to add_slashes and use mysqli_real_escape_string when entering data into the database? then to strip slashes when extracting rows? is this the right way to go around things...thanks
  17. no the string just contains letters only...but yeah your right to use other functions other than regex when possible...thank you for your help...was just what i needed
  18. when trying to call get_class($this) it will return the namespace of my class Application\Models\User_Model But what im really after is just User_Model... is there a way of actually getting the class name and not the namespace itself? thought i'd ask before making a class for that...thank you
  19. hey im tring to match words which contain double s at the end...ie. address, business, class etc...so that is so i can put a ' at the end... class' if (preg_match("/ss$/", $name)) { $name = $name . "'"; } any help with the regular expression would be great thank you
  20. hey guys im in a bit trouble trying to use window offset() function. basically i have a fixed header and what im trying to accomplish is for when the user scroll past a certain point the header content will change...im not sure if im going about this the right way or even sure if it is possible with a fixed header. any help would be grateful thank you <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <style type="text/css"> body{ margin:0px; background:#FFFFFF; } .header-cont { width:100%; position:fixed; top:0px; } .header { height:50px; background:#F0F0F0; border:1px solid #CCC; width:960px; margin:0px auto; } .content { width:960px; background: #F0F0F0; border: 1px solid #CCC; height: 2000px; margin: 70px auto; } </style> <script> $(window).scroll(function(){ var position = $('#position').offset().top; if ($(window).scrollTop() > position) { alert('hey'); // Change header content } }); </script> </head> <body> <div class="header-cont"> <div>FIXED HEADER</div> </div> <br /> <div id='position'></div> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> CONTENT HERE! </body> </html>
  21. hey guys im having a problem aligning a div so its vertically aligned middle...the objects im having the difficulty with is "search-bar" and "quick-links" which are apart of the "search_bar_container"...i;ve been fiddling about with it but have had no luck...css isn't really my thing so any pointer will be greatly appreciated thank you <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#list-icon").click(function() { if ($('#top-bar-media-menu').is(":visible")) { $('#top-bar-media-menu').hide("fast"); } else { $('#top-bar-media-menu').show("fast"); $('#top-bar-media-menu').focus(); } }); }); </script> <style> body { margin: 0px; } div#top-bar-media-menu { display: none; } div#header #left-link { display: inline-block; vertical-align: middle; padding: 5px; } div#header #right-link { float: right; line-height: 45px; padding-right: 10px; } div#header #list-icon { background-image: url('list.png'); vertical-align: middle; display: inline-block; height: 48px; width: 48px; } div#header #home-icon { background-image: url('home.png'); background-color: #505050; vertical-align: middle; display: inline-block; height: 48px; width: 48px; } div#header #arrow-down { background-image: url('arrow_down.png'); vertical-align: middle; display: inline-block; height: 16px; width: 16px; } div#header #top-bar-container { background-color: #000000; width: 100%; border-radius: 3px; position:relative } div#header #top-bar-desktop { background: -moz-linear-gradient(top, #505050, #343434); border: 1px solid #080808; width: 85%; height: 48px; margin-left: auto; margin-right: auto; border-top-right-radius: 3px; border-bottom-right-radius: 3px; font-family: Verdana,Arial,sans-serif; font-size: 12px; color: #FFFFFF; vertical-align: middle; } div#header #top-bar-media { display: none; } div#search_bar_container { width: 85%; height:80px; margin-left: auto; margin-right: auto; position:relative; } div#search_bar_container #logo { display: inline-block; background-image: url('logo.png'); height: 80px; width: 220px; } div#search_bar_container #search-bar { line-height: 45px; display: inline-block; position:absolute; width: 50%; height: 40px; } input#search { position: relative; width: 40%; border: 1px solid #080808; height: 30px; border-radius: 20px; font-family: Verdana,Arial,sans-serif; font-size: 14px; color: #000000; vertical-align: middle; } div#search_bar_container #quick-links { display: inline-block; vertical-align: middle; } @media all and (max-width:500px) { div#header #top-bar-desktop { display: none; } div#header #top-bar-media { display: block; background: -moz-linear-gradient(top, #505050, #343434); border: 1px solid #080808; width: 85%; height: 45px; margin-left: auto; margin-right: auto; border-top-right-radius: 3px; border-bottom-right-radius: 3px; font-family: Verdana,Arial,sans-serif; font-size: 11px; color: #FFFFFF; } } </style> </head> <body> <div id='header'> <div id='top-bar-container'> <div id='top-bar-media'> <div id="list-icon"></div> </div> <div id='top-bar-desktop'> <div id='home-icon'></div> <span id='left-link'>Register / Login</span> <span id='left-link'>News</span> <span id='left-link'>My Account</span> <div id='arrow-down'></div> <span id='right-link'>Language</span> </div> </div> <div id='search_bar_container'> <div id='logo'></div> <div id='search-bar'><input id='search' type='text'/></div> <div id='quick-links'>quick links here<div> </div> </div> <div id='top-bar-media-menu'>menu here</div> </body> </html>
  22. hey guys im wdondering if there's a magic method which works like __GET() but allows you to put a parameter in...thank you <?php class test { public function run() { $this->object->('string'); // __get with parameter? } public function __get($value) { return $this->{$value} } } ?>
  23. using the code above will remove all sessions and data set...im only want to unset a particualr session not all...i tried using session_unset which worked great...although the function unappreciated
  24. Well I use a name space which will make my sessions look like $_SESSION['authentication']['id']; Would I put that instead of session_name()? Thank you
  25. hey guys im having a spot of botter unsetting, destroying a session which has been given a cookie lifetime...i know it is possible to destroy all sessions using session_destroy() but i want to destory a particials session and not all of them. here is my method if anyone can give some advice on how i could do this please...thank you public function destroy($name = null) { $namespace = $this->_namespace; $sessions = $_SESSION[$namespace]; if ($name == null) { foreach ($sessions as $name => $value) { $session = $sessions[$name]; unset($sesion); if (isset($session)) { // sessions with lifetime ini_set('session.cookie_lifetime', 0); ini_set('session.gc_max_lifetime', 0); ini_set('session.gc_probability', 1); ini_set('session.gc_divisor', 1); $session; } } } else { unset($sessions[$name]); } session_regenerate_id(true); }
×
×
  • 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.