[thelist] PHP help needed

Scott DeMers demerss1 at msu.edu
Mon Nov 28 19:47:41 CST 2005

You're on the right track, it seems. The image source name is nothing  
but a string, so you should be able to concatenate any number of  
variables to any number of static strings. The proper way (although  
you can cheat in PHP) is something like the following:

1. $username = $_POST['username'];
// if you do it this way, be sue the login form uses POST as the action

2. $image_src =  "<image src="images/' . $username . '" />";
// the dots are what do the concatenating. Notice I used single  
quotes on the outside of each dot. This is so as not to interfere  
with the double quotes which are part of the HTML. If my HTML uses  
single quotes, then I  concatenate with double quotes.

3. echo $image_src;
//if my user name is Bob, then  <image src="images/Bob" /> is what  
should be the final product.

If this seems confusing, read up on strings and variables here:  

hope this helps.


On Nov 28, 2005, at 7:13 PM, Flavia Tarzwell (FayeC) wrote:

> I am sorry to bug you but I am lost. I am still learning PHP and I  
> think
> I got myself into things I am not able to do yet....
> I have a simple login (no need for secure login - as instructed by the
> site's owner - she *requested* that the login uses only a username, no
> password), the login is not validated against a db or anything....it's
> basically only a way to sort through image files and display only the
> associated files.
> So, the login sends the user to a page called gallery.php where 4  
> images
> are displayed. The images are named user1_1.jpg, user1_2.jpg,
> user1_3.jpg and user1_4.jpg.
> The images are displayed and arranged in the page and I have the src
> pointing to $username_1.jpg, $username_2.jpg, $username_3.jpg and
> $username_4.jpg.
> The problem is selecting the images from the images folder.
> I have been struggling to write the right code to grab the username  
> from
> the form and then use that in the path to the images (I thought it  
> would
> be a good idea to have folders named after the username inside the
> images folder like images/user1, images/user2 and the whenever the  
> user
> logs in with the username the username is then added to the path to  
> the
> images and all images in that specific folder are loaded...
> But since I *know* only 4 images are to be displayed then the  
> images can
> be put in the images folder together but the name of the images  
> need to
> be user#_1.jpg, etc....
> Maybe I am complicating things more than they need to be.
> Could I just get the username using:
> <?php
> $username = $_POST['username'];
> ?>
> And then use $username in the image source name?
> Is that the solution?
> Has anybody done something similar?
> *And yes, I did explain to the client about the security issues of not
> having a password and not validating the password/username but she
> explained it was not a matter of safety as the images were for public
> display anyways. The images are screenshots taken during ultrasound
> exams and they are posted online for the extended family to view so  
> the
> only concern is really selecting the right images for the right
> costumer/user.
> Thank you in advance for any tips,
> FayeC
> -- 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

More information about the thelist mailing list