Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 6th, 2004, 11:21 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Fairfield, Iowa, USA.
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
Reply With Quote
  #2 (permalink)  
Old June 7th, 2004, 12:27 AM
Authorized User
 
Join Date: May 2004
Location: , , .
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.
Reply With Quote
  #3 (permalink)  
Old June 7th, 2004, 02:58 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Fairfield, Iowa, USA.
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

Reply With Quote
  #4 (permalink)  
Old June 7th, 2004, 05:05 PM
Authorized User
 
Join Date: May 2004
Location: , , .
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!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:25 PM
could any one explain this code for me ? method Access VBA 1 August 13th, 2005 03: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 09:23 PM



All times are GMT -4. The time now is 02:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.