PDA

View Full Version : Using the echo language construct


sydesign
03-19-2012, 07:27 PM
I'm pretty new to php and still am not understanding some things.

I am going through a tutorial on making a membership log-in system i got it working mostly. the issue I'm having now is that the way the tutorial was set up is that when a user is logged in it echoes out a message "welcome user" or something like that. however i would like to have it echo out the webpage i have already created. i looked it up and saw that you can't add quotes within the echo string. is there another way i can have the echo statement show the webpage without me having to input the html (and fix all the quotes) after within the string?

the code i have right now is

<?php
error_reporting (E_ALL ^ E_NOTICE );
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];


if ($username && $userid){
echo "Welcome Sydesign!";

}
else
echo "Please login to access this page. <a href='../login.php'>Login here</a>";

?>

where it says "Welcome Sydesign!" i want it to display the webpage i already created. I'm sure there are many other ways to do this and I'm open to anything i just want to learn how to do it right.

thank you so much for any help.

edbr
03-20-2012, 01:50 AM
it might be simpler to use location to redirect if they are logged in try this (edit the page name of course :) )

<?php
error_reporting (E_ALL ^ E_NOTICE );
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];


if ($username && $userid){
header( 'Location: http://www.yoursite.com/new_page.html' ) ;

}
else
echo "Please login to access this page. <a href='../login.php'>Login here</a>";

?>

sydesign
03-20-2012, 05:23 PM
okay thank you. I got it to work finally. Figured out how to make a heredoc statement work and it seems to be working fine for now. But that will be good to know for the further thank you!