Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:44:12+00:00 2026-06-05T08:44:12+00:00

I have a checklogin.php script that works fine to redirect a user to a

  • 0

I have a checklogin.php script that works fine to redirect a user to a specific page on successful login. I now want to set it to redirect to the original index.php page that redirected the user to the login form. At the top of index.php I include:

<?php
session_start();

$_SESSION['url'] = $_SERVER['REQUEST_URI'];

if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

I have checked that $_SESSION[‘url’] is getting correctly set on this page.

main_login.php just contains the login form which is processed by checklogin.php:

<form name="form1" method="post" action="checklogin.php">

and $_SESSION[‘url’] is getting correctly set on this page too.

checklogin.php looks like this:

<?php
session_start();

print_r($_SESSION['url']);

ob_start();
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 
$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);
$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_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 "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:$_SESSION['url']");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>

As you can see I am trying to print $_SESSION[‘url’] at the top of this script but nothing is getting returned.

Could someone help with this?

Thanks,

Nick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:44:14+00:00Added an answer on June 5, 2026 at 8:44 am

    You cannot insert a “complex” variable like $_SESSION[‘url’] inside a litteral string, like the following statement:

    header("location:$_SESSION['url']");
    

    In my version of PHP (5.3.10), it produces the following error:

    PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
    expecting T_STRING or T_VARIABLE or T_NUM_STRING in
    /home/…/test.php on line …

    Indeed, if you want to output a field in an array, you should use concatenation:

    header("Location: " . $_SESSION['url']);
    

    This may be the source of your problem. Depending on PHP configuration, it may not display the error and just output a blank page, check the php logs to be sure.

    The best practice is to use this whenever you want to output the value of a variable in a string.

    For example, do not use echo "Foo: $foo";, use instead echo "Foo : ". $foo;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 pages in my set up here: login.php: The login page that
I have the following function that I use to check a user login, at
I have the following function that checks for a user login. At it's current
I have a basic php login script. I have three fields: username, password, and
I have a login script which generally works for me, but occasionally goes into
Have a matrix report now that has Position, Hours and Wages for a location
I have made an app which will be a FB page tab. Now I
I have an admin page (../index2.php) I would like to log in as my
So, when I run this login script, I get the following error: PHP Warning:
I'm new to PHP and Codeigniter; I did a login page without using Codeigniter,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.