Jump to content

alwoodman

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by alwoodman

  1. Hi I am trying to get drupal to only show a block during certain times of the day and only on a specific URI but it keeps showing up on other pages so the substr($_SERVER["REQUEST_URI"], 0) == "/folder/mypage") must be the issue i assume? <?php $time = (int) date('Gi'); return (($time < 600 && $time >= 0000) || ($time > 1630 && $time <= 2359) && substr($_SERVER["REQUEST_URI"], 0) == "/folder/mypage"); ?> <?php $time = (int) date('Gi'); return (($time > 600 && $time < 1630)) && ($_SERVER["REQUEST_URI"] == "/folder/mypage")); ?> thanks Lee
  2. Im trying to select all the records that were created today irrespective of time from a Datetime field. This is what i have so far but it only pulls yesterdays. SELECT * FROM table WHERE date_time_value < curdate() and date_time_value> DATE_ADD(CURDATE(), INTERVAL -1 day) ORDER BY date_time_value ASC thanks in advance Lee
  3. What is the best way for me to gzip my dynamic pages? thanks Lee
  4. Hi I have a simple page cacher on my site <?php if($_GET['testing'] != 1){ $cachefile = 'cache/index.html'; $cachetime = 3000; // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { include($cachefile); exit; } ob_start(); } ?> but recently came across this update to it which is: <?php if($_GET['testing'] != 1){ $cachefile = 'cache/index.html'; $cachetime = 3000; // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { include($cachefile); exit; } if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); } ?> Could you confirm this script is caching the content of my page and when a user requests it again it's being decompressed? The reason i ask is the output still seems to be the same size in the cache folder with and without this code thanks Lee
  5. Im trying to get the days tide information which is currently in the array $tides to echo out as part of a string $message $tides = array(); do { $newtideheight = round($row_TidesFeed['Height'] + 3, 0); $basedate = strtotime($row_TidesFeed['Time']); $date1 = strtotime("-1 hour", $basedate); $newdate = substr(date('H:i:s', $date1), 0, 5); array_push($tides, rtrim($row_TidesFeed['State'], "W").''.$newdate); } while ($row_TidesFeed = mysql_fetch_assoc($TidesFeed)); // This is what i need to echo ideally as one variable $alltides which will sit at the end of and be part of the $message.''.$alltides foreach ($tides as $value){ echo $value; } $message = $message.' and the tides are $alltides'; thanks Lee
  6. Im created a series of Rewrites and on page checks to make sure the correct url is being called. But now that i am buying in traffic through Adwords the gclid parameter is being dropped and im unable to measure conversions...im not sure if its the php or the rewrite rule at fault...the rewrite rule im assuming. Im not sure if the ? is saying keep parameters or not. # page rewrite rule example http://www.mydomain.co.uk/location/1/name/ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^location/([^/]+)/([^/]+)/? location-view.php?loc=$1&n=$2 [L,NC] and on the page in question "location-view.php" i have the following: if (isset($_GET['gclid'])){ if ($_SERVER['REQUEST_URI'] != "/location/".$row_getlocation['location_id']."/".$row_getlocation['location_seo_name']."/?gclid=".$_GET['gclid']) { header("HTTP/1.1 301 Moved Permanently"); header("Location: /location/".$row_getlocation['location_id']."/".$row_getlocation['location_seo_name']."/?gclid=".$_GET['gclid']); exit; } }else if (!isset($_GET['gclid'])) { if($_SERVER['REQUEST_URI'] != "/location/".$row_getlocation['location_id']."/".$row_getlocation['location_seo_name']."/") { header("HTTP/1.1 301 Moved Permanently"); header("Location: /location/".$row_getlocation['location_id']."/".$row_getlocation['location_seo_name']."/"); exit; } } thanks Lee
  7. Hi Im building a platform which uses the $_SERVER['server_name'] as the unique identifier to access the database record. It allows for www.a.com, www.b.com or www.c.com to access the same database and file system but depending on what the url is...displays different information. Im wondering what the security risks are in doing this? Should i be doing a reverse lookup on specified nameservers to check its a valid domain name? thanks Lee
  8. I have an array ($hotels) which contains hotel ids. I want to be able to pass all the variables into one variable ($arrayvalues) in the following format hotel_ids=34505,34625,34655,34672,34753,34787,34903,35288,35329,35426 $hotels = array(); $y=0; do { if($y==$totalRows_getHotels-1){ array_push($hotels, ",".$row_getHotels['Hotel_Id']."&"); }elseif ($y==0){ array_push($hotels, "hotel_ids=".$row_getHotels['Hotel_Id'].""); }else{ array_push($hotels, ",".$row_getHotels['Hotel_Id'].""); } $y++; // echo $y; } while ($row_getHotels = mysql_fetch_assoc($getHotels)); I've tried looping through like this to output the values: foreach($hotels as $value){ echo $value; } but it only outputs the last value. I want to be able to pass all the values through to a url like this $url = "http://www.getmyhotels.com?hotel_ids=".$arrayvalues."&arrival_date=".$newcheckin."&departure_date=".$newcheckout."";
  9. Google has a method for logging events in its analytics callex Event Tracking i have successfully installed it using onClick events but i was wondering how i could incorprate it into a PHP if statement for example pageTracker._trackEvent onlclick="pageTracker._trackEvent('Search', 'Post', '22f2c435817f70fdc0b3432586a6b4e8')" thanks Lee
  10. ah ha!...legend! as you said i wasn't printing out the right part of the array! 2 worked! Lee
  11. Im trying to match a title tag but can;t seem to case match just the word title on both sides. i've tried it with / at the beginning and /i at the end which kind of works in that it will match the tag but includes the whole title tag in the variable using preg_match instead of just the title tag text /(<title>(.*)<\/title>)/i This one works but it won;t match case // get title $pagetitle = preg_match("(<title>(.*)<\/title>)", $file, $t); $title = $t[1]; Thanks Lee
  12. thanks for that... i still couldn;t get it to work but i found this one... (<meta[\s]+[^>]*?name[\s]?=[\s\"\']description[\s\"\']+content[\s]?=[\s\"\']+(.*?)[\"\']+.*?>) which seems to work well. I'm also trying to get the title tag contents which is working but it won;t find capital versions or with encoded HTML...this is what i have $pagetitle = preg_match("(<title>(.*)<\/title>)", $file, $t); $title = $t[1]; this is the tag it won't process <TITLE>MySite- bla bla &#038; reviews about stuff</TITLE> thanks Lee
  13. I'm trying to extract the Meta Description content using REGEX but its giving me some trouble. It will find the content=" and echo that out but can;t seem to get it to get the end part of the tag which could include " /> or "> or "/> i have got ((\b\"(.)>\i*)) . I have been using this tool http://www.gskinner.com/RegExr/ which rocks! <?php function strip($file, $start_mark, $end_mark){ $start = strpos ($file, $start_mark); $end = strpos ($file, $end_mark, $start); $text = substr ($file, $start, $end - $start); $text = str_replace ($start_mark, '', $text); $text = str_replace ($end_mark, '', $text); return $text; } $file = file_get_contents($_GET['url']); // get the description $desc = preg_match('(\<(/?meta name="description"[^\>]+)\>)', $file, $fulldesc); //echo "Match Content:<br/><br/>".$dstart[1]."<br/><br/>"; echo $fulldesc[1]; //get the title $descstart = preg_match("((\bcontent=\"\i*))", $fulldesc[1], $dstart); echo $dstart[1]."<br/>"; $descend = preg_match("((\b\"(.)>\i*))", $fulldesc[1], $dend); echo $dend[1]."<br/>"; $description= strip($fulldesc[1], $dstart[1], $dend[1]); echo "This is the match:<br/><br/> $description";
  14. Thanks Wolfrage, i added sleep(15); after the ftp_close but its still having the same problem... // try to login if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) { echo "Connected as $ftp_user@$ftp_server\n"; do { $newch = '0'.$row_getFiles['file_chmod']; if (ftp_chmod($conn_id, eval("return({$newch});"), $row_getFiles['file_name']) !== false) { echo "CHMOD successfull on ".$row_getFiles['file_name']." to ".$row_getFiles['file_chmod']."<br/>"; } else { echo "Could not CHMOD ".$row_getFiles['file_name']." to ".$row_getFiles['file_chmod']."<br/>"; } }while ($row_getFiles = mysql_fetch_assoc($getFiles)); ftp_close($conn_id); sleep(15); regards Lee
  15. Im trying to change permissions on files on multiple ftp connections I have a database of file names that i want to change and a list of domains to step through with the corresponding connection details (their all on the same server). Its processing the first connections files perfectly but when it comes to the next step in the loop (and the rest) its saying Warning: ftp_chmod() [function.ftp-chmod]: User myusername logged in in /var/www... above where it says User myusername logged in, it is the right username but is it somehow referencing the previous session somewhere? here's the code do { $ftp_server = "1.1.1.1"; $ftp_user = $row_get['ftp_username']; $ftp_pass = $row_get['ftp_password']; // set up a connection or die $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); // try to login if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) { echo "Connected as $ftp_user@$ftp_server\n"; do { $newch = '0'.$row_getFiles['file_chmod']; if (ftp_chmod($conn_id, eval("return({$newch});"), $row_getFiles['file_name']) !== false) { echo "CHMOD successfull on ".$row_getFiles['file_name']." to ".$row_getFiles['file_chmod']."<br/>"; } else { echo "Could not CHMOD ".$row_getFiles['file_name']." to ".$row_getFiles['file_chmod']."<br/>"; } }while ($row_getFiles = mysql_fetch_assoc($getFiles)); } else { echo "Couldn't connect as $ftp_user\n"; } ftp_close($conn_id); echo "<b>- - - - - - - - - - - - -</b><br/>"; }while ($row_get= mysql_fetch_assoc($get)); } ?>
  16. Hi thanks for the reply... ok here's the actual code...i thinned it out a bit previously thanks lee # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_city_system = "localhost"; $database_city_system = "dbname"; $username_city_system = "username"; $password_city_system = "password"; $city_system = mysql_pconnect($hostname_city_system, $username_city_system, $password_city_system) or trigger_error(mysql_error(),E_USER_ERROR); // get all the details of the databases that need updating mysql_select_db($database_city_system, $city_system); $query_getSpecCity = "SELECT * FROM tbl_city"; $getSpecCity = mysql_query($query_getSpecCity, $city_system) or die(mysql_error()); $row_getSpecCity = mysql_fetch_assoc($getSpecCity); $totalRows_getSpecCity = mysql_num_rows($getSpecCity); if ($_GET['run'] == "go") { do { // get specific sites database details $hostname_get_city = "localhost"; $database_get_city = $row_getSpecCity['city_db_name']; $username_get_city = $row_getSpecCity['city_db_username']; $password_get_city = $row_getSpecCity['city_db_password']; $get_city = mysql_pconnect($hostname_get_city, $username_get_city, $password_get_city) or trigger_error(mysql_error(),E_USER_ERROR); // $UpdateSQL = "ALTER TABLE `tbl_city` ADD `City_Via123AID` VARCHAR( 11 ) NOT NULL AFTER `City_AdsenseID` , ADD `City_Via123PCID` VARCHAR( 11 ) NOT NULL AFTER `City_Via123AID`"; mysql_select_db($get_city, $database1_get_city); $query_getCity = "SELECT * from tbl_hotels"; $getCity = mysql_query($query_getCity, $get_city) or die(mysql_error()); $row_getCity = mysql_fetch_assoc($getCity); $totalRows_getCity = mysql_num_rows($getCity); // update successful echo $row_getSpecCity['City_URL']." Updated<br/>"; echo $totalRows_getCity; unset($hostname_get_city); unset($database_get_city); unset($username_get_city); unset($password_get_city); unset($get_city); unset($query_getCity); unset($row_getCity); unset($totalRows_getCity); unset($query_getCity); }while ($row_getSpecCity = mysql_fetch_assoc($getSpecCity)); }
  17. Im trying to connect to multiple local databases to run updates but on completing the first run ok (and occasionally the second run) it hangs saying: Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/mywebsite/httpsdocs/SQLUpdate.php on line 58 Site 1 Updated Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/mywebsite/httpsdocs/SQLUpdate.php on line 58 No database selected Im pretty sure its something to do with unsetting variables before the next run?? This is how it works at the moment: Primary Query here to get all the database settings, username passwords etc $query_getSpecCity = "SELECT * FROM database settings table"; do { // get specific sites database details $hostname_get = "localhost"; $database_get = $row_getSpec['name']; $username_get = $row_getSpec['username']; $password_get = $row_getSpec['password']; $get = mysql_pconnect($hostname_get, $username_get, $password_get) or trigger_error(mysql_error(),E_USER_ERROR); // $UpdateSQL = "THIS WILL BE MY QUERY TO ALTER UPDATE ETC"; // update successful echo $row_getSpecCity['City_URL']." Updated<br/>"; echo $totalRows_getCity; unset($hostname_get_city); unset($database_get_city); unset($username_get_city); unset($password_get_city); unset($get_city); unset($query_getCity); unset($row_getCity); unset($totalRows_getCity); unset($query_getCity); }while ($row_get = mysql_fetch_assoc($get)); } thanks Lee
  18. ah ha...ive briefly tested it and it looks to be doing what i had hoped...much appreciated. Lee
  19. Hi Im trying to loop through an XML file which has 3 PrimaryCategories unlimited CategoryList and unlimited EventList The code below works to a degree in that it will loop through all the elements but it pulls out the same category and event data each time instead of skipping onto the next category List This is what i have so far: <?php $s = simplexml_load_file('../events.xml'); // 3 primary categories foreach ($s->PrimaryCategory as $PrimaryCategory) { foreach ($s->PrimaryCategory->CategoryList as $CategoryList) { foreach ($s->PrimaryCategory->CategoryList->EventList as $EventList) { print $EventList->EventID . $EventList->EventName ."</br>"; } unset($EventList); } unset($CategoryList); } unset($PrimaryCategory); ?> This is the XML format <VLinks> − <PrimaryCategory> <PrimaryCategoryID/> <PrimaryCategoryName/> <PrimaryCategoryURL/> − <CategoryList> <CategoryID/> <CategoryName/> <CategoryURL/> <CategoryImageURL/> <CategoryDescription/> − <EventList> <EventID/> <EventName/> <EventDate/> <EventURL/> <VenueName/> <VenueCity/> <VenueAddress/> <VenueState/> <VenueCountryCode/> <VenuePostCode/> <MinCurrentPrice/> <MaxCurrentPrice/> <TicketCount/> <PresaleDate/> <OnSaleDate/> <SoldOutDate/> </EventList> </CategoryList> </PrimaryCategory> </VLinks> The problem at the moment is the results look like... 186991Billy Elliot - The Musical 186992Billy Elliot - The Musical 186993Billy Elliot - The Musical 186994Billy Elliot - The Musical 186995Billy Elliot - The Musical 186996Billy Elliot - The Musical 186997Billy Elliot - The Musical 186998Billy Elliot - The Musical 186999Billy Elliot - The Musical 135279Billy Elliot (Matinee) 135280Billy Elliot (Matinee) 135281Billy Elliot (Matinee) 135282Billy Elliot (Matinee) 135283Billy Elliot (Matinee) 135284Billy Elliot (Matinee) 135285Billy Elliot (Matinee) 135286Billy Elliot (Matinee) 135287Billy Elliot (Matinee) 135288Billy Elliot (Matinee) 135289Billy Elliot (Matinee) 135290Billy Elliot (Matinee) thanks Lee
  20. Hi I have an XML parser which works fine if the XML file is flat but i cant get it to work when i want to loop through one particular node. For example below there are 3 category ID's each with an unlimited number of events (EventsList) in each...i want to get these in my database but can only get the parser to loop through the top level This is te XML format <TopLevel> <PrimaryCategory> <PrimaryCategoryID></PrimaryCategoryID> <PrimaryCategoryName></PrimaryCategoryName> <PrimaryCategoryURL></PrimaryCategoryURL> <CategoryList> <CategoryID>1</CategoryID> <CategoryName></CategoryName> <CategoryURL></CategoryURL> <CategoryImageURL></CategoryImageURL> <CategoryDescription></CategoryDescription> <EventList> <EventID></EventID> <EventName></EventName> <EventDate></EventDate> <EventURL></EventURL> <VenueName></VenueName> <VenueCity></VenueCity> <VenueAddress></VenueAddress> <VenueState></VenueState> <VenueCountryCode></VenueCountryCode> <VenuePostCode></VenuePostCode> <MinCurrentPrice></MinCurrentPrice> <MaxCurrentPrice></MaxCurrentPrice> <TicketCount></TicketCount> <PresaleDate></PresaleDate> <OnSaleDate></OnSaleDate> <SoldOutDate></SoldOutDate> </EventList> </CategoryList> </PrimaryCategory> </TopLevel> This is my parser $xmlFeed = "../../xml/events.xml"; $data = @implode("",file($xmlFeed)); $parser = xml_parser_create(); xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); xml_parse_into_struct($parser,$data,$d_ar,$i_ar); xml_parser_free($parser); /** * The XML data is broken up into the two arrays, * $d_ar and $i_ar, now we can loop through * the arrays to display the data on our website: */ for($i=0; $i<count($i_ar['CategoryList']); $i++) { if($d_ar[$i_ar['CategoryList'][$i]]['type']=='open') { for($j=$i_ar['CategoryList'][$i]; $j<$i_ar['CategoryList'][$i+1]; $j++) { /** * Assign the data to a variable; * to include more tags, add extra elseif statements */ if($d_ar[$j]['tag'] == 'EventID'){ $eventid = mysql_real_escape_string($d_ar[$j]['value']); }elseif($d_ar[$j]['tag'] == 'EventName'){ $eventname = $d_ar[$j]['value']; }elseif($d_ar[$j]['tag'] == 'EventDate'){ $date = $d_ar[$j]['value'];; $datesplit = explode("T", $date); echo $datesplit[0]; // piece1 echo $datesplit[1]; // piece2 }elseif($d_ar[$j]['tag'] == 'EventURL'){ $eventurl = $d_ar[$j]['value']; }elseif($d_ar[$j]['tag'] == 'VenueCity'){ $venuecity = $d_ar[$j]['value']; }elseif($d_ar[$j]['tag'] == 'MinCurrentPrice'){ $mincurrentprice = $d_ar[$j]['value']; }elseif($d_ar[$j]['tag'] == 'CategoryDescription'){ $categorydescription = $d_ar[$j]['value']; } // --- Build the rows --- mysql_select_db($database_system_conn, $system_conn); $query_doEventCheck = "SELECT * FROM tbl_events WHERE event_id = $eventid"; $doEventCheck = mysql_query($query_doEventCheck, $system_conn) or die(mysql_error()); $row_doEventCheck = mysql_fetch_assoc($doEventCheck); $totalRows_doEventCheck = mysql_num_rows($doEventCheck); ///////////////////////////////////////////START INITIAL INCLUDE IF DOESNT EXIST if ($totalRows_doEventCheck == 0) { $insertSQL = " INSERT INTO `tbl_events` ( `event_id` , `event_genID` , `event_name` , `event_category` , `event_desc` , `event_price` , `event_dateStart` , `event_dateEnd` , `event_timeStart` , `event_timeEnd` , `event_location` , `event_geocode` , `event_url` , `event_tel` , `event_email` , `event_approved` , `event_uniqID` ) VALUES ( '$eventid', '', '$eventname', 'cat000', '$categorydescription', '$mincurrentprice', '".$datesplit[0]."', '".$datesplit[0]."', '".$datesplit[1]."', '', '$venuecity', '', '$eventurl', '0000000000', '', '1', '".mt_rand(10000, 10000000000)."' )"; mysql_select_db($database_system_conn, $system_conn); $Result1 = mysql_query($insertSQL, $system_conn) or die(mysql_error()); echo "$eventname added <br/><br/>"; }else{ echo "$eventname already exists<br/><br/>"; } } } } Thanks for your help Lee
  21. I have this query, its a bit more complex than what's written below but it returns over 1000 rows of data and on using ORDER BY RAND() is hundreds of time slower than the other queries running in the system. I want to remove the ORDER BY RAND() function which will return 3 results. I then want to run another query with a specific ID from the returned results set. Will this speed up the query as its not using ORDER BY RAND(). I guess what im trying to say is how do i randomly select a row from a results set? mysql_select_db($database_system_conn, $system_conn); $query_getFeaturedBusiness = "SELECT ID FROM Business WHERE Status = 1 ORDER BY RAND()"; $getFeaturedBusiness = mysql_query($query_getFeaturedBusiness, $system_conn) or die(mysql_error()); $row_getFeaturedBusiness = mysql_fetch_assoc($getFeaturedBusiness); $totalRows_getFeaturedBusiness = mysql_num_rows($getFeaturedBusiness); thanks Lee
×
×
  • 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.