Username:
Password:
Remember me:
Register

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Search forums via Google


0 Users appreciate this thread.

One page login/home
 >  >>
Started by angelrulez7
(2014-01-06 10:35:36)
angelrulez7 (2014-01-06 10:35:36)
The title is not very specific, but I shall explain here.

So, basically, I have recently seen sites that have a homepage that if $_SESSION['username'] has no variable, it redirects you to "login.php" to login. I find it inconvinient because you need to keep being redirected. As well as Android's default browser (DO NOT USE) disliking multiple server redirects.

Here is a basic code (that probably anyone can guess but doesn't think to do) that can resolve this problem.

[code=*php]
<?php
session_start(); //Can be changed if you do not use sessions
$username = $_SESSION['username']; //Make it easier, can be changed to your display code

if($username){
echo 'Welcome, ' . $username . '!<br>Durhur stuff here';
}else{
echo 'Welcome, Guest!' . '<br>
<form action stuff and stuff>
Username:<br><input username><br>
<input pass><br><tickbox and whatnot>
Remember me?<br><input type submit stuff>
</form><br><new account link>'; //Be sure to edit this correctly!
}
?>[/code]

I've just made a basic homepage (very lazily and with no real html on the login form) with 2 versions. One part (if $username is active) for the main homepage, and one part ($username is not active) for the login form.

If I messed up on the code, please tell me. It's 2:35 AM and I needed something to do.

Good luck on your coding ventures!

This post has been edited one or more times, the last time was:
2014-01-08 01:53:19

a
angelrulez7 (2014-01-07 03:39:57)
I've never really found a problem with using the code. ^

EDIT: I see where you're going, but all processes are stored in one file with me.

This post has been edited one or more times, the last time was:
2014-01-07 04:02:10

a
(Capt.)Orb (2014-01-07 23:27:40)
You need to expand the variable to actually get the value of $username...

To show you, this is one way of doing it..

Also, you forgot a = on the input bar.


Source Code
<?php session_start(); //Can be changed if you do not use sessions $username = $_SESSION['username']; //Make it easier, can be changed to your display code if($username){ echo "Welcome, $username!" . '<br>Durhur stuff here'; }else{ echo 'Welcome, Guest!' . '<br> <form action stuff and stuff> Username:<br><input username><br> <input pass><br><tickbox and whatnot> Remember me?<br><input type=submit> </form><br><new account link>'; //Be sure to edit this correctly! } ?>


This post has been edited one or more times, the last time was:
2014-01-07 23:31:01

Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
angelrulez7 (2014-01-08 01:19:46)
I didn't put an equal because the HTML isn't real... ._. ^
a
angelrulez7 (2014-01-08 01:51:00)
[code=*php]
<?php
//I made a workaround for my login. I also fixed a few mistakes and disabled the Guest feature
include('include/session.php'; //Can be changed if you do not use sessions
$username = $session->username; //Make it easier, can be changed to your display code
if($_GET['log']){
$username = 'FakeUser';
}else
if($username == "Guest"{
$username = '';
}

if($username){
echo 'Welcome, ' . $username . '!<br>Durhur stuff here';
}else{
echo 'Welcome, Guest!' . '<br>
No login here because it was not real html'; //Be sure to edit this correctly!
}
?>[/code]

Try http://social-ring.tk/proof.php (While not logged in to SocialRing, make sure of that) and then click the link there. There is no problem at all.

This post has been edited one or more times, the last time was:
2014-01-08 01:52:15

a
PLMasterSSB (2014-01-08 05:48:51)
yes, its easier that way. but in some cases, redirects may be needed.
angelrulez7 (2014-01-08 06:01:22)
Why would redirects be needed?
a
(Capt.)Orb (2014-01-08 17:36:04)
Ah, I saw you edited your first post to .$username.


This post has been edited one or more times, the last time was:
2014-07-09 05:23:27

Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
angelrulez7 (2014-01-09 07:17:41)
I found that problem on my own. o.o ^
a
(Capt.)Orb (2014-01-09 20:45:17)
^ Very well, I don't really care. Just being kind by reporting errors.
Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
angelrulez7 (2014-01-09 23:26:49)
"You can't fool me easily, AR7." I still don't get it.
a
(Capt.)Orb (2014-01-11 00:21:29)
Never mind..
Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
joemckellar20 (2014-05-07 04:17:10)
it's not working
[REMOVE REQEST]

This post has been edited one or more times, the last time was:
2014-05-07 11:18:27

angelrulez7 (2014-05-07 05:06:31)
...for one, you don't even have a login...
a
~Justin~ (2014-06-22 05:01:46)
Dumb
 >  >>

Log in to submit a comment

This topic's ID: 67459

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved