![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
mbtaylor
-
Posts
96 -
Joined
-
Last visited
Never
Posts posted by mbtaylor
-
-
bugger knows then lol maybe someone else will enlighten us!
-
Odd, only thing I can think is if its looking for false? 1=true, 0=false etc.
Maybe the triple equal would sort that !== that does type check too I believe.
-
if ($start_year % 4 == 0) { # the year is divisible by 4 }else{ # the year is not divisible by 4 }
!= 0 should work fine too (the opposite obviously).
-
because the <? is contained in a string.
Check out HEREDOC syntax in the php manual (explained in the print manual page)
-
Not too sure that this is what you mean but this is how I generate dynamic XML from a php page:
<?php $xml =<<<XML <?xml version="1.0" encoding="utf-8"?> <products> <product> <name>Some Product</name> <name>1.99</name> </product> </products> XML; print ($xml); header( "Content-type: application/xml; charset=\"iso-8859-1\", true"); header("Pragma: no-cache"); ?>
The XML would likely come from a database.
-
Actually this is a bit better:
%((http://)?(www)\.?[A-Za-z-]*\.?[A-Za-z-]{1,5})%
-
<?php $url = "http://www.some-url.com"; $url = preg_replace ("%([http://]*[www]{3}.?[A-Za-z-]*.?[A-Za-z-]{1,5})%", "<a href='$1' title='$1' />$1</a>", $url); print ($url); ?>
-
Heh I wrote a different one...
<?php $url = "http://www.some-url.com"; $url = preg_replace ("%(http://www.?[A-Za-z-]*.?[A-Za-z-]{1,5})%", "<a href='$1' title='$1' />$1</a>", $url); print ($url); ?>
I like your use of \w\d - you also need to allow for a hyphen in the character range though.
Regular expressions rule
-
Thanks, i've read up in google and a couple of my programming books.
The lightbulb just hasn't clicked on yet the way it works from one page to the next in verifying if the variable has been passed.
Regarding Login, yes, I've used in login but this isn't a login. Although it's a membership purchase, the member doesn't establish a un and pw. They pay from a purchase.php page, which if approved to to the thankyou.php page which has three choices to select to fill out an informational form.
I'm trying to keep access to the thankyou.php page except by way of the purchase.php page.
If the user pays for your product and doesnt have a login, how are you going to know in future that they have paid?
I would generate them a username/password based on their email address and email them it, then they can login with the details and access whatever they paid for. You are going to need to store these details in a database which can be looked up in the login function to check payment status and other user details.
If someone pays you could log them in automatically with a session. Maybe set that on the thankyou page and provide a link to the download page, or whatever.
-
Well traditionally before page1.php you would have login.php which would ask for the username, password and match it against the database values. If correct then a session variable is created saying loggedin or whatever and then a simple function can be called on each page to check whether or not the user is logged in. I would personally put that in a header include or similar.
Added:
Oops reading your post again thats maybe not what you want
In that case set a session to contain an array of referrers maybe and check the array to see if the neccessary pages are contained within.
-
I dont thing sleep is counted in php script execution time, but I could be wrong.
-
Aye, the MaxMind GeoIP Lite data + API would suit your needs well and its free
-
Its the database of IP addresses that is important, how you access that is up to you. I believe you can get the Maxmind GeoIP lite data for free and in either csv or binary format. I personally use their API to access that but you could use sql statements I guess.
-
Doesn't seem to match on \
%[<>\\\/:*?,|\"\s]%
An easier way to avoid special (non-letter) characters is to use /\W/, or /\P{L}/ if you're Unicode friendly. It may be easier to establish what you want to allow, instead of what you don't.
Ive not heard of that (/\W/), im going to have to read your regex post links Effigy
-
Im not sure about ereg but with preg it would be something like:
$string = "<test?>"; preg_match ("/[<>\\/:*?,|\"\s]/", $string, $matches); print_r ($matches); if (count($matches) > 0) { # match }
Would this not be more useful as a preg_replace though? Not knowing what you are trying to do exactly... preg_replace would string the chars out of your string.
-
Does it?
* Reads manual page.
Sorry to dupe your post then.
-
You could write a function which uses explode to split the string on a space which would create an array of words. Then loop through the array and insert a <br /> every Nth word.
e.g
$words = explode (" ", $string); $numtoseparate = 10; #number of words before inserting a <br /> foreach ($words as $word) { $i++; print ($word); if ($i == $numtoseparate) { print ("<br />"); } }
-
Heres a nice mcrypt class for you (mcrypt allows de-encryption).
<? /*************************************************************** Data encryption class ***************************************************************/ /* usage example : $encryption = new ubercrypt(); $encryption->$key = "RQ2ByIw4g6u7FqLvtS+Nw1+tCRQaZKNf"; $encryption->$encrypt_text = "secret"; $password = $encryption->encrypt(); echo ("encrypted pass = ".$password."<br />"); echo ($encryption->decrypt($password)); */ class ubercrypt { var $key; var $encrypt_text; var $decrypt_text; function encrypt(){ $key = $this->$key; $input = $this->$encrypt_text; $input = str_replace("\n","",$input);$input = str_replace("\t","",$input);$input = str_replace("\r","",$input); $key = substr(md5($key),0,24); $td = mcrypt_module_open ('tripledes', '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); mcrypt_generic_init ($td, $key, $iv); $encrypted_data = mcrypt_generic ($td, $input); mcrypt_generic_deinit ($td); mcrypt_module_close ($td); return trim(chop(base64_encode($encrypted_data))); } function decrypt($input){ $key = $this->$key; $input = str_replace("\n","",$input);$input = str_replace("\t","",$input);$input = str_replace("\r","",$input); $input = trim(chop(base64_decode($input))); $td = mcrypt_module_open ('tripledes', '', 'ecb', ''); $key = substr(md5($key),0,24); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); mcrypt_generic_init ($td, $key, $iv); $decrypted_data = mdecrypt_generic ($td, $input); mcrypt_generic_deinit ($td); mcrypt_module_close ($td); return trim(chop($decrypted_data)); } } ?>
-
Wow theres a DATEDIFF function?
* remembers to read up on all MySQL functions...
I always did it the strtotime() way
-
Use a foreach loop to loop through as associative array. You can use $var => $value to look through all the keys.
foreach ($_POST as $var => $value) { # loop through post vars and add up anthing that has "VB" in the variable name. if (strstr ($var, "VB")) { $total += $value; } } if ($total > 0) { # user has made a purchase } /* Note if you did $$var = $value you would get the variable $VB0001 etc. */
But then, why would a Select form field be submitting many VBXXXX values surely it would only be 1?
If so you would access that with the name attribute of your select field e.g
<select name='something'> $something = $_POST['something'];
Does that help?
-
I'm pretty sure the foreach is so that if there is more then 1 row he is searching for in the query, it will display all of them, instead of just one.there is no need to add a foreach loop inside a while loop... they do the exact same thing... you're just using up more resources.
The while loop will loop through all rows. What I posted was a solution to what truegilly was wanting to do. I personally use the same to give me a quick idea of all the elements being pulled in from the db. The same could be achieved with print_r which I guess may be more efficient I dont know but less flexible certainly.
-
No they arnt.
The while loop is looping through the database rows, the for loop is looping through the current database row.
-
Well its an array so just use a for loop to show the elements you want.
For example:
$numelements = count ($arrImages); for ($i=0;$i<3;$i++) { print ($arrImages[$i]); # prints out first 3 elements } for ($i=3;$i<6;$i++) { print ($arrImages[$i]); # prints out elemets 3 - 6 }
Hope that helps.
-
You mean you want the array sorted?
$arrImages = array(); if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { // Is it a valid extension? if(!is_dir($file) && is_numeric(strpos($file, "."))) { if($this->_IsValidExtension($file)) $arrImages[] = $file; } } closedir($dh); } } array_multisort ($arrImages, SORT_DESC, SORT_STRING); //or array_multisort ($arrImages, SORT_ASC, SORT_STRING); $num_elements = count ($arrImages); array_splice ($arrImages, 10, $num_elements);
This is untested code, but I am basically using array_multisort to sort the elements then splicing anything over 10.
Good luck!
(more...) for articles
in PHP Coding Help
Posted
Heres my version...