Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. Have you checked out the oscommerce contributions?
  2. Its entirely up to you. There are no fixed rules for OOP. The concept of OOP is about reusability, so could you use the user class in another project by itself or is it coupled tightly to your db object (i.e. would you have to take both). If you want to use the db object in you user class then why not extend it i.e (using a made up database object). class user { public $name; } class dbUser extends user { private $db; // pass a new db object in public function __construct(db $db) { $this->db = $db; } public function getUser($id) { $this->db->query("SELECT * FROM user WHERE id='".$id."'"); $result = $this->db->record(); $this->name = $result['name']; } } // usage $user = new dbUser(new db()); $user->getUser(12); print $user->name;
  3. This is quite simple but you are better setting a cron job to grab the data in given intervals rather than requesting live from your site page. The remote site will end up banning your IP if traffic is high and your page load time could be slowed if the remote site is busy. In your script Use CURL to grab https://www.arabfinance.com/MarketStatistics/Quotes.aspx?Id=1725 Then simply use regular expressions to extract the data you require from the HTML. Save the extracted data to your website database. Your website can then display the data from your database. Easy
  4. It is probable that your browser is not fully closed. Sometimes browsers keep a users session open in the background even when closed by clicking the x. You could use an ajax request with the <body onUnload=""> trigger. I'm not sure why you would need to adopt this policy anyhow.
  5. Because a new session is started if you fully close your web browser then reopen. Your old session key is not retained.
  6. Impossible with pure PHP. PHP is server side and is only interpreted when requests are made. A browser is a client side application thus PHP cannot detect a user closing a browser.
  7. You need to specify the cookie path in the set_cookie() path parameter // set setcookie("test", $value, time()+3600, "/mysubdir/"); // destroy setcookie ("test", "", time() - 3600, "/mysubdir/"); If you set the path to / it will be available within the entire domain setcookie("test", $value, time()+3600, "/");
  8. You are setting the session value rather than testing it: if($_SESSION['logged_in']=true) Should be if($_SESSION['logged_in'] == true)
  9. Display php settings using phpinfo() <?php print phpinfo(); ?> Save a file and run in your browser. It will tell you the path to the ini file. In linux its usually in /etc/php.ini but not always. Unsure on windows. Any changes made requires a restart of the webserver service httpd restart
  10. Explode the string into an array and then rearrange $string = "AAAA|BB|CC"; $parts = explode("|", $string); $newString = $parts[2]."|".$parts[1]."|".$parts[0]; print $newString;
  11. You need to add a GROUP BY claus to the sql GROUP BY YEAR(date)
  12. Set the smtp server address in your php.ini i.e. SMTP = mail.yourisp.com smtp_port = 25 However you cannot use SMTP authentication through the ini file so mail() will not work if required Use a mail library such as PEAR::Mail or Swiftmailer where you can set your SMTP settings http://swiftmailer.org/
  13. These pages make no sense! session_any.php <<--To allow anyone to view the page and keep the session going I can't do this session_safe.php <<--To only allow logined in users to the page I can't do this Sessions are the easiest thing in the world to use! All you need is to include a file on every page that starts sessions up, lets say a application.inc.php In this document all you need is: <?php session_start(); ?> For your login file i.e login.php include('application.inc.php'); // the user has attempted to login // check the login details against the database // user details ok - set some session variables $_SESSION['name'] = "Joe Bloggs"; $_SESSION['id'] = 123; // redirect the user to the welcome page header("Location:welcome.php"); exit(); Now on the welcome.php page you can display a message to the user. Remember to include the application.inc.php file: include('application.inc.php'); // display welcome message print "Hello ".$_SESSION['name']; To logout all you do is destroy the session variables so logout.php include('application.inc.php'); // destroy all session variables foreach($_SESSION as $key => $val) { unset($_SESSION[$key]); } print "You were successfully logged out"; For pages on your site that require you to be logged in all you need to do is make sure that the session variable you set after a successful login exists. i.e include('application.inc.php'); if(!is_numeric($_SESSION['id'])) { // the user is not logged in - redirect to login.php header("Login.php"); exit(); } Any book on PHP has sections on sessions.
  14. print out the filepath variable and check to see if it is what you expect $filepath = $_SERVER['DOCUMENT_ROOT'].'/documents/'.$getfile; print $filepath; exit(); It maybe the additional / after $_SERVER['DOCUMENT_ROOT'] as the server variable may already contain the trailing /
  15. Has anyone got any pointers or links on loading dynamic data into flash using php. Lets say I have a flash module that scrolls through the latest news or rotates some kind of photo album. The data is to be grabbed from a mysql database and used in the flash file. Not much experience with flash.
  16. You can connect and issue telnet commands to the mail server using: // use to connect fsockopen() // use to issue commands fputs() // use to read fgets()
  17. Place your insert code above any html or echo/print statement (very top of script). i.e. if ($_GET['act'] == "send") { // insert post // reload page header("Location:) exit(); } <form ....... </form>
  18. Check your code mtoynbee. $bad_word variable is undefined in eregi function. You have defined $word in the foreach loop.
  19. That will replace the word. To find words you can use a variety of string functions. You will need a bad words list to compare as the post above suggests. strstr() preg_match() strstr() ereg() preg_match_all()
  20. After the insert query reload the page using the header function $query = mysql_query("INSERT INTO web_downloads_replies ( name, content, date, reply_in ) VALUES ( $name , '$reply' , '$date' , '$download_id' )"); // reload page header("Location:nameofyourpage.php"); exit();
  21. Why do you need AJAX? Once you lookup the username/password for the submitted form via your database you can set session values based on the returned results.
  22. OO design is generally more resource hungry than procedural but there are reasons for using OO as oppose to procedural. They are reusability and extendability where large procedural programs suffer from a lack of the two.
  23. cgi should be dropped if it exceeds the apache TimeOut directive. If not set this defaults to 300 seconds.
  24. You could try SWF upload. I have implemented this before. Allows multiple uploads and displays progress bar: http://swfupload.org/
×
×
  • 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.