Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
After Login go back to original Page.
Old 11-10-2009, 06:59 PM After Login go back to original Page.
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
I have this script, its a login script. Currently after logging in and checking the login it goes to accounts.php

Goes on top of the webpage:
PHP Code:
<?php
session_start
();
if(!
session_is_registered(myusername)){
header("location:accounts-login.php");
}
?>
Form:
PHP Code:
<form autocomplete="off" id="form" method="post" action="checklogin.php">
<
h1>Login Form</h1>
<
p>Please log in to the admin area to view logged accounts.</p>

<
label>Username
<span class="small">Minsize 6 chars</span>
</
label>
<
input name="myusername" type="text" id="myusername" size="20" />


<
label>Password
<span class="small">Minsize 6 chars</span>
</
label>
<
input name="mypassword" type="password" id="mypassword" size="20" />

<
button name="submitBtn" type="submit"></button>
<
div class="spacer"></div>

</
form
checklogin.php
PHP Code:
<?php
require "inc/config.php";
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);
$sql="SELECT * FROM `admin` WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "accounts.php"
session_register("myusername");
session_register("mypassword");
header("location:accounts.php");
}
else 
{
header('Location:accounts-login.php');
}
?>
Lets say I was at contact.php, and I had no session, it would redirect me to accounts-login.php

after I login it takes me to accounts.php.

Accounts.php is like the index of the folder.

What I need is for it to take me back to the page I was viewing before.

Kind of like in vbulletin, if your viewing a thread and ur not logged in, when u login it takes u back to the thread.

Is that possible?
__________________
MY MSN:
Please login or register to view this content. Registration is FREE

PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-10-2009, 07:14 PM Re: After Login go back to original Page.
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
When you reach the login page, where the user is redirected if not logged in, save the path to the previous page (SERVER['HTTP_REFERER']) in a session. Be aware of, though, that the SERVER['HTTP_REFERER'] isn't always available, so you should check if it is set first. Then when the user has logged in redirect him the the stored page.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-10-2009, 07:16 PM Re: After Login go back to original Page.
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Store the current page in a session variable before you redirect:
PHP Code:
$_SESSION['prev_page'] = $_SERVER['REQUEST_URI']; 
Then redirect back to that page after the login in processed

PHP Code:
header('Location: ' $_SESSION['prev_page']); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-10-2009, 07:22 PM Re: After Login go back to original Page.
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
Ugh... what??

Like:

PHP Code:
<?php
session_start
();
$_SESSION['prev_page'] = $_SERVER['REQUEST_URI'];  
if(!
session_is_registered(myusername)){
header("location:accounts-login.php");
}
?>
and


PHP Code:
 <?php
require "inc/config.php";
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);
$sql="SELECT * FROM `admin` WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "accounts.php"
session_register("myusername");
session_register("mypassword");
header('Location: ' $_SESSION['prev_page']);  
}
else 
{
header('Location:accounts-login.php');
}
?>
Is that correct?
__________________
MY MSN:
Please login or register to view this content. Registration is FREE

PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-10-2009, 07:38 PM Re: After Login go back to original Page.
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Assuming that config.php starts the session then yes. Also, you should hash your passwords rather than store them raw.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-10-2009 at 08:00 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to After Login go back to original Page.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21562 seconds with 12 queries