-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Output Database Content To Csv With Php - Special Characters!
kicken replied to MatthewNLane's topic in PHP Coding Help
There is an example of fputcsv over in a previous post of mine. It is a very easy and worthwhile function to use. Makes CSV exports a snap.- 5 replies
-
- csv
- special characters
-
(and 2 more)
Tagged with:
-
Flaw In Php's Namespace, Cannot Import An Entire Namespace,
kicken replied to Hall of Famer's topic in Miscellaneous
No, you only have to write one line like this: use \Model\User; Then when you use those classes, do: new User\Member or new User\Admin There are a lot of people who frown upon using an import * statement and suggest you should be explicit just like PHP forces you to be. By doing so it makes it easier to see where exactly a particular class comes from. As you said what if you're importing a bunch of namespaces into your controller, eg import Blah.*; import Bleh.*; import Foo.*; import Bar.*; then later on you do something like: meh = new Meh(); What namespace is Meh from? Dunno, gotta go search the docs to try and fine out. With PHP, or if you import selectively you'd know right from the code where it comes from. -
Write And Erase Contents Of A File After A Length Of Time Has Expired
kicken replied to rad1964's topic in PHP Coding Help
file_get_contents - Read the file json_decode - Decode the json stored in the file. Whenever you add an alert to the array of alerts, you add a date indicating when it should expire. Check that date against the current date whenever you read the alerts to see if it has expired. If so, remove it. time - Get current date foreach - Loop the alerts unset - remove an alert json_encode - Encode the alerts array as json data file_put_contents - Save the data to a file -
Fatal Error Call To A Member Function Prepare() On A Non-Object
kicken replied to mostafatalebi's topic in PHP Coding Help
You never assign your class's _connect variable. This line: if(!$_connect = new mysqli($host, $user, $pass, $database)) should be: if(!$this->_connect = new mysqli($host, $user, $pass, $database)) -
The name parameter should not contain any spaces or special characters. window.open('feeds.html', 'rssfeed', 'width=800,height=800') Also, this would be a better way of coding it which will allow the link to work still even if JS is disabled: <a href="feeds.html" onclick="return !window.open(this.href, 'rssfeed', 'width=800,height=800')">
-
You're not selecting which database to use. Your DSN should look like: "mysql:host=$host;dbname=$mysql_database"
-
Just add a static column to the select list. Also, don't use SELECT *, especially with a union. If you ever add an additional column to one of those tables, or the column order does not match exactly the whole query will break. List out the specific columns you need. SELECT 'ban' as type, col1, col2, col3 FROM bans WHERE player = '$search' union all SELECT 'kick' as type, col1, col2, col3 FROM kicks WHERE player = '$search'
-
If you make sure the only Listen directive is Listen 127.0.0.1:80 Then that should work to prevent anyone from connecting. That would cause apache to listen on a socket that only accepts connections from 127.0.0.1. Setting up appropriate firewall rules would be a good option too.
-
Why Won't A Page Load When Using Mobile Network ?
kicken replied to vincej's topic in PHP Coding Help
Would you be able/willing to provide a URL to the page for us to test with? Without being able to see the problem all we could do is speculate which is a bit pointless. -
From what I understand reading the docs, if you use PARAM_LOB, then the variable is supposed to be a stream resource (ie, fopen() or similar) rather than just the raw data. So the code would end up looking something like this: switch($v[1]){ case 'LOB': if (!is_resource($v[0])){ $fp= tmpfile(); fwrite($fp, $v[0]); rewind($fp); $v[0] = $fp; } $sth->bindValue(':' . $f, $v[0], PDO::PARAM_LOB); break; That will open a temporary file to write the variable data too. When the script finishes the file will be automatically deleted.
-
You could check whether the $_SERVER['REQUEST_URI'] points the file or not. If it does have the script exit; possibly with an error message. Another common and relatively easy thing to do is have your main files define a constant which you then check for in your other files. Example: index.php: <?php define('PROPER_REQUEST', true); include('buddy_list.php'); buddy_list.php <?php if (!defined('PROPER_REQUEST')) die("Invalid Request."); //... rest of script
-
You need to include the directory along with the filename when you try and open the file, since you're reading the files from a different directory. Because your script is located at /home/a6125536/public_html/gallery.php, when you are doing imagecreatefromfile($file) (where $file=emmaus001.jpg) it is going to try and locate that file at /home/a6125536/public_html/emmaus001.jpg. That of course is not the correct location. The correct way to try and access the file would be: $src = imagecreatefromfile("images/gallery/$file"); You would need to include the directory in any other places where you're trying to reference the file as well (ie, your other imagecreatefrom* lines).
-
You're using the wrong variable name. You're using $REMOTE_ADDR, but should be using $_SERVER['REMOTE_ADDR']: $mailnachricht.="\nDatum/Zeit: ". date("d.m.Y H:i:s"); $ip=@$REMOTE_ADDR; echo "<input type='hidden' value='$ip' />"; If you would have not used the error-suppression operator, you would have gotten a big fat E_NOTICE error telling you that.
-
Just move the excel stuff to the same page as your current search form, then branch based on whether you want to output for excel or output the html results. Eg: <?php ///do all your ///query stuff here if (isset($_GET['action']) && $_GET['action']=='download'){ //Do excel output } else { //Do HTML output } Then for the download all you would do is re-submit the form but with an extra action=download option.
-
All your check's to see if they read the file should be done server side. As you've described it, someone could just disable javascript to bypass all your checks and use the site anyway. What you need to do is in your server-side scripts after checking the login, check if they have read the required documents. If not, redirect them to the page to read them where they can then click a button at the bottom of the page to acknowledge having read it.
-
swap the order of your require statements. You have to define the redirection class before you can extend it.
-
11.2. Numeric Types
-
What's The Advantage Of Google Cache For... Google?
kicken replied to Shizuka's topic in Miscellaneous
As part of the indexing process they do for the web search. If I am remembering properly what I had read, google's crawler bots only download and save the pages, they do not do any of the indexing work as far as extracting key words and ranking pages. All that is handled by a separate process. So the process goes a little something like: 1) Crawler bot downloads a page from the internet. 2) Crawler bot saves the downloaded file to the disk somewhere 3) Crawler bot adds that file to the indexer's queue. 4) crawler bot repeats the process from step 1. So there are several crawlers all doing nothing but downloading files from the internet and saving them somewhere to be processed later by the indexer. The indexer works off a queue type system where it goes though each file in the queue, extracts all the key words, ranks the page using an algorithm, finds links to follow, etc. Once the indexer is done processing a file they basically had a choice between deleting it or keeping it. Deleting it would free up space, but by keeping they can then offer that cache service as an extra feature for relatively little investment on their part. -
You probably need to install an onsubmit handler for your form that copies the text out of the nicEdit editor and puts it into your textarea. When you do a rich-text editor the user is not actually typing into the textarea. Instead they are modifying the contents of a dom element such as a DIV or something else. When they are done editing you have to read the contents of that element and put it into the textarea to submit it. TinyMCE, which is the only one I have really worked with, will do this for you automatically by adding an onsubmit handler to the form. nicEdit might not have that feature so you'd have to implement it yourself. You'll have to read the documentation for nicEdit to find out exactly how to do it.
-
What's The Advantage Of Google Cache For... Google?
kicken replied to Shizuka's topic in Miscellaneous
If you're talking about the 'Cached' link google has next to search results, allowing a searcher to pull up a copy of a page as of the last crawl, it's mostly a convinence feature for users. I seem to recall reading an article a long time ago about how they offered it mainly because it they were storing a copy of the page anyway, so why not let users see it. Offering the cached copy is good not only for end-users but possibly for site owners as well. From an end user perspective, it means they can still get the information they want even if the original site is down or slow. Users being able to get what they want means the users are more likely to continue using google. More users using google means more ad revenue for google. The investment google has to make to offer the "cached service" is relativly minimal. They already have to download and store the page anyway as a result of their indexing process, so all it really costs them is storage space and a minimal amount of development time to implement the feature. Storage space is fairly inexpensive compared to other operating costs, and the development time to add a "Cached" link is minimal and probably only a one-time investment. For site owners, having the cached content available on google means someone searching for something could still get to your content even if your site is currently down or running slow. Sure you may not get that single hit, but if the content is good a user may note your site and visit it again later when you're back up and running again. -
You would have some IP address (or list of addresses) that the user would have to setup their domain to point to. As an alternative, you could host their DNS for them so that you don't have to get them to setup all the CNAME/A records but instead just change the domain's NAMESERVER settings to point to yours. For example if you were running your setup on IP 10.0.1.1 (hostname sitesrv.example.com), you would have the user configure their DNS so that their A records for their domain point to IP 10.0.1.1 (or their CNAME records point to sitesrv.example.com). As for why places use a different set if IP's for their customer sites vs their own is due to keeping things separate. You wouldn't want a problem with a customers site causing issues with your own site, so you keep them as separate entities, likely on completely separate servers. If you're hosting lost of customers, you'll likely need to divide up the customers as well among several different machines/addresses, but there are a variety of ways to do that In the application code, when a request is received you would examine the Host: header ($_SERVER['HTTP_HOST'] in php) to determine which domain the request was sent to. With the domain name you can lookup in your database which user that domain name belongs. For the first case (http://example.com/username) you would examine the URI that was requested ($_SERVER['REQUEST_URI'] in php) to get the username. For example: if HTTP_HOST == 'example.com' then set username=REQUEST_URI else if HTTP_HOST == '*.example.com' then set username= HTTP_HOST - '.example.com' //username is the hostname, minus the .example.com part else { set username = result of database query where domain=HTTP_HOST } Once you have the appropriate user, you can display that user's content. If you're unable to find a user for the request, you could either display an error page, or just redirect the request to your homepage.
-
I doubt there is any difference worth worrying about between a for and a foreach loop. Probably the only real difference you might notice is that in a typical usage case, foreach() is going to create a copy of the source array, but even that would probably not cause much of a speed difference until you get into pretty massive array sizes. Use which ever one fits your needs best. If you just want to loop over every item in an array, a foreach() generally the best. If you need to loop through just a portion of an array, or need to keep a count as you loop the array for some reason (ie creating a numbered list output) a for loop may be better.
-
Connecting to the serial port on the arduino causes a reset. There are various ways to disable it if you do some google searching about it. Which one works best for you would depend on what your needs are.
- 16 replies
-
- script
- serial port
-
(and 2 more)
Tagged with:
-
So I did some playing around (I have an arduino) and aside from the previously mentioned problem with \r\n, the phpSerial class is not properly setting up the connection parameters. If you add a system('mode') after the deviceOpen call and find the port # the parameters are incorrect. In my case they were set to: Status for device COM3: ----------------------- Baud: 9600 Parity: Even Data Bits: 7 Stop Bits: 1 Timeout: ON XON/XOFF: OFF CTS handshaking: OFF DSR handshaking: OFF DSR sensitivity: OFF DTR circuit: OFF RTS circuit: ON Which ended up causing the character 'L' to be ready by the arduino as byte 207 rather than byte 76 like it should have been meaning the if statement never triggered to turn the light on. Setting the parameters myself rather than through the class, and removing the \r\n, corrected the issue: exec('mode COM3 BAUD=96 PARITY=n DATA=8 STOP=1 xon=off octs=off rts=on'); $serial->deviceOpen();
- 16 replies
-
- script
- serial port
-
(and 2 more)
Tagged with: