Jump to content

DarkElf

Members
  • Posts

    103
  • Joined

  • Last visited

Everything posted by DarkElf

  1. DarkElf

    Array help

    to delete a variable, array, or just one part of an array you can use the unset function: unset($array['key'])
  2. Try putting the menu within a div with set width (which should be just wide enough to incorporate all the menu elements), that means when the users resizes the window to smaller than the width the body of the page stays wide enough to keep all the elements inline (i.e. they'll get a scroll bar at the bottom instead of the page resizing to fit the new window width)
  3. Doh!Spent days struggling with the problem.... finally resort to spending about 30 mins writing it out in detail here for some help.... and guess what?No more than a few minutes after I've finished typing do I spot my error!The file get contents line of that last code block should have read as follows:$filecontent = file_get_contents('../content/'.$file)Just goes to show how the tiniest mistakes can cause the biggest problems!
  4. DarkElf

    Array help

    Sounds like a fun one.I'm assuming you know the basics of manipulating arrays, e.g. you can modify the value of key called key1 in an array called array by doing this: $array['key1'] = value If that key doesn't exist then that statement will create it.Now for the complicated bit:If you're using numeric keys then you could load the array and count the number of keys, then add the new key with a numeric identifier of that number (note you don't need to increment it because default numeric keys start from 0 not from 1). Does that make sense and/or help? Sorry I don't have time to work out the code for it right now. If you're still stuck and no-one else comes to your aid I'll try and work it out. I think there is a function that will count the number of terms stored in an array for you but i can't recall it off the top of my head.
  5. This is going to take a while to explain, but here goes;I'm building a basic content management system which works something like this; There is a single file called page.php which contains a template for the users website. When someone browsing the site opens a page it calls page.php and supplies it some variables which it uses to add the content of that particular page to the template, the content is stored in files in a folder called 'content'.Here's an example, the user calls index.php which looks something like this: <?php//set variables$page = index;//call page.phpinclude ('page.php');?> page.php looks a little like this: Some irrelevant html<?php//add content of page$content = file_get_contents('content/'.$page);echo $content;?>Some more irrelevant html content/index is just a file of no defined type that contains nothing more than text.So far this all works wonderfully, now onto the content management bit. There is another folder called 'cms', in which the content management system lives. The structure of the pages works almost identically to the users site, except the content is added to each page by an include statement instead of file_get_contents, this is so I can include some php in the page content.There is a page called update.php which contains a text area, based upon variables passed to it a php script should open and print one of the content files such as the example above, the user can the modify the content of this text area and submit it to another page for processing. The variable which calls the content of the text area is passed in a different way here because obviously i don't want a php file in my cms for every page in the user site, instead it is passed using a query string (e.g. ?index is added to the end of the url), i've checked and this is being passed correctly. Here's what should happen, bear in mind that update.php is located in the directory root/cms/ where root is the location of the users website.1. user goes to www.mywebsite.com/cms/update.php?index2. update.php calls page.php and passes it the $page=update variable (note that this is page.php for the cms and is in the cms directory not the page.php file for the users website).3. page.php calls content/update4. content/update contains a text area which contains the following code to load the index content file: <?php//get $file variable$file = $_SERVER['QUERY_STRING'];//get contents of file$filecontent = file_get_contents('../../content/'.$file);echo $filecontent;?> It should work, I can't find any holes, but there is an error on the file_get_contents line:Warning: file_get_contents(../../content/index): failed to open stream: No such file or directory in /root/cms/content/updateWhy? What is wrong? I'm stuck.What is really annoying is that if I create a php file which should emulate update.php after all the includes have been performed it works like a charm. I know I've gone on a bit but if anyone manages to read through all of this then please let me know if you spot anything.
  6. See this topic:http://w3schools.invisionzone.com/index.php?showtopic=3440
  7. I'm assuming that your using cookies to keep track of logged in users? If so then if you don't set an expiration time the cookie will simply expire at the end of the session (when browser window is closed). Alternatively use php sessions as aspnet guy suggests.The latter is a bit more secure, all the information about a cookie is stored in the browser and can be modified by the user. In a PHP session the only information stored on the browser is the session ID, this identifies the session (i.e. an open browser window on one particular machine), all the other information (such as the fact that the user on that session is or isn't logged in) is stored on the browser in a temporary flat file. Your PHP can check and modify the settings of session variables in the same way it can with cookies, but scripts not executed on the server (javascripts etc) can't see the session variables (unless you pass them back to the browser in your script, something you may occasionally want to do).Take a look at http://uk2.php.net/manual/en/ref.session.php for more info.
  8. Brilliant, that did the trick. Still don't understand why there was the problem, it's really wierd.
  9. Where it says int or string this is refering to the variable type of the following term, 'string comment' for example tells you that the data type you put at that point in the function is a string and 'comment' describes what it is. This is quite an advanced function which I admit I have no idea how to use - you need to go to the manual at php.net and work it out. Remember that PHP, as with all things, is best learnt from the ground up. If the information on the manual makes no sense to you then you are probably starting way to deep and need to go back and learn the basics properly first.
  10. DarkElf

    request forms

    Why not write your own script for dealing with the email? You'll need to learn some server side scripting, PHP has a function specifically designed for sending emails so that might be a good place to start. If you search the PHP forums you should find lots of helpful posts already there as this is a very common question.
  11. This is a bit of a strange one for me, normally I to find that most of my browser specific CSS problems relate to divs appearing in strange places in firefox (not that I don't love Firefox - just that it tends to be more fussy than IE). However today I have discovered something that is working beautifully in Firefox (and Netscape & Opera) but doesn't work in IE.I've got a div which spans the top of the page and contains menu links to the left hand side, there is also a help link which appears at the very other end of the div. Here's the code:HTML: <div id="menu"><p style="float: right"><a href="help.html">Help</a></p><p><a href="page1.html">Page 1</a> | <a href="page2.html">Page 2</a> | <a href="page3.html">Page 3</a></p></div> CSS: /* Typography */body {font-family: arial;}p {font-size: 10pt;}a {text-decoration: none;}/* Layout */body {margin: 0px; padding: 0px;}div#menu {height: 15px; margin: 0px; padding: 8px;border-top: 2px solid white;}p {margin: 0px;}/* Colours */body {background-color: #FFFFFF;}div#menu {background-color: #95B3DE;}a {color: #FFFFFF;}a:hover {color: #000000; background-color: #D6DEEC; border: 1px solid black;} As you can see, the hyperlinks should (in theory) change color and have a border around them on hover. This works exactly as it should for the links on the left, but the link on the right doesn't display the border on the top or bottom (but does to either side). I can't work it out, especially as it works in every other browser I have tried. Any ideas?
  12. great minds think alike
  13. brilliant, thanks very much.
  14. I'm not seeing entirely how that helps?I do have a kind of idea though. The script at the minute takes the string passed to it, strips slashes, and writes it to a file which is later opened by another page to display the content. The strip slashes is required because on some servers the magic quotes function might be enabled (and i want the script to be easily portable). If magic quotes is enabled it works fine because this escapes user inputted slashes, the problem occurs when its on servers where magic quotes isn't enabled because it strips user inputted slashes which haven't been escaped by magic quotes.I think what i need is some code to test the server to see if it is running magic quotes and then it can decide to perform stripslashes if required. Is there a way I can do this?
  15. ok, here's a new predicament (but part of the same problem).I've been dealing with reserved characters, for instance "<" and ">". Obviously if the user were to incorporate those into their text it would cause some problems, therefore when the back-end writes the file it's replacing each of those (and some others) with the relevant alias. That bit works fine, but what I've now spotted is a similar kind of problem with backslashes.Because of the magic quotes feature (grrrrr) i've had to perform stripslashes on the string before it is written to the file. If the user incorporates backslashes though they are unfortunately lost I know I can disable magic quotes by putting a flag in the .htaccess file, in which case I could remove the stripslashes function, but I'm trying to avoid that so as to maximise the ease of portability of my code.Any ideas as to how I can get around this?
  16. DarkElf

    HTML refresh

    That line refreshes the browser loading that page every 5 seconds, fairly simple really.
  17. I've been working on a basic content management system for a while, so far it as simply been an online interface which users can use to directly alter the html of the pages. I'm now trying to make it a bit cleverer, the idea is that text for a certain area of the site is taken from a txt file, the user modifies the txt file using the interface. The back end bit works fine but I'm having problems reproducing the data at the front end.If the user only wants one paragraph then there is no problem, you could just use the code: <p><?php //include contentsinclude ('content.txt');?></p> But if the user wants to include new lines or paragraphs it has to be a bit more complicated. Instead of including the file you need to open it and write it to a string and then perform the string replace function to replace all occurances of "\n" (php's delimiter for a new line) with "<br />". Here is my attempt: <p><?php //Open content file$fp = fopen ('content.txt','r');//Write contentswhile (!feof($fp)) { $print = fgets($fp, 999999); //add <br /> tags $print = str_replace("\n","<br />",$print); echo $print; }fclose($fp);?></p> All nice in theory, except it doesn't work. When it gets to a new line it puts in the "<br />" tag and then stops reading the file. If the content.txt file is this: Test line oneTest line two the output on my page is this: <p>Test line one<br /></p> What is really annoying me is that at one point I managed to get it to work perfectly, then I tried adding a few extra lines of code for some further functionality and it stopped working! I've taken those lines back out again but I've obviously missed something as it no longer behaves how it did before! Any ideas?
  18. Nope, I don't have that line, I guess that would be the problem. I'm a bit confused about which charset to use? I notice a lot of pages use that iso one, though the number isn't always the same.
  19. DarkElf

    HTML Certificate

    You can't really learn webdesign without practising it. Go build some websites (even it they are stupid and random) testing out the skills you've read about. It will all make far more sense and you'll remember it much better if you've put it into action. Think about it - what's the exam really about, whether you can answer a few questions or whether you can build a website?
  20. try setting the background elements size in 'em' units. 1 em is the space of one character, so if the font size changes your element will change to fit!
  21. When I validate my pages using the w3c validator they always pass 'tentatively', and I get the following warning:No Character Encoding Found! Falling back to UTF-8.I was not able to extract a character encoding labeling from any of the valid sources for such information. Without encoding information it is impossible to reliably validate the document. I'm falling back to the "UTF-8" encoding and will attempt to perform the validation, but this is likely to fail for all non-trivial documents. I've searched and searched and can't workout what this is about! I've tried comparing my pages to other pages which validate without this error and can't see what I'm missing! Can anybody enlighten me?
  22. No, as far as I am aware there are no languages that can be used for both server side and client side scripting and php certainly can't, it is only a server side script. The biggest benefit of php is that onced parsed on the server it is removed from the html sent to the browser, this makes your sites clean and secure :)For client side scripting your best option is javascript, unlike the the rivalry found between php and asp, client side scripting is dominated by javascript and thus it is fully supported by all the main browsers.Your comments have made me wonder though.... wouldn't it be nice if someone wrote a client and server side script that both used the same syntax.....
  23. The problem with the w3schools tutorial, along with most other tutorials you will probably find, is that it isn't really much more than eloborated function reference. It explains the basics of what php is and explains how to use a few functions, giving one or two basic examples, but it is very hard to see from there how you might usefully use php in your webpages!I learn't most of my PHP through this book:http://www.samspublishing.com/title/0672326728It's actually written for teaching advanced techniques for integrated PHP and MySQL powered websites, but the first section is about 150 pages just on PHP that will bring you up to scratch so that you can understand the rest of the book even if you've never used PHP before. The strong point about the book is that there is a real emphasis on demonstrating actual practical uses of everything you are being taught, it teaches you PHP by guiding you through the production of a website using much more complicated examples than on any online tutorials I've find, this allows you to see useful applications of php in practice which makes it much easier to understand how you can usefully implement php in your own pages!Just to give you an example - 2 months ago I didn't even understand what php is, so far I've only worked through the first section but I've already managed to use the skills I've learnt from it to build my own basic flatfile content management system.I know this doesn't quite answer your question but I found that it was a really good place to start for me, and if you do have questions after this then you will find that there are loads of really helpful and experienced people on these forums who are always happy to help.
  24. DarkElf

    variables

    Douglas' example is probably the easiest way to do it. I had a page in which I wanted to do pretty much exactly the same as you are and used sessions for it.The really good thing about the session variable is that you don't need to keep passing it from one page to another, once set it remains set until you either unset it or the session ends. It is also open to any page or script that looks for it, unlike post which is only available on the page it is submitted to.The session ends when the user closes the browser window, rather like post variables or cookies the session variable is stored in the users browser, the difference is when the variable ends (cookies can last for variable lengths of time, they can expire at the end of the session, they can expire after a fixed window of time, or they can last forever. Post variables on the other hand only last whilst the page that uses them is open).
×
×
  • Create New...