Replace PHP with text [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have some PHP that displays the users session name in the HTML and if the user is not logged in, then I would like it to display "User" instead.
Can I have an if statement in this case? I tried it myself but I got header errors.
This is what I've tried so far but each practical attempt just spits out more errors at me.
This is a different approach I have tried.
<?=$_SESSION['sess_user'] or ("User");?>!

<?php echo (isset($_SESSION['sess_user']) ? $_SESSION['sess_user'] : "User"); ?>
This will check if the session is set, if it is then echo the session, if it isn't then it will echo "User".

Related

How do I change the Default Design? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have two different web designs(Created in PHP, HTML, CSS and JavaScript) Can I upload both and just switch them from time to time?
How do I redirect so i can choose what design will show when i open my website?
Try with this code :
if(some condition here)
header('Location:design1.php');
else if(some condition here)
header('Location:design2.php');
or you can also use include function.
if(some condition here)
include("design1.php");
else if(some condition here)
include("design2.php");
Thanks.

How do I access the elements in this php array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Im using a login code snippet from a friend in one of my apps.
He accesses the user logged in by doing:
$username_from_cookie = $_COOKIE[$cookiename];
How can I get the other elements in that array?
I've tried print_r() and the page returns blank as if php parsing stopped.
You can use print_r() or var_dump() to inspect the contents of the $_COOKIE array. Like so:
var_dump($_COOKIE);
or:
print_r($_COOKIE);
Hope this helps :)

How can i store and fetch.php page in mysql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a project in which i have to make a code in which when we click on menu bar and the option that we select in menu bar the page related to that option will display all this is to be done through my sql.Is there any way to do this task.
I don't understand exactly what you want and if there is a better way to do this, but don't put in your sql fields PHP code.
You can create a xml document instead, and use it better.PHP.net - XMLdocument

Php redirect, not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a form with an add user button. If the user is added, the page should redirect to another page which would allow you to edit that user.
What I currently do is:
if ($user_added) {
<META HTTP-EQUIV=refresh CONTENT='0;
URL=<php echo $root. "Path1/path2/path3/userEdit.php?ID=".$newUser->GetID(); ?>'>
NOTE: ID is not something you can switch to easily, its a different more complicated number that i generate randomly whenever I add users, for the sake of the question i kept it simple.
UPDATE: This changes the page to the userEdit page but it does not load the data from the new user.
You are mixing html and php. PHP redirects can be done with a header BEFORE the page loads like so:
<?php header('Location: http://mywebsite.com/index.php'); ?>
But again this only works if the content has not yet been sent.
Also:
URL=<php echo $root. "Path1/path2/path3/userEdit.php?ID=".$newUser->GetID(); ?>'>
This is also insecure because any user can access any user's page simply by changing the url.

Display text based on SESSION in PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following line of code that displays a user's first name once logged in. I had text that says Welcome, before the echo statement but it looks silly unless you are logged in. Is there a quick way to only display Welcome, if the session FirstName is not empty?
<h2><?php echo "".$_SESSION['FirstName'];?></h2>
I'd like to use PHP isset but I still don't know how to hide Welcome, and display only if the session contains data.
Best way to check the variable or array value exist or not, you can use isset. For ypur case, you can do as follow.
<h2><?php echo ( isset($_SESSION['FirstName'])?"Welcome":"");?></h2>

Categories