3 Answers
  • 1

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 190


File: /var/www/stackquestions.com/public_html/application/views/question.php
Line: 190
Function: _error_handler

File: /var/www/stackquestions.com/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /var/www/stackquestions.com/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to make a redirect in PHP?

Say the user goes to www.example.com/page.php and I want to redirect them to www.example.com/index.php, how would I do so without the use of a meta refresh? Is it possible?

This could even protect my pages from unauthorized users.

You can use session variables to control access to pages and authorize valid users as well:


    if (!isset( $_SESSION["valid_user"]))

    // Page goes here


Recently, I got cyber attacks and decided, I needed to know the users trying to access the Admin Panel or reserved part of the web Application.

So, I added a log access for the IP address and user sessions in a text file, because I don't want to bother my database.

  • 1
Reply Report

There are two ways to redirection

Using PHP


header("Location: http://example.com/page.php");

Using Jquery

$(document).ready(function(){ location.href = 'http://example.com/page.php'; });

  • 1
Reply Report