Jump to content

Benmcfc

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Benmcfc's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Haha, that does make sense. I have to remember to think about things more logically (in my defence, it's been a long week ) Thanks for the quick replies.
  2. Hi all, I started reading a few tutorials about OOP within PHP recently. At the minute I'm not seeing the advantages over procedural but I'm sure this is largely because most of the tutorials use abstract dog classes that are extended with breeds, or car classes, to get the ideas across. I decided the best thing to do would be to have a bash at making a couple of classes to see first hand what an object oriented approach could do. Below is an address class, and there is also an property class that is extended by a residential class and a commercial class. <?php class address { public $addressLine1; public $addressLine2; public $addressLine3; public $postcode; function __construct($addr1, $addr2, $addr3, $pcode){ $this->addressLine1 = $addr1; $this->addressLine2 = $addr2; $this->addressLine3 = $addr3; $this->postcode = $pcode; } public function getAddress(){ return array('addressLine1' => $this->addressLine1, 'addressLine2' => $this->addressLine2, 'addressLine3' => $this->addressLine3, 'postcode' => $this->postcode); } } //$add1 = new address("1","2","3","4"); //print_r($add1->getAddress()); ?> <?php require_once("address.class.php"); abstract class property extends address { protected $buildingValue; protected $address; function __construct($bval,$addr1,$addr2,$addr3,$pcode) { $this->buildingValue = $bval; $this->address = new address($addr1,$addr2,$addr3,$pcode); } function getBuildingValue(){ return $this->buildingValue; } function setBuildingValue($value){ $this->buildingValue = $value; } function updateDetails($bval,$addr1,$addr2,$addr3,$pcode){ $this->buildingValue = $bval; $this->address = new address($addr1,$addr2,$addr3,$pcode); } } class residential extends property { protected $tenantType; function __construct($bval,$addr1,$addr2,$addr3,$pcode,$tenant) { parent::__construct($bval,$addr1,$addr2,$addr3,$pcode); $this->tenantType = $tenant; } } class commercial extends property { protected $trade; function __construct($bval,$addr1,$addr2,$addr3,$pcode,$trade){ parent::__construct($bval,$addr1,$addr2,$addr3,$pcode); $this->trade = $trade; } } ?> This is the code I am using to create and display the objects: <?php require_once("property.class.php"); session_start(); $res1 = new residential(250000,"1 Test Road","Testville","Testshire","T1 1TT","Professional"); $com1 = new commercial(260000,"2 Test Road","Testville","Testshire","T1 1TT","Butcher"); #print_r($prop1); $_SESSION['res1'] = $res1; #print_r($_SESSION); $_SESSION['res1']->updateDetails(450000,"144 Test Road","Testvilless","Testshirerer","T1 1TT","Student"); print_r($_SESSION); print_r($res1->getAddress()); ?> The problem is that there is no output from $res1->getAddress(); although if I call the same function from within the address class it works OK. The output from that final print_r is: Array ( [addressLine1] => [addressLine2] => [addressLine3] => [postcode] => ) Any help on this would be much appreciated, as would any general comments about OOP. Thanks in advance.
  3. Hi all, I'm about to make major alterations to a few of my tables in order to create v2 of a certain service that depends on them. The issue is that there is already a lot of data in there from v1. For example, in v1 there is a varchar field in one of the tables containing the date and time, which is being replaced with timestamp. Elsewhere, there are some new columns, some columns being removed, etc. What I am wondering, is if I can maintain the old data whilst making these changes, or whether this is impossible? Obviously, I will be making a full backup of the db before starting to make the changes. Thanks in advance.
  4. That's brilliant, it's all working fine. Thanks for the help If anyone has found this page through Google and is struggling with the checking of the URL to redirect, <?php $uri = $_SERVER['REQUEST_URI']; $pieces = split ("[.?=]",$uri); if ($pieces[1] == 'php' ) { //headers as above } ?> $pieces[0] is /products $pieces[1] is php $pieces[2] is p and $pieces[3] is the product type If the user has reached the page through the new SEO friendly link, $pieces[1] != php so the headers aren't sent.
  5. Thanks for the reply. Is that going to work if the 'new' URL is technically still pointing at the same location as the old one? Can I perhaps check whether the user has used the SEO friendly URL or the old one with an if statement? I would've thought the URL the script sees is the actual one rather than the rewritten one.
  6. I've recently changed the links on a couple of my sites using .htaccess rewrite. For example, before it would say: /products.php?p=product-name Now it appears as: /products/product-name/ Is there a way to get Google to update their index to reflect the changes? If it required removing the current indexed pages through Webmaster Tools and letting them respider would I lose all progress on the SEO front? Thanks.
  7. Are you getting an error message or is it simply not sending the email? If so, does changing your final if statement to this work: if ($_POST['sendmessage']) { if(!isset($_POST['message'])) { $messages = "You have not entered a message. Please enter a message in the comments box below and submit.<br>"; } elseif(!preg_match("/^.*?@.*?$/", $_POST['email'])) { $messages = "You have not entered a valid email address. It must be in the format name@provider.com.<br>"; } else { //separating the variables here is unnecessary but helpful for readability $subject = stripslashes(trim($_POST['subject'])); $message = stripslashes(trim($_POST['message'])); $headers = "From: " . $_POST['email']; mail($sysmail, $subject, $message, $headers); $messages = "Please wait for a response from the user you messaged.<br>"; } }
  8. You could record the current time as a session variable, and on every subsequent pageload you could check if that time was within 5 minutes of the current time.
  9. Base part of the password on the user's id, which should be a unique auto incrementing number.
  10. Hi all, First off, apologies if this is in the wrong section of the forums. I know there's a lot of results in Google for this but I've been unable to fix it. try { //vars $userName = "someusername"; $password = "somepw"; $request = array( 'UserName' => $userName, 'Password' => $password, 'Transaction' => array( 'ID' => '001', 'TransID' => '000001', 'Reference' => 'some_string_0101', 'SchemeCode' => 'abc', 'ClientReference' => 'some_string', 'Branch' => 'some_string', 'SchemeBrokerNo' => '42', 'SaveState' => 'Pending', ), 'SaveState' => 'Pending' ); //soap include 'lib/nusoap.php'; $namespace = "XMLTransferServiceProxy"; $soapACTION = "path/to/action/url"; $URL = "path/to/xmltransferengine.asmx"; $client = new SoapClient($URL); $client->useHTTPPersistentConnection(); $SaveTransaction = $client -> call("SaveTransaction", $request, $namespace, $soapACTION); } catch(SoapFault $fault){ echo "SoapFault: ".$fault; } print_r($client); This is the soap request: POST /services/xmltransferengine.asmx HTTP/1.1 Host: host User-Agent: NuSOAP/0.7.3 (1.114) Connection: close Content-Type: text/xml; charset=UTF-8 SOAPAction: "path/to/soap/action/method" Content-Length: 1089 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body><ns8502:SaveTransaction xmlns:ns8502="XMLTransferServiceProxy"> <UserName xsi:type="xsd:string">someusername</UserName> <Password xsi:type="xsd:string">somepw</Password> <Transaction> <ID xsi:type="xsd:string">001</ID> <TransID xsi:type="xsd:string">000001</TransID> <Reference xsi:type="xsd:string">some_string_0101</Reference> <SchemeCode xsi:type="xsd:string">abc</SchemeCode> <ClientReference xsi:type="xsd:string">some_string</ClientReference> <Branch xsi:type="xsd:string">some_string</Branch> <SchemeBrokerNo xsi:type="xsd:string">42</SchemeBrokerNo> <SaveState xsi:type="xsd:string">Pending</SaveState> </Transaction> <SaveState xsi:type="xsd:string">Pending</SaveState> </ns8502:SaveTransaction> </SOAP-ENV:Body> </SOAP-ENV:Envelope> This is the soap response from the server: HTTP/1.1 500 Internal Server Error. Date: Fri, 03 Apr 2009 09:30:53 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Cache-Control: private Content-Type: text/xml; charset=utf-8 Content-Length: 488 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>Server was unable to process request. --> Object reference not set to an instance of an object.</faultstring> <detail /> </soap:Fault> </soap:Body> </soap:Envelope> As I said, I've visited a number of the results Google brought up for the error code, but have been unable to find the cause of the problem and fix it. Any help would be much appreciated.
×
×
  • 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.