473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to redirect the refer page after loggin ?

62
Well, actually im bad in this im not sure if i post the title correctly...

My problem is I make a site which people can comment the picture each other..
every comment will be sent to their email to lead them to see that comments page......but they have to login first......

My problem is howto do that ? for example i set like this

u have got a comment on your pic if u want to see it just loggin
www.mysite.com/see_img.php?id=10278

after they click on it they have to login first and i dont know how to do to make them go to that pćage directly after they login.

Im so sorry if my language is not good enaugh
paitoon
Sep 7 '07 #1
5 2161
Atli
5,058 Expert 4TB
Hi.

You could save the ID of the image, the one you with the see_image.php, to a session variable. Then it would be saved throughout the session and you could call it wherever you want.
Sep 8 '07 #2
paitoon
62
My problem is the first page after logg in is not see_img.php.....but it is home.php

so, I try to do like this--->if the session is logged in it no problem because after people click on the link they could go to see the comment on the see_img.php....but if they are not logged in then they have to go go to logg in first...i use header( "Location: login.php"); exit();

But after that i dont know how to take the variable to the login.php or u can say i dont even know the system....i tried to do what you gave me the direction but i maybe too stupid to understand what u saaid.....ohhhh......sadd....i dont want to give up..because this is the last problem i get now befire i invite people to my web site...i got stress with this for many days now...

:-/
Paitoon
Sep 9 '07 #3
Atli
5,058 Expert 4TB
Ok. Think of it this way.

When your users enter see_image.php you set a session variable containing the Image ID of the image they are viewing. Somewhat like this:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['lastImg'] = $_GET['id'];
  2.  
When they are done with the user login, you check that variable.
If it is set, grab the value from it, unset() it and redirect your user the the see_img.php using the ID you grabbed from the session:
If it is not set, redirect them to home.php.
Expand|Select|Wrap|Line Numbers
  1. if(isset($_SESSION['lastImg'])) {
  2.   $id = $_SESSION['lastImg'];
  3.   unset($_SESSION['lastImg']);
  4.   header("Location: see_img.php?id=$id");
  5. }
  6. else {
  7.   header("Location: home.php");
  8. }
  9.  
You would also need to check if this session variable is set when you enter home.php and unset() it if it is, just so you wont get redirected to the last image you viewed when you log in from there.
Expand|Select|Wrap|Line Numbers
  1. if(isset($_SESSION['lastImg'])) {
  2.   unset($_SESSION['lastImg']);
  3. }
  4.  
And remember to always put session_start() at the top of each page.
Sep 9 '07 #4
kovik
1,044 Expert 1GB
Security risks aside from saving an unfiltered GET variable, that is a good solution. A more permanent one would be to have some sort of central authorization that you use to handle that sort of thing. For example, maybe have a simple script like this:

[php]if (!$currentUser->isLoggedIn()) {
$_SESSION['lastPage'] = $_SERVER['REQUEST_URI'];
header('Location: http://domain.tld/login.php');
}[/php]

And include that script into every file that requires user authorization (*after* session_start(), of course). Then, login.php could use $_SESSION['lastPage'] for redirection.

Another thing you may want to add is another sort of central thing that destroys that session variable if you go anywhere but on login.php so that the user would always be directed to where they were expecting.
Sep 9 '07 #5
paitoon
62
You are very good....thank you so much i proved it .......:-)
Sep 9 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Vic Spainhower | last post by:
Hello, I just purchased a new domain name and I've set it up as a redirect to a folder on my main site. What is happening is the index.php page checks a session variable to see if the user is...
1
by: Tony Zoccolillo | last post by:
I have a toolbar aspx page in a frameset. On the toolbar is a dropdownlist. The frameset is launched from an outside source and comes in with a specific parameter for the module desires, like......
3
by: Alan Silver | last post by:
Hello, Sorry if this is a stupid question, but I can't really see much difference between these tow methods according to the scant info in the SDK. Could anyone enlighten me? TIA -- Alan...
8
by: Laith Zraikat | last post by:
I am trying to invoke a post request from code behind of an asp.net page using "WebClient" object, and I want the user to be redirected to the action url as well. So far Ive been able to send...
3
by: André | last post by:
Hi, I want to include a graphic made in file2 into file. File must first send a value to file2 (with Response.Redirect) which will be used for the graphic. My problem is that only the graphic is...
12
by: =?Utf-8?B?cGI=?= | last post by:
I am having trouble doing a redirect in an async asp.net implemention. Most of the time it works, but when it doesn't it just "hangs", the browser never gets any return page. If I run it under the...
11
by: DavidOwens | last post by:
hey guys i have 5regions, and i would like to redirect a region manager to the region page of der choice. so say David Price wants to go to his region, which wouyld be region 2, so they...
2
by: RuthC | last post by:
Hi, In my website there is a facility for user to create there own pages we are maintaing this url as www.mywebsite.com/mypage/user created page name ex : www.mywebsite.com/mypage/ruth user...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login page into every page. Thanks, -Billy
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.