Re: [PHP] validating username
You need to encode the # mark. It is a special character in URLs. Example (not a real url): www.php.net/documentation.php#help That #help points to an anchor in that page. Try using the javascript escape() function. http://www.javascripter.net/faq/escape.htm ~Ted On 27-May-08, at 10:14 AM, Sudhakar wrote: my question is about validation using php. i am validating a username which a user would enter and clicks on a image to find if that username is available. example if a user enters abc#123 php file is reading this value as abc ONLY which i do not want instead the php file should read as abc#123. follow is the sequence of pages. please advice the solution. first page = register.php here a user enters a username and clicks on an image to find out if the username is available or not. using a javascript function of onclick i am reading the value entered in the form in javascript as = var useri = document.registrationform.username var valueofuseri = document.registrationform.username.value var recui = /^\s{1,}$/g; if ((useri.value==null) || (useri.value=="") || (useri.length=="") || (useri.value.search(recui))> -1) { alert("Please Enter a User Name") return false } window.open("checkusernamei.php?theusernameis="+valueofuseri, "titleforavailabilityi", "width=680, height=275, status=1, scrollbars=1, resizeable=yes"); second page = checkusernamei.php = this file uses GET to read what was entered in the form. $username = $_GET["theusernameis"]; if( $username == "" || !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) ) { echo "username is blank or has special characters"; } the # sign is being ignored only if the image is clicked in order to check the username, if the user enters abc#123 and clicks the submit button without clicking on the checkuser image button then my php validation for username shows an error message. == if( $username == "" || !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) ) { echo "display error message for username"; } == now the problem is with clicking the image only and passing using GET method how can i fix this problem. please advice. thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anybody got a little spare time to help me out with a little OOP
On 1-Jun-08, at 8:15 AM, Ryan S wrote: Thanks for replying, but how and where do I put that into the script? all that "this->" stuff is confusing Tony Marsten's links seem to be very good, but let me offer you a simpler introduction. Once you can think in an OOP fashion, procedural-/functional-based programming seems archaic. Object-oriented programming is all about thinking about everything as "objects" people, cars, flowers, dogs, pictures, food items... whatever your application manages. You model up these real-world objects using simple PHP syntax. Objects can refer to themselves (or their inheritance) using $this->, which means "me" or "mine". When using $this->, the object is referring to a property or method (aka function) within itself or inherited from one of its parents, whichever comes first. ~Ted
Re: [PHP] strlower problem
On 2-Jun-08, at 10:25 AM, Ed Curtis wrote: I found the problem myself. The actual code follows the same principal but the value of $thisStr is a $_GET value from a link. The name of that value in the link was 'style'. Oops, you should never use a HTML reserved attribute as a varible identifier in a link. I just wasn't thinking at the time I wrote it. (href="order2.php"?style="CL22">) Input validation is always a very important aspect when using values submitted by the client. Assuming that $_GET['style'] existed without testing for it was the first thing that should've been looked at. In order to make maximum use of this mailing list, it's really helpful for us to see the _actual_ code you're using, rather than fake code. Your fake code had no problems, so we weren't able to provide you with a solution, but it sounds like your real code had the error that caused the problem. Even in your latest post, you put this: () What's with all of those double-quotes? More fake code, or is that actually what you have in your code? ~Ted -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] question about session variables
How are you "calling thankyou.php"? 1. are you -redirecting- the user to that file? --or-- 2. are you -including- that file into register.php upon a successful submission? The method you're using determines how you best secure thankyou.php from direct access. If you're redirecting, then using a session variable is what you want. If you're including, then a simple constant or variable defined in register.php can be checked and validated in thankyou.php. NOTE: use of session_register() is deprecated. After calling session_start(), just assign variables directly to $_SESSION: $_SESSION['firstname'] = 'Fred; ~Ted On 2-Jun-08, at 11:12 AM, Sudhakar wrote: i have a registration page called register.php if the data entered is validated correctly i call a file called thankyou.php or else validate.php presently a user after seeing the url website.com/thankyou.php if they enter the url directly in the browser as website.com/thankyou.php they can access the file, if a user accesses the file this way i would like to redirect to a page saying "Direct acess to this file is not allowed" previously i used sessions in register.php and also in thakyou.php and validate.php and it worked fine for some reason now it is not working the way it is supposed to i might have made some changes which i do not know previously my code in register.php was, the first few lines of register.php file = = code in thankyou.php, the first few lines of register.php file = http://website.com/directaccess.html";); exit; } // rest of the html and php code ob_end_flush(); ?> = NOTE = in thankyou.php i display a thank you message by retrieving the first name from register page and displaying in thankyou.php using session variables in the following way in register.php, the first few lines of register.php file = if(!session_is_registered("firstname")) { session_register("firstname "); } $_SESSION[firstname] = $ firstname; = in thankyou.php, the first few lines of register.php file = if(session_is_registered("firstname ")) { echo $_SESSION[firstname]; session_unregister("firstname "); } = please advice how i should rewrite the php code in both the files(register.php and thankyou.php) so that if a user enters the url directly in the browser i can redirect to directaccess.html file thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Links (A HREF) loosing my session
1. If you're using cookies, there's no need to pass the session name via the URL. 2. Is the cookie being created? ~Ted On 2-Jun-08, at 11:32 AM, Razer Montaño wrote: Hello All, my first time here at list. Well, I am with a very weird question, never happened with me, always worked fine. First of all, I am using WAMP (php 5.2.6, apache 2.2.8, mysql 5.0.51b), Firefox (All cookies allowed), Windows XP SP 3 (I think ;-)... Ah, the "session.save_path" property is pointing to a valid path and the session files are been created there. The "session.cookie_domain" I leave in blank, as I saw in other forum. That code below is not working properly. First time it creates the session and show me "First activation etc etc". If I press CTRL-R (Firefox, but I tested in IE too), it gets the same session, showing me the next number. If I press First Link (Again 1), it creates a NEW SESSION, when It would get the old one. And now, every CTRL-R is getting me a new session. Only If I go at address bar and hit ENTER, I can get the very first session created. The second link (Again 2) is a test. I saw that, if I set: session.use_only_cookies=0 session.use_trans_sid=1 this link works fine. But, I don't want to pass Session ID every link. I tried to set the properties above in other ways, but I get the same behavior: session lost in every link click. Could someone execute this script, to see if it has some wrong? Could you please help me... Thank you in advance. Razer. http://localhost:8081/testesession.php";>Again 1 http://localhost:8081/testesession.php?">Again 2 " . session_id() . ""; ?> -- Razer Anthom Nizer Rojas Montaño -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no array passed error
PJ, I remember the days when this stuff seemed beyond mystical. 1. $dbh and $query are not "built-in" variables... but they need to be defined somewhere earlier in the code. That could even be in a different file if the file you're in has been included. 2. One trick to try is to use the php function var_dump(). var_dump($dbh, $query); That will spit out the contents of both of those variables so you can see what's "inside" them. If one or either of them spits out as NULL, then it is undefined. If you see FALSE, then there may have been an error connecting to the database. ~Ted On 3-Jun-08, at 3:28 PM, PJ wrote: I don't know if this is the right list, it seems php and postgresql are rather interdependent in the webside I am debugging :(, but here goes: I'm getting this error: pg_execute() [function.pg-executea>]: No array passedE_WARNING for this line of code: if( !($r=pg_execute($dbh, $query)) ) I suspect that I am not connecting to the database on the server... How can I check my connection from withing the code or some other way? Are the $dbh and $query built-in variables in postgres or php - I'm afraid that I'm rather a bumbling newbie :) I can connect from XP to the FreeBSD 7.0 server and I can access and read the files and the samba connection appears to be correct... but I can't connect to the database from phped debugger Can't figure this out... Help ??? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Objects and Traversing
You should be able to access the "Name" field using this syntax: QueryResult->records[0]->sobjects[0]->fields->Name Reading from left-to-right: 1. accessing index 0 (zero) of the "records" array. 2. accessing index 0 (zero) of the "objects" array. 3. accessing the "Name" property of the "fields" SimpleXML element A more verbose approach would be: $fld = $queryObject->records;// get the "records" array $fld = $fld[0]; // get the first index of the array $fld = $fld->sobjects; // get the "sobjects" array $fld = $fld[0];// get the first index of the array $fld = $fld->fields; // get the "fields" SimpleXML element $fld = $fld->Name;// get the Name property Either way, you're "walking" left-to-right, top-to-bottom. ~Ted On 4-Jun-08, at 3:37 PM, VamVan wrote: Hello Guys, Here is the object. How can I get access to the [Name] = access. People who help me with this can you please tell me what is the logic behind traversing the objects and how do you gather the values. Thanks. I am looking for an answer like this $queryResult->f->dsfsdf QueryResult Object ( [queryLocator] => [done] => 1 [records] => Array ( [0] => SObject Object ( [type] => Contact [fields] => [sobjects] => Array ( [0] => SObject Object ( [type] => Account [fields] => SimpleXMLElement Object ( [Name] => Access ) ) ) ) ) [size] => 1 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quickly verifying single word.
There's probably a regex solution that is most elegant, but here is one solution: if ($str == str_replace(array(' ', "\n"), '', $str)) { // if you get here, then $str has no spaces or newline characters } ~Ted On 4-Jun-08, at 4:04 PM, Tyson Vanover wrote: I need a quick way to make sure that a string is a single word with no white spaces. I would prefer that it is a command that could fit on a single line. Or at least an if block. I have a few thoughts on this but it involves things like explode(), stripslashes(), etc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP code will not work
PHP at the command line doesn't run within a web server environment. ~Ted On 9-Jul-08, at 11:07 PM, Sanjay Mantoor wrote: Hi, I found $_SERVER['HTTP_USER_AGENT'] works when you are using with browser by server like Apache. If you are executing your code like script in command prompt it may not work. I got below :- PHP Notice: Undefined index: HTTP_USER_AGENT If you use print_r($_SERVER) , you can see all the listing of indexes. On Wed, Jul 9, 2008 at 7:15 PM, Mike V <[EMAIL PROTECTED]> wrote: I had this problem and just figured it out. I was copying and pasting the code snippet from the tutorials page to my test editor and in the process picked up an invisible ctrl char. Doh!! Joseph Subida wrote: The error I get when I try is Parse error: syntax error, unexpected T_VARIABLE in /Library/WebServer/Documents/test.php on line 106 I tried Googling "T_VARIABLE" and haven't found any useful solutions. Any ideas? Thanks! -J.C. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- View this message in context: http://www.nabble.com/PHP-code-will-not-work-tp17811807p18362005.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Thanks, Sanjay Mantoor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question regarding OO
Object-oriented programming, with it's "class" and "object" approach, is meant to model real life more closely than functional programming. In, a "parking space" is physically inside a "parking lot", but a parking space is not a subclass of a parking lot. It's not a variation or mini parking lot. It's an entirely different entity. A parking lot consists of parking spaces, but a parking space is its own thing. In other words, don't extend ParkingSpace from ParkingLot. They should be separate classes entirely. As for the recursion... no, that won't be a problem. Each ParkingSpace you're instantiating is a separate instance, and won't be related to the parent ParkingLot in anyway way internally. In the above class definition, simply populate the $spaces array with instances of the ParkingSpace class. ~Ted On 11-Jul-08, at 9:03 AM, Yeti wrote: I have a question here regarding object orientation in PHP and any other language. Let's start with some hypothetical code: */ // <--- 1st CLASS class ParkingLot { var size; // size in sq feet var max_number_of_cars; // how many cars there is space for function __construct($size, $max_cars) { $this->size = $size; $this->max_number_of_cars = $max_cars; } }; cpark = new ParkingLot(5, 17); // <--- 2nd CLASS class ParkingSpace extends ParkingLot { var ps_ID; // ID of the parking space ( 1 .. max_number_of_cars ) var occupied_by; // ID of the car on the parking space var st_time; // Unix time stamp set when the car parks function __construct($car, $id) { $this->st_time = time(); $this->occupied_by = $car; $this->ps_ID = $id; } }; /* OK, so i got a parking lot class and its subclass parking space. Now the question: I want a list of occupied parking spaces, where do I put that? One might put it into the ParkingLot Class, but wouldn't that be a recursion (a child instance in the parent class)? */ $occ_parking_spaces = array(); $occ_parking_spaces[] =& new ParkingSpace('Joes Car', 8); $occ_parking_spaces[] =& new ParkingSpace('My Prshe', 17); $occ_parking_spaces[] =& new ParkingSpace('Toms Caddy', 4); /* After a while a method to print all occupied spaces is necessary. Correct me if I'm wrong, but I usually add it to the ParkingLot class. class ParkingLot { // previous code ... var $occ_parking_spaces = array(); function print_occ_spaces() { var_dump($this->occ_parking_spaces) } }; What bothers me here is that I'm actually having a list of child classes in the parent class, is there a better/correct way to do this? I hope I made myself clear. Greetz, Yeti */ ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question regarding OO
Corrected code example: (too early in the morning to think) In the above class definition, simply populate the $spaces array with instances of the ParkingSpace class. ~Ted -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class 'PDO' not found in .... PHP 5.2.5
PDO is distributed with PHP 5.1 and higher by default, but it can still be excluded during the compile stage. This may be the case for your installation. Run php_info() to find out, and if PDO is not listed, ask your host to install it. http://ca3.php.net/manual/en/pdo.installation.php ~Ted On 17-Jul-08, at 8:07 PM, Stephen wrote: I am with a new host and just tried to upload new files that use PHP and the class PDO for database access. I get the error in the subject. I thought PDO was in the base code of PHP 5* My host is on 5.2.5 according to PHP info I have created a ticket I fear that this is one of those "not supported" things. So I am asking for any advise. Thanks Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] syntax error
Not a syntax error. It's not successfully connecting to the database. Check your settings. ~Ted On 21-Jul-08, at 4:24 AM, Ronald Wiplinger wrote: On a system with php4 and mysql 4.x I had these lines: require("../db-config"); // includes $dbhost, $buname, $dbpass $db = mysql_connect($dbhost, $dbuname, $dbpass); mysql_select_db($dbname,$db); $sql = "SELECT * FROM CATEGORY WHERE ."; $result = mysql_query($sql,$db); $num=mysql_num_rows($result); while ($myrow = mysql_fetch_array($result)) { Moving the *.php to a php5 and mysql 5.x site I get these errors: PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ... Looking at the manual, I cannot see what I am doing wrong. bye R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reference or copy?
The general rules of thumb are --> don't use references unless you actually *want* a reference. And don't use references for performance reasons. Under PHP 4, it's generally been recommended to use a reference operator when creating objects. $obj =& new Object(); PHP uses references internally until it's necessary to create a copy: $a = array(); $a = $b;// internally, $b is a reference to $a $b[] = "chocolate";// at this point, a copy is made, and $b is modified So PHP waits until a copy is actually needed before it makes one. Explicitly making copies incurs overhead because of the concept of "reference counting". So again, don't use references for performance reasons. ~Ted On 23-Jul-08, at 1:07 AM, Yeti wrote: Hello everyone, Many of you may be familiar with references in PHP. Now i read somewhere in the PHP manual that creating references can take longer than copies. PHP5+ also seems to reference a bit different thant PHP4 did. Here is some working example code: huge_array = array(); for ($i = 0; $i < 1024; $i++) $this->huge_array[] = $GLOBALS; // fill ze array with copies of $GLOBALS array return true; } function useless() { return $this->__construct(); } } $time_start = microtime(true); $test_obj = new useless(); $time_end = microtime(true); $time = $time_end - $time_start; echo "It took {$time} seconds without using the reference operator.\r \n"; unset($test_obj); $time_start = microtime(true); $test_obj =& new useless(); $time_end = microtime(true); $time = $time_end - $time_start; echo "It took {$time} seconds using the reference operator.\r\n## with obj2 \r\n"; $time_start = microtime(true); $test_obj = new useless(); $obj2 = $test_obj; $time_end = microtime(true); $time = $time_end - $time_start; echo "It took {$time} seconds without using the reference operator.\r \n"; unset($test_obj); $time_start = microtime(true); $test_obj =& new useless(); $obj2 =& $test_obj; $time_end = microtime(true); $time = $time_end - $time_start; echo "It took {$time} seconds using the reference operator.\r\n"; ?> I tested the code in PHP 4.4.7 and in PHP 5.2.5 and the results were pretty much the same. Using references speeds up the script! Occasionally obj2-with-references took longer than all the others. But i don't know if that's to be taken serious. Now if i do not need a copy, isn't it smarter to use references instead? I'm grateful for any ideas, thoughts or experiences Yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reference or copy?
On 23-Jul-08, at 1:19 AM, Ted Wood wrote: So PHP waits until a copy is actually needed before it makes one. Explicitly making copies incurs overhead because of the concept of "reference counting". So again, don't use references for performance reasons. That should've been: Explicitly making "references", not copies... ~Ted -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reference or copy?
In both PHP 4 and PHP 5, this would be an internal reference: $a = $b; until $b is changed. The only exception is with Object handling under PHP 4, which had flawed reference handling. So, the rule remains -- don't use references for performance reasons -- use them if you need references. :-) ~Ted On 23-Jul-08, at 1:20 PM, Yeti wrote: # In PHP5 $a would still be a reference as long as $b is not being changed?(!) # Such behaviour makes it extremely easy to write a speedy script without worrying about copy/reference issues! # Thanks to all of you, # Ernie ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with an error...
Micah, Please provide an example of what your response was referring to in the original message. And it is possible to have commands in the middle of a string by using concatenation. $str = "My name is ".strtoupper($name).'", but you can call me Sam."; ~Ted On 24-Jul-08, at 10:40 AM, Micah Gersten wrote: You cannot have commands in the middle of a string. Try building a string first, or use output buffering and then capture the buffer and use that as the string for the mail function. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com [EMAIL PROTECTED] wrote: Hi, I am currently working on a php script that will be called by cron. But I have an error that keeps coming up. Parse error: syntax error, unexpected T_VARIABLE inmail_report.php on What I am trying to do is a simple php script to send me a report everynight. Any clues as to why? Also does anyone know of a site with mail srcipts that are ran on the cli? - $query = "Select ip, date, time, CONCAT(city, ', ',country) as location from ips where country !=' ' and date = current_date() order by date,time,country asc;"; $result = mysql_query($query) $mailsend = mail("[EMAIL PROTECTED]","The IP's that Attacked $hostname", "The following are ip's that have try to attack your system.\r\n\r\ if ($result) { //if that ran ok, display the record echo " Country td> # of Attacks "; //fetch and print the records while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "$row[0]$row[1]"; } echo ''; mysql_free_result ($result); //free up the resources } else { //if did not run ok echo 'This could not be display due to a system error. We apologize fore any incovenience.'. mysql_error() . ''; } ","From:[EMAIL PROTECTED] To:[EMAIL PROTECTED]"); print("$mailsend"); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php