Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2004, 10:21 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default Could somebody explain this to me, please?

On page 321 there is a chunk of code for the postcard example, which by the way was poorly explained, that I do not know what is for:
Code:
$path = “http” . ($_SERVER[“HTTPS”]==”on”?”s”:””) .
“://” . $_SERVER[‘SERVER_NAME’] .
strrev(strstr(strrev($_SERVER[‘PHP_SELF’]),”/”));
Could somebody explain it to me please?

Thanks
Christian
Note: I could not find the images I was suppose to use for this example. Somebody know where I can find them?
__________________
Christian
 
Old June 6th, 2004, 11:27 PM
Authorized User
 
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you sure that was page 321? I have that code on page 305.

I see that it is used in two places: db_insertpics.php and viewpostcard.php. It looks like viewpostcard.php does not use the path -- it is possible that it did in an earlier incarnation, but does not now. It is not currently needed in viewpostcard.php.

However, it IS needed in db_insertpics, and what that little piece of code does is builds up a URL.

As I'm sure you know, a url is made up of parts. The protocol (http, https, ftp, etc.), the server address, the path, and the file. Of course, there is more to it, but that is the basics. Let's look at each piece:
Code:
$path = “http” . ($_SERVER[“HTTPS”]==”on”?”s”:””)
This part starts $path with "http" and if you are on a secure connection, adds an "s".
Code:
 . “://” . $_SERVER[‘SERVER_NAME’]
Next, the :// is added, as well as the server address. so now we have "http://www.yourserver.com/".
Code:
strrev(strstr(strrev($_SERVER[‘PHP_SELF’]),”/”))
I'm assuming that if you weren't referring to the $path being in the viewpostcard.php file, then your question might be referring to the above part of the code. What we're doing here is reversing the URL of the page we are currently on. So, if were were on "http://www.myserver.com/path/to/file/somefile.php" it would be reversed to "php.elifemos/elif/ot/htap/moc.revresym.www//:ptth". With me so far? Then, it performs strstr() on that string, returning the string starting with the first "/". In our example, that would be "/elif/ot/htap/moc.revresym.www//:ptth". We then reverse it again, and are left with "http://www.myserver.com/path/to/file/".

It's a quick and dirty way of returning the path, when you need to trim off the filename and any querystring variables.

Sorry for the confusion. Hope that answers your question.
 
Old June 7th, 2004, 01:58 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Buzzly thanks sooooooooooooooooo much. I am so sorry about the page confussion. But I usually read the book from the pdf file which comes on the cd, so the page I gave you was the page number of the pdf file. I was actually asking about the code from page 298, because I kind of skipped all the code after that until chapter 11, except for the explanation of the md5 function. The explanation of the postcard aplication is not enough, so I got kind of lost, but I think I got the idea about the confirmation thing.

Thanks so much once again.
Christian

 
Old June 7th, 2004, 04:05 PM
Authorized User
 
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No problem. If there is an area that you find confusing because it's not explained well or even at all, please let us know, and maybe we'll fix that in the next revision.

Keep on truckin!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to Data Table Explain msbsam ASP.NET 1.0 and 1.1 Professional 1 October 30th, 2006 02:20 AM
Can someone explain this code to me pandu345 Java Basics 2 October 6th, 2006 12:25 PM
could any one explain this code for me ? method Access VBA 1 August 13th, 2005 02:02 AM
explain please rein Javascript 3 January 31st, 2005 09:47 AM
could any one explain this query to me somanchivasu Access 3 April 6th, 2004 08:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.