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
Header function problem?
Old 12-08-2011, 03:29 PM Header function problem?
Novice Talker

Posts: 14
Trades: 0
Hello. I have one problem with header function in my login script. The code is:

PHP Code:
$_SESSION["username"] = $dbusername;
        
$username1 $_SESSION['username'];
        
$_SESSION["myusername"]=$dbusername;
        
$sql1 "SELECT admin FROM admin WHERE username=$username1";
        
$result1 mysql_query($sql1) or die(mysql_error());
        while (
$row1 mysql_fetch_array($result1))
        {
            
$admin $row1['admin'];
            if (
$admin != '1')
            {
                
header("Location:../sales/");
            }
            else
            {
                
header("Location:index.php");
            }
        } 
When i log in, it opens checklogin.php file, but it don't redirect me to 'index.php'. But, when is $admin != '1', it redirects me to sales folder. I don't know what to do. Thanks.
Ivan96 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-08-2011, 03:40 PM Re: Header function problem?
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Try:

PHP Code:
header("Location: /index.php"); 
with a / in front of index.php
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 12-08-2011, 03:41 PM Re: Header function problem?
Novice Talker

Posts: 14
Trades: 0
Again the same
Ivan96 is offline
Reply With Quote
View Public Profile
 
Old 12-08-2011, 04:01 PM Re: Header function problem?
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
You can try just the / without the index.php after, though I'm going to guess that won't work either. You could also try the absolute path to the domain.

You're saying it does work when you're not an admin and it takes you to the sales page?

I'm assuming the index.php page is at the root of the domain.

Try adding some other random page instead of the index.php page and see if you get redirected there. If you can redirect to the other page then the issue is how you're trying to redirect to the index.php page. If you can't get redirected to any page as admin then the system isn't understanding you're an admin and something in the programming logic needs to be fixed.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 12-08-2011, 04:09 PM Re: Header function problem?
Novice Talker

Posts: 14
Trades: 0
I tried to change the index.php, and it isn't working. I can send you whole code, if you want.
Ivan96 is offline
Reply With Quote
View Public Profile
 
Old 12-09-2011, 12:10 AM Re: Header function problem?
Junior Talker

Posts: 2
Trades: 0
I also have the same problem

Any updates on this one?
__________________

Please login or register to view this content. Registration is FREE
tobiwan is offline
Reply With Quote
View Public Profile
 
Old 12-09-2011, 05:08 AM Re: Header function problem?
Novice Talker

Posts: 14
Trades: 0
Hello. I found problem. It was in SQL query. My query was:

PHP Code:
$sql1 "SELECT admin FROM admin WHERE username=$username1"
I changed it:

PHP Code:
$sql1 "SELECT admin FROM admin WHERE username='$username1'"
I didn't put '' on $username.
Thanks anyway. Bye.
Ivan96 is offline
Reply With Quote
View Public Profile
 
Old 12-09-2011, 02:25 PM Re: Header function problem?
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I'm glad you were able to find the fix.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 12-09-2011, 05:31 PM Re: Header function problem?
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Lesson 1: Always test results of things like db queries.

Lesson 2: Put an exit(); after the header call ...
__________________

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


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Header function problem?
 

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.75637 seconds with 12 queries