Jump to content

CStrauss

Members
  • Posts

    52
  • Joined

  • Last visited

Everything posted by CStrauss

  1. Well they both have to do with classes so there is a class called POP3 and what the first line is doing is setting a new instance of that class called $pop3.Now in the second line its calling a function inside that POP3 class and storing the value in a variable called $status.Basicly classes are used so you dont have to retype code over and over, so what you do is make an instance of that class and use the functions defined in the class such as it doing in your above code. I hope that clears it up a bit. But if your just learning you might want to get the basic down before you dive into classes and it should make more sense.
  2. I'm back with another question to for my latest idea not sure if this is possible or a good thing to do but in my case it seems logical.Here is what Im doing I got a table that allows people to add a category to it. Now from that I want to count the number of rows in the table which represent a category. In my example I have 8 rows so I want to generate a case for each of the rows represented in the database.So in my category table like i said i have 8 records.Cat1Cat2Cat3Cat4 and so on.Now lets say on category.php page is my switch statement and in the default case it displays a set of links with the req value the category name like this <a href="category.php?req="Cat1">Cat1</a> Still Following me?Okay now when they click a link it takes them to the switch part of the script and from here I need to count the number of rows in the table (since the user can add as many categories as the wish this is an unknown number) and loop through the category table and make a case for each of the categories. ie case "Cat1": case "Cat2": etc until all the categories in the databasse have a case then exit the loop and then the default case is next.Now i know how to do the sql count and the while loop to loop through the records just not sure where the best place to put my query to count the number of records and exactly how the syntax to make the cases will go. I usually start my cases off like this $req = (!isset($_REQUEST['req'])) ? 'default' : $_REQUEST['req'];switch($req){case:default:}// End switch should my record count be outside the first line of code then after the switch keyword have my loop to make the cases or should have it all after the switch statement?If anyone has done something similar to what im describing can you please post an example of how you did it. I cant seem to get my idea to work. Thanks sorry for the long post
  3. Okay I solved the problem of creating a caption for my articles. Basicly here is what I did: I first use the nl2br() function to create <br> tags between paragarphs.next I used strpos() to find the first <br> tagThen I stored that in a variable called caption concatentated between to <p> tags and there i got my caption to insert into my database using substr() with the varaible from the strpos as the length parameter.However I came across one problem to achieve my goal. I actually want to insert the article with <p> tags to seperate paragraphs rather then <br /> tags. This will make it easer to format with my css style sheets. Now i have a functions called br2nl i could convert <br> tags back to new line breaks. Im just not sure what the best string function to take the paragraphs between the nl breaks and put them between <p> tags.I notice when I use the strpos() to find the <br> it only return the position of the first <br> tag. So im thinking i could run it through a loop with the same concept i use before using strpos() variale as the starting point of the new paragraph of my article. Now if this will work I just need to find away to insert <p> tags at the beging and end of each paragraph. Would the str_replace() function be good for this since im not actually replacing any string in actuallity but just adding to a current string?Any other ideas or flaws in my theory you might see let me know. Keep in mind Im not good with regexps yet(still learning and have a few question to post on that topic another day). Thats all for now would appreciate some feed back on my theory?
  4. Here is an awsome link I found and use on pretty much every time i want to create an thumbnail image. Its a nice little tutorial that will give you a new weapon to add to your php arsenal. and is portable for any project meaning read the article and follow along with the tut and in the end you will have a code you can save and put in any project.imageresizing basicly it takes any image you upload at any size and converts it to a thumbnail of your size. Why is this so good you might ask? Well I found it saves alot of server space if you have alot of images you want to uplaod and instead of having two folders, one for thumb nails and one for full size images, or having two versions of the same image,again a thumbnail and full size image. You know only have to upload the full size image, and generate your thumbnail from that.Hope this helps
  5. Can you post some code so we can see what is going on. From the sound of it, it seems your getting the classic header error in which case your outputting information after the header has already been displayed. if you can post your code or a similar example of your code we might be able to see whats going on.
  6. Im creating an adminstration part of my site where I can ad new articles to my site by typing in a form my article and what Im looking for is a way to pull out the first paragraph of an article to display on my home page as a caption to the article then a link to read more.For this to work it has to be able to store html in the database i.e. the <p> so it knows how to parse out the first paragraph of that paragraph and store it in a varible to use. So if anyone knows of any online tutorials that cover these types of topics thats what im looking for at the momemnt so i can read up how it should be done and what not. Im sure there something out there that I just havent found on google yet. So if you know of one please post back a link for me.Thank you.
  7. Thanks justsomeguy that seemed to be it the md5 hash. Things seem to be working for now. Thanks for all your help now i got something new to play with and add to my php tool box. Now im just going to test and try to break it in everyway possible. Call me sick but thats the fun part to me after I write some code is trying everything possible to break it and get errors and what not. anyways thanks again.
  8. Okay after a few days of playing around with all this trying to make something easy for me to follow and understand I almost got.First I tested loging in with out choosing to set cookies and it works fine.Then I login in with cookies and it stores my cookies and sessions correctly.But when I close the browser and open it something goes wrong. My cookie info is still there but the session variables I need do not get stored so I will post all my work up to this point and hopefully someone can tell me what I need to change to make session varables be stored when someone returns to the site.my index page. session_start();session_name('2am-designs');header("Cache-control: private"); // Fix for IEinclude $_SERVER['DOCUMENT_ROOT'].'/inc/database.php';?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?php if(isset($_COOKIE['login'])){ $username = $_COOKIE['username']; $password = $_COOKIE['password']; $validate = @mysql_query("SELECT * FROM members WHERE username='$username' AND password = md5('$password')"); if(mysql_num_rows($validate) == 1){ while($row = mysql_fetch_assoc($validate)){ $_SESSION['login'] = true; $_SESSION['username'] = $row['username']; } // End While }// End If echo "Session username is set to ".$_SESSION['username']."<br />"; echo "Session Login in set to = ".$_SESSION['login']."<br />"; echo "Cookie Username = ".$_COOKIE['username']."<br />"; echo "Cookie Password = ".$_COOKIE['password']."<br />"; echo "Cookie Login Value = ".$_COOKIE['login']."<br />"; echo '<a href="/test/destroy.php">Destroy</a>'; }elseif(isset($_SESSION['login'])){ echo "Session username is set to ".$_SESSION['username']."<br />"; echo "Session Login in set to = ".$_SESSION['login']."<br />"; echo "Cookie Username = ".$_COOKIE['username']."<br />"; echo "Cookie Password = ".$_COOKIE['password']."<br />"; echo "Cookie Login Value = ".$_COOKIE['login']."<br />"; echo '<a href="/test/destroy.php">Destroy</a>'; }else{ ?><form action="validate.php" method="post"><p><label>Username</label><input type="text" name="username" /></p><p><label>Password</label><input type="password" name="password" /></p><p><label>Set Cookie</label><input type="checkbox" name="remember" /></p><p><input type="submit" value="Go!" name="submit" /></p></form><?php } // End Else ?></body></html> My Logic: if cookies where set it logs in user and and sets the session variables. In this case im outputting my variables to see they are there.(im paranode I know).If they dont have cookies set (the elseif) is checking to see if the member is logged on and displaying information that can only be seen if they are logged on. Meaning if they have been on surfing my site their info is there.And finally if they are not logged on to the site show them a form.**NOTE All ALL THE DESTROY LINK DOES IS DESTROY MY SESSIONS AND VARIABLES FOR TESTING PURPOSES.**Now here is my vaidation if they are logging on to the site for the first time or if they did not set cookies from a previous visit. <?phpsession_start();session_name('2am-designs');header("Cache-control: private"); // Fix for IEinclude $_SERVER['DOCUMENT_ROOT'].'/inc/database.php';$validate = @mysql_query("SELECT * FROM members WHERE username='{$_POST['username']}' AND password = md5('{$_POST['password']}')"); if(mysql_num_rows($validate) == 1){ while($row = mysql_fetch_assoc($validate)){ if(isset($_POST['remember'])){ setcookie("login",true,time()+60*60*24*100,"/"); setcookie("username",$row['username'],time()+60*60*24*100,"/"); setcookie("password",$row['password'],time()+60*60*24*100,"/"); $_SESSION['login'] = true; $_SESSION['username']=$row['username']; }else{ $_SESSION['login'] = true; $_SESSION['username'] = $row['username']; } }// End While echo '<meta http-equiv="Refresh" content="4;url=http://localhost/test/index.php">'; }else{ echo "Invalid Login Information"; }?> This should be self explanitory it first checks the username and password from the form and if they have the remember me feature checked it sets the cookies. If not just sets some session variables then takes them back to the index page where it displays all my varaibles I have set.Now all this code is working fine until I close my browser and reopen when testing my remember me feature again the cookie variables are display but i can not get my sessions to be set on return visits. I have come up with nothing with every thought possible is to why this is happening which means to me its something so simple that i need a fresh pair of eyes to point it out to me. So if anyone has an explination to what i need to fix please let me know. thanks
  9. Okay bear with me im still trying to figure this out, im a little confused by your solution so to see if im understanding it correctly when they submit the form create a page that says thank you being redirected and on that page set the cookies then use the meta refresh tag to send them to another page. That part I think i got so then on the next page do i copy my cookie variables into my session variables or do I copy my session variables on the same page im setting the cookies.(This assuming the user name and password have been checked against the database). Is this what you meant?
  10. Okay I tried to go back to basics to get an idea how to make cookies and sessions play nicely together and trying to follow your advice it seems i messed something up here is what I did just made some basic code pages to try to get them to work together.here is my form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><form action="validate.php" method="post"><p><label>Username</label><input type="text" name="username" /></p><p><label>Password</label><input type="password" name="password" /></p><p><label>Set Cookie</label><input type="checkbox" name="cookie" value="yes" /></p><p><input type="submit" value="Go!" name="submit" /></p></form></body></html> here is the page the form sends you to to validate information (my database info left out for obvious reasons) // Database connection here$validate = @mysql_query("SELECT * FROM members WHERE username='{$_POST['username']}' AND password = md5('{$_POST['password']}')"); if(mysql_num_rows($validate) == 1){ while($row = mysql_fetch_assoc($validate)){ // if cookies if($_POST['cookie'] == "yes"){ setcookie("username",$row['username'],time(5)); $_SESSION['username'] = $_COOKIE['username']; }else{ $_SESSION['username']=$row['username']; } } header("Location: /test/results.php"); }else{ echo "Wrong username and password!"; }?> Then if user info is correct goes to this page to show results <?phpsession_start();session_name('2am-designs');header("Cache-control: private"); // Fix for IE?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?php if(isset($_COOKIE['username'])){ echo "Cookie User name is set to ".$_COOKIE['username']."<br />"; echo "Session is set to ".$_SESSION['username']."<br />"; }else{ echo "Cookie is not set but Session is set to ".$_SESSION['username']; }?></body></html> Now what it seems to be doing is the opposite on the last page if i have the check box to set a cookie it shows the else statement on the last page omitting the $_SESSION['username']. just showing the string text.And If I check the check box to not set the cookie it shows the if statement showing the first line of echo correctly but not showing the $_SESSION['username'] value.Now I did something wrong here perhaps its the checkbox value messing things up or maybe Im doing this whole thing wrong. Can you see something wrong?
  11. thanks alot justsomeguy, that was very good explination, gives me a better visual to play around with. I didnt get much chance to play with it the last few days was out at the football game all day yesterday but anyways, I got a lot of free time today so im going to sit down and experiment with my cookies When I come up with something on my own I will post back and show the world what I have accomplished anyways thanks again.
  12. So if I understand you correctly using my code exampel above when they loggin add a section before the session to check for cookies if so then set session. if not set cookies then session in say an else clause correct?I will play around and post back with any success(hopes for) or problems I have thanks for the tip justsomeguy
  13. CStrauss

    class in php

    Well there are several websites out there that can help you learn classes basicly any website with php tutorials will usually have something on using classes.As for other resources I basicly learned classes through c++ which made it easier to learn in php, its not as complicated in php then in c++ or other languages such as java and what not. but if you understand classes in other languages its pretty simple in php.I also use several php books i have bought also go into great detail on classes one of my favorite php books I use as a bible to design all my sites that pretty much covers everything you want to know about building a php driven site is called Creating Interactive Websites with PHP and Web Services by the owner of phpfreaks.com by Eric Rosebrock. published by Sybex. Its a Intermediate/Advanced book but if you have a good php foundation should be easy to follow along and get some good useful tips out of it.to some it up just do some reading on the web by doing a google search for OOP PHP Class Programming or go down to your local bookstore and look for a good book on PHP that you can follow along with most of them all cover classes in some point in the book.Good Luck Classes will make your life easier. I have Several I use in all my sites such as an email class, a paging class, one to generate meta tags, and even did one to intergrade PHPBB login system with my own. So Once you learn it will give you a wealth of tools to use in your own projects.
  14. hmmm what do you mean by the image is not visible? I tested your code and it seemed to work fine, it upload the image and renamed it and placed it in a folder I made called upload.can you be more clear as to what you mean by not visible, do you mean when you try to display the image its not showing up? or is not showing up in your upload folder?
  15. I have always used sessions and have a pretty good understanding how they work, now i want to try what i normally see around the web with other sites where they have a login box that has a check box that says remember me. So now i need to figure out the best way to modify my current login script to allow cookies. Here is the codesbasic html form with a check box to let the user be remembered <?php if($_SESSION['login'] != true){ ?> <form action="/login.php" method="post"> <p><label for="1">Username:</label><input type="text" id="1" name="username" /></p> <p><label for="2">Password:</label><input type="password" id="2" name="password" /></p> <p> <input type="hidden" name="req" value="validate" /> <input type="submit" name="submit" value="Go!" /> Remember me!<input type="checkbox" name="cookie" checked="checked" /> </p> </form> <p>Not a member yet? <a href="/join.php">Register Here</a></p> <?php }else{ echo '<p>Welcome '.$_SESSION['username'].'</p>'. '<p>To Logout <a href = "logout.php"> click here</a></p>'; } ?> Here is my actual login script that checks info with database and sets the sessions. $validate = @mysql_query("SELECT * FROM members WHERE username='{$_POST['username']}' AND password = md5('{$_POST['password']}') AND verified = '1'"); if(mysql_num_rows($validate) == 1){ while($row = mysql_fetch_assoc($validate)){ $_SESSION['login'] = true; $_SESSION['userid'] = $row['id']; $_SESSION['first_name'] = $row['first_name']; $_SESSION['last_name'] = $row['last_name']; $_SESSION['email_address'] = $row['email_name']; $_SESSION['username'] = $row['username']; if($row['admin_access'] == 1){ $_SESSION['admin_access'] =true; } } $login_time = mysql_query("UPDATE members SET last_login=now() WHERE id='{$row['id']}'"); } header("Location: /index.php"); }else{ myheader(" - Login Failed!"); echo '<p>Login Failed</p>'; echo '<p>If you have already joined our website, you may need to validate '. 'your email address. Please check your email for instructions.'; footer(); } Now i was reading another post and it suggest setting the cookies the same as your session variables to keep them synchronized, which makes sense, and then still use the session variables. But i have seen so many examples its really kinda of confused me so I posted my code hoping someone can look over it and show me the best way to do it that way i can see and understand better with my own code and what not and how to implement it all.Also after I got my cookies set after the use has logged in and opted to be "remember" how do i work that in with my session on the condition where it checks the session to see if user is logged in or not?Thanks for any advice in advance sorry if this is a redundent post, I did a search before but like i said I saw so many examples it just confused me a bit more then needed.
  16. Thank you so much that worked well, and thank you for the additional tips i will defentatly use them. Again I appreciate the time you took to help me. I hope others read this topic with the same problem and use your knowledge as well.
  17. well sorta Ible-white, they are streched the way I like them to be except im looking to have them fill 100% of browser regardless of how much content. Atleast the background I tried putting a background image (blank transparent gif file) but that didnt work. To give a better example of what im trying to do i uploaded my site im working on and here is the link.LinkAs you can see the nav bar on the left doesnt expand all the way down. to fill the empty space. Eventually I will make a nav bar graphic that I would like to fill that entire section so regardless of how much content is in that section it will reach the bottom if you know what i mean. This layout example I found on the net, its actually a 3 column layout that uses the right section as a sub header part beneath the logo. Anyhow I hope this gives every one a better visual example Im trying to achieve. the code has changed since my original code, but can be seen through Fire fox but if you need me to repost the new code. Let me know. Thanks again everyone for your help in trying to help me figure this out. I really appreciate it.
  18. hmmmm that didnt seem to work as well as I thought it would. It pretty much gave me the same results of I was getting before by adding the 100% to the mainNav div in IE it does push that area down to end of the browser like I want but when tested in other browsers such as FF, Netscape, and Oprea the mainNav area still remains the same until content is added. Again Im trying to achieve the effect of the mainNav area stretching down to the bottom of the browser regardless of how much content is down I will keep playing with it until i figure it out or someone comes up with a working solution thanks for the help attempt BiteMe if you have any other ideas please let me know.
  19. Thank you i will give it a try today. I know theres gotta be away just a matter of playing with it. to me it just make more sense to have your nav bar stretch the length of the browser for i noticed most sites have them longer then most content they display on the current page if you know what i mean. What im getting at is people add new links and section to their nav bar so im basicly trying to set it up so regardless of how much content is in the nav bar it will stretch to the bottom of the page to prepare for future additions while at teh same time giving it a more complete look.Anywyas thanks for the tip i will give it a try today and report back what happen.
  20. I been practicing more on my CSS skills and trying to accomplish making my navigation or any other div container to streatch 100% of the browser. Now I figured out how to make the wrapper fit 100% of the browser now I want to try to be able to make specific div boxes inside the wrapper also streatch down to the bottom of the page. I been playing with it for days and it seems i can make it work in IE but not other browsers so now im back to square one running out of ideas can someone please look at my code in the sample im providing and explain how to do it it all browsers.Below is code for a 2 column layout with a header and footer. As you can see I have wrapper streatching down the length of the browser that is working okay. Now i want to do the same for the navigation on the right to also streatch down the page. I tried adding the similar code i used for the wrapper but i must not be understanding something when doing that trick to make it work for elements inside the wrapper. Any suggestions??? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>2 Col Float Layout</title><style type="text/css">body{text-align:center;}#wrapper{width:720px;margin-left:auto;margin-right:auto;background-color:#CCCCCC;text-align:left;min-height:100%;}/* commented backslashes hack v2 \*/html, body{ height:100%;}* html #wrapper{ height:100%;}/* end hack */#content{width:520px;float:right;background-color:#666;}#content p{padding-right:20px;}#mainNav{width:180px;float:left;padding-top:20px;padding-bottom:20px;background-color:#990099;}#mainNav p{ padding-left:20px; padding-right:20px;}#footer{clear:both;background-color:#33CCFF;} </style></head><body><div id="wrapper"> <div id="header"><h1>This is the header</h1></div><!-- End Header --> <div id="content"> <p>Lorem ipsum dolor sit amet, consectetuer adipiscin</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscin</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscin</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscin</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscin</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscin</p> </div><!-- End Content --> <div id="mainNav"> <p><a href="#">Link 1</a></p> <p><a href="#">Link 2</a></p> <p><a href="#">Link 3</a></p> <p><a href="#">Link 4</a></p> </div><!-- End Main Nav --> <div id="footer">© 2am designs 2006</div><!-- End Footer --> </div><!-- End Wrapper --></body></html>
  21. Hello,I have created gallery scripts many times using mysql database but i want to try something diffrent and work with reading files with phpI have a script i writen that resizes images for thumbnails so Im looking for some logical solutions to go about reading the image files in the folder. So im trying to figure out how i need to go about pulling the images out of the folder to display on my page.I figured I need to open the folder then load the images in an array then loop through it to display the images with my my resize script to create thumbnails and links does this sound correct. Can anyone give me a simple example on how to read the image folder and load them in to an array and loop through to display.Usually I use a database which is easier to do this to sort them but i want to try something diffrent to expand my knowledge. Thanks
  22. yeah i figure i might have to do that for now use search to replace but i was just curious if there were functions or special ways to input it the data and retrieve it but if anyone else knows better ways to do this please post and let me know so i can experment with it
  23. Here is my current project I been playing with and just want some ideas or suggestions to accomplish this taskBasicly I have a form I can type out a little article or what not, and when I submit the form it inserts the data into a database. Here is what I want to know. What is the best practice to storing information into a database so things that should be displayed as html when extracted show up on my page as html. for example if i type in my textarea of my form, a link refrence such as http://something.com or www.something.com, or http://www.something.com how should that be stored in a database and how can i extract it so it converts it to a link when displayed on my web page.I learned so far to use nl2br to help store nl as line breaks and I even made a function to convert them back with a custom made function called br2nl if needed to. So basicly Im looking for other functions in php i can use to do the same with other html entiies. Should i be using the htmlspecialcharacters or htmlentities function if so can some one give me a little bit more understandable explaintion then what the php online manual explains them as so i can understand those better if thats what i need to be using to complete what i want to try. Again its not with links im only looking for to convert but thats the main reason of this post just any html tags in general that wil be generated dynamicly on my page as its pulled from the database how should i be inserting this information into the database so i dont get garbage put in my database.Thanks for any input oyu can advice on
  24. can you post what the error messeage is saying? Im not a mysql expert by far but I'm pretty good at figuring out my errors as the come along from what the mysql_error() reports back on my screen.
×
×
  • Create New...