NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP, sign in then return to previous page

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-22-2005, 05:32 AM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




PHP, sign in then return to previous page


Good day. When a user signs in on my website, they are automatically redirected to the "Member's Area" section of the website. How can I make it so that they are redirected to the page they were on before signing in. (eg. thread in a forum)? Thanks
Encenta.com is offline  
Old 10-22-2005, 05:44 AM   #2 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Hello,

Could you please post the php and a url of the login script.

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 05:56 AM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




PHP Code:
<?php
##
$signout $_GET["signout"];
if (
$signout == "true")
{
session_start();


if (isset(
$_SESSION['logged_in'])) {
   unset(
$_SESSION['logged_in']);
}
session_destroy();


header('Location: index.php');
}
##
elseif ($_POST['submit']) { 
include(
"config.php");

$passwordbeforemd5 $_POST['password'];

$username $_POST['username'];
$password md5($passwordbeforemd5);

$query mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'") or die(mysql_error());

$i=0;
while (
$i $num) {
$sesid mysql_result($query,$i,"user_id");
$sesaccount mysql_result($query,$i,"account"); 
????: NamePros.com http://www.namepros.com/programming/133907-php-sign-then-return-previous-page.html

$i++;
}



session_register("username""password""sesid""sesaccount");

$sql mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1");


$login_check mysql_num_rows($sql);

if (
$login_check == "1") {
$_SESSION['logged_in'] = true;
include (
"membersarea.php");
}
else {
include(
"head.php");
session_unset();
echo 
"<h1>Error</h1><p>Your attempt at logging in failed. If you feel as if there is
a problem, email the administrator at [email]admin@darkfx.co.uk[/email] or use the contact form</p>"
;
include(
"foot.php");
????: NamePros.com http://www.namepros.com/showthread.php?t=133907
}
}



#################################################################

else { include("head.php"); 
echo 
"<h1>Sign in </h1>";

$auth $_GET['auth'];
if (
$auth=='2') {
echo 
"<p>You must be signed in to access this page</p>"; }

echo 
"<form method='post' action='signin.php'>
<table width='50%'  border='0'>
  <tr>
    <td width='33%'>Username</td>
    <td width='67%'><input name='username' type='text' class='inputbox' id='username'></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input name='password' type='password' class='inputbox' id='password'></td>
  </tr>
  <tr>
    <td height='45'>&nbsp;</td>
    <td><input type='submit' name='submit' value='Sign in' class='inputbox'></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
    <tr>
    <td align='left'><a href='register.php'>need to register?</a></td>
    <td align='right'>&nbsp;</td>
  </tr>
</table>
</form>"
;
include(
"foot.php");
}
?>
http://www.darkfx.co.uk/darkfx/signin.php

Thanks
Encenta.com is offline  
Old 10-22-2005, 06:13 AM   #4 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Hello,

I have edited it to redirect back two pages insted of displaying member area.
It displays Do you want to go to member area or back to previous page. If they click member area it goes to member area. If they click back it goes back 2 pages. (Or back to previous page)
PHP Code:
<?php
##
$signout $_GET["signout"];
if (
$signout == "true")
{
session_start();


if (isset(
$_SESSION['logged_in'])) {
   unset(
$_SESSION['logged_in']);
}
session_destroy();


header('Location: index.php');
}
##
elseif ($_POST['submit']) {
include(
"config.php");

$passwordbeforemd5 $_POST['password'];

$username $_POST['username'];
$password md5($passwordbeforemd5);

$query mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'") or die(mysql_error());

$i=0;
while (
$i $num) {
$sesid mysql_result($query,$i,"user_id");
$sesaccount mysql_result($query,$i,"account");

$i++;
}



session_register("username""password""sesid""sesaccount");

$sql mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1");
????: NamePros.com http://www.namepros.com/showthread.php?t=133907


$login_check mysql_num_rows($sql);

if (
$login_check == "1") {
$_SESSION['logged_in'] = true;
if(
$memberarea == 'yes') {
include (
"membersarea.php");
}else{
print 
"Click <a href="signin.php?memberarea=yes">here</a> to go into member area. Click <a href="#" onclick="javascript:history.back(2)">here</a> to return to previous page.
}
else {
include(
"head.php");
session_unset();
echo 
"<h1>Error</h1><p>Your attempt at logging in failed. If you feel as if there is
a problem, email the administrator at [email]admin@darkfx.co.uk[/email] or use the contact form</p>"
;
include(
"foot.php");
}
}



##################################################  ###############

else { include("head.php");
echo 
"<h1>Sign in </h1>";

$auth $_GET['auth'];
if (
$auth=='2') {
echo 
"<p>You must be signed in to access this page</p>"; }

echo 
"<form method='post' action='signin.php'>
<table width='50%'  border='0'>
  <tr>
    <td width='33%'>Username</td>
    <td width='67%'><input name='username' type='text' class='inputbox' id='username'></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input name='password' type='password' class='inputbox' id='password'></td>
  </tr>
  <tr>
    <td height='45'>&nbsp;</td>
    <td><input type='submit' name='submit' value='Sign in' class='inputbox'></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
    <tr>
    <td align='left'><a href='register.php'>need to register?</a></td>
    <td align='right'>&nbsp;</td>
  </tr>
</table>
</form>"
;
include(
"foot.php");
}
?>
Can you test it and tell me if it works?

iNod

Here is an edited version without the error.

PHP Code:
<?php
##
$signout $_GET["signout"];
if (
$signout == "true")
{
session_start();


if (isset(
$_SESSION['logged_in'])) {
   unset(
$_SESSION['logged_in']);
}
session_destroy();


header('Location: index.php');
}
##
elseif ($_POST['submit']) {
include(
"config.php");

$passwordbeforemd5 $_POST['password'];

$username $_POST['username'];
$password md5($passwordbeforemd5);
????: NamePros.com http://www.namepros.com/showthread.php?t=133907

$query mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'") or die(mysql_error());

$i=0;
while (
$i $num) {
$sesid mysql_result($query,$i,"user_id");
$sesaccount mysql_result($query,$i,"account");

$i++;
}



session_register("username""password""sesid""sesaccount");

$sql mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1");


$login_check mysql_num_rows($sql);

if (
$login_check == "1") {
$_SESSION['logged_in'] = true;
if(
$memberarea == 'yes') {
include (
"membersarea.php");
}else{
print 
"Click <a href='signin.php?memberarea=yes'>here</a> to go into member area. Click <a href='#' onclick='javascript:history.back(2)'>here</a> to return to previous page.";
}
else {
include(
"head.php");
session_unset();
echo 
"<h1>Error</h1><p>Your attempt at logging in failed. If you feel as if there is
a problem, email the administrator at [email]admin@darkfx.co.uk[/email] or use the contact form</p>"
;
include(
"foot.php");
}
}



##################################################    ###############

else { include("head.php");
echo 
"<h1>Sign in </h1>";

$auth $_GET['auth'];
if (
$auth=='2') {
echo 
"<p>You must be signed in to access this page</p>"; }

echo 
"<form method='post' action='signin.php'>
<table width='50%'  border='0'>
  <tr>
    <td width='33%'>Username</td>
    <td width='67%'><input name='username' type='text' class='inputbox' id='username'></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input name='password' type='password' class='inputbox' id='password'></td>
  </tr>
  <tr>
    <td height='45'>&nbsp;</td>
    <td><input type='submit' name='submit' value='Sign in' class='inputbox'></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
    <tr>
    <td align='left'><a href='register.php'>need to register?</a></td>
    <td align='right'>&nbsp;</td>
  </tr>
</table>
</form>"
;
include(
"foot.php");
}
?>
iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 06:31 AM THREAD STARTER               #5 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Many thanks iNod. I made a few ammendments but when the "previous page" link is clicked, it takes the user back to the sign in page. Example:

http://www.darkfx.co.uk/darkfx/signin.php

username: username
password: password

Thanks again
Encenta.com is offline  
Old 10-22-2005, 06:41 AM   #6 (permalink)
Senior Member
 
scribby's Avatar
Join Date: May 2005
Location: Australia
Posts: 1,196
scribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of light
 



You could just like

header (location: afterlogin.php);
scribby is offline  
Old 10-22-2005, 06:43 AM   #7 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
CHange history.back(2) to (-2)

Try that

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 07:09 AM THREAD STARTER               #8 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Still doesn't work Thanks anyway.

What would i put in "afterlogin.php", scribby?
Encenta.com is offline  
Old 10-22-2005, 07:16 AM   #9 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Do this

Change
Click <a href='#' onclick='javascript:history.back(2)'>here</a> to return to previous page.

To
Click <a href="javascript:history.go(-2)()">here</a> to return to previous page.

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 07:17 AM   #10 (permalink)
NamePros Regular
 
nick's Avatar
Join Date: Jun 2004
Location: Iowa City
Posts: 703
nick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud of
 


Save The Children
why not when you click Sign Url button have something like this:

href="signin.php?r=http://www.yoursite.com/blah/prevoiuspageblah.php"

and you could just store "r" in a session/cookie/or a hidden form field



i use a hidden form field

and then instead of doing javascript(-2) or something like that, you get an exact url for the visitor to use (in case user doesnt allow javascript? lol)
__________________
formally ninedogger
------
Want to talk to a stranger? -->| Click Here | TalkToAStranger.com | <-- Meet New Friends
nick is offline  
Old 10-22-2005, 07:18 AM   #11 (permalink)
Senior Member
 
scribby's Avatar
Join Date: May 2005
Location: Australia
Posts: 1,196
scribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of lightscribby is a glorious beacon of light
 



Ah sorry didn't read the whole thread.

This should do the trick

<a href = "javascript:history.back(-2)"> Go back </a>
scribby is offline  
Old 10-22-2005, 07:26 AM   #12 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Originally Posted by ps2gamer
why not when you click Sign Url button have something like this:

href="signin.php?r=http://www.yoursite.com/blah/prevoiuspageblah.php"

and you could just store "r" in a session/cookie/or a hidden form field



i use a hidden form field

and then instead of doing javascript(-2) or something like that, you get an exact url for the visitor to use (in case user doesnt allow javascript? lol)
I don't think you can do that you would need to track him on every page he visits because HTTP_REFERRER only works on some browsers and isn't always correct.
????: NamePros.com http://www.namepros.com/showthread.php?t=133907

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 07:29 AM THREAD STARTER               #13 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




It worked! Thanks very much iNod
Encenta.com is offline  
Old 10-22-2005, 07:30 AM   #14 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Anytime miseria.

I am glad it worked for you

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 08:13 AM   #15 (permalink)
NamePros Regular
 
nick's Avatar
Join Date: Jun 2004
Location: Iowa City
Posts: 703
nick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud of
 


Save The Children
Originally Posted by iNod
I don't think you can do that you would need to track him on every page he visits because HTTP_REFERRER only works on some browsers and isn't always correct.
????: NamePros.com http://www.namepros.com/showthread.php?t=133907

iNod

It wouldn't be using http_referrer it would be actually getting the URL of the current page and just adding it to the signin link

but you know a simplier way, nice
__________________
formally ninedogger
------
Want to talk to a stranger? -->| Click Here | TalkToAStranger.com | <-- Meet New Friends
nick is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
HOWTO: Install the Apache Web Server, Perl, PHP, and MySQL on Windows deadserious Webmaster Tutorials 96 05-27-2007 01:24 PM
Need help on one page PHP project Jim_Westergren Web Development Wanted 5 09-15-2005 08:40 PM
Tutorial: Simple site management with the use of PHP and the query string(?page=1) deadserious Webmaster Tutorials 8 10-09-2004 01:20 PM
Tutorial: Using PHP require() & include() Dave S Webmaster Tutorials 5 03-22-2004 12:40 AM

 
All times are GMT -7. The time now is 02:02 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger