0

I'm new in php. I recently go through one login example in php (http://net.tutsplus.com/articles/news/build-a-login-and-registration-system-with-xml/) and implemented login page for my test site in local host.

But now i want to assing each user one image let say i have 3 user and i have 3 user xml under user folder and each xml should look something like this

<?xml version="1.0"?>
<user>
    <password>some password will come here</password>
    <email>[email protected]</email>
    <img>images/mynewimage.jpg</img>
</user>

i added <img> node in xml but i don't know how to call that on php page. Here the biggest challenge is for me is to find out the current user on each page since i have 3-4 basic pages after login and i'm maintain his login on each page so i want his image also on all the page i given below code on each page to maintain session

<?php
session_start();
if(!file_exists('users/' . $_SESSION['username'] . '.xml')){
    header('Location: login.php');
    die;
}
?>

when i check with username <?php echo ucfirst($_SESSION['username']); ?> it shows me current user name but in same way i'm unable to call image next to username.

3
  • are you able to get password and email of that current user??are you maintaining one xml per user?? Commented Aug 23, 2012 at 7:56
  • yes rest all information i can get. I'm maintaining one xml for each user. Since my requirement is of 10 user max and i don't want to use any database so i'm good with 10 xml for each 10 user. Commented Aug 23, 2012 at 8:01
  • ok then check the below answer or fetch the values of ima the same way you are fetching email.if you can get the email then you should also be able to get img in the same way if not then put the code snippet you are using to get email of user from that xml Commented Aug 23, 2012 at 8:04

2 Answers 2

1

use simplexml_load_file()

$xml = simplexml_load_file('users/' . $_SESSION['username'] . '.xml');
echo $xml->img;
Sign up to request clarification or add additional context in comments.

1 Comment

Thx mihai :) its done now i just change echo '<img src='. $xml->img .'>'; its working fine... thank again u save my life :)
0

the first thing you have to do is parse your xml file.php have a function for this:

$xmls = simple_xml_load_file(your_file's_exact_path);
$image = $xml->img;

if you have many img elements in your xml file you have to use foreach loop for that like:

foreach($xmls as $xml)
{
 $xml->img;
 $image = implode(',',$$xml->img;);
}

this code parse you xml file and save all images to the variable $image. now you can use it as you want.make sure about the img element's path. just try with this. it will help you. happy coding!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.