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

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 400
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: January 6, 20252025-01-06T09:29:07+00:00 2025-01-06T09:29:07+00:00In: PHP

php – Unable to redirect the to correct URL after form submission with Codeigntier 4

  • 0
  • 0
php – Unable to redirect the to correct URL after form submission with Codeigntier 4

I am having trouble redirecting to /admin/seo after form submission. The script insists to stay at https://www.example.com/admin/seo/submitIndexNow. My form is a simple button as follows:


My controller takes my sitemap.xml and preps it for submission to indexnow. Here is my controller:

data['admin_css']    .= '';
        $this->data['admin_js']     .= '';
        return view('/Admin/SEO/seo_index', $this->data );
    }

    public function submitIndexNow()
    {
        error_reporting(-1);
        ini_set('display_errors', '1');

        // Path to your sitemap
        $sitemapPath="sitemap.xml";
 
        // Load the sitemap
        $sitemap = simplexml_load_file($sitemapPath);
        if ($sitemap === false) {
            return redirect()->to('/admin/seo')
                ->with('warning', 'Failed to open sitemap.xml');
        }
        
        // Extract URLs from the sitemap
        $urlList = [];
        foreach ($sitemap->url as $url) {
            $urlList[] = (string) $url->loc; // Get the  content
        }
        
        // Your API key and key location
        // openssl rand -hex 16
        $apiKey = "[deletedkeyhere]";
        $host = site_url();
        $keyLocation = site_url($apiKey);
        
        // Prepare the payload
        $payload = [
            "host" => $host,
            "key" => $apiKey,
            "keyLocation" => $keyLocation,
            "urlList" => $urlList // List of URLs extracted from the sitemap
        ];
        
        // Convert payload to JSON
        $payloadJson = json_encode($payload, JSON_PRETTY_PRINT);
        
        // Call submitIt() to send the payload
        $this->submitIt($payloadJson);
    }

    public function submitIt($payloadJson)
    {
        // API endpoint for IndexNow
        $endpoint = "https://api.indexnow.org/indexnow";
    
        // Initialize cURL
        $ch = curl_init($endpoint);
    
        // Set cURL options
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadJson);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
        // Execute the request
        $response = curl_exec($ch);
    
        // Get HTTP response code
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
       
        curl_close($ch);
        
        // Handle response
        if ($httpCode === 200) {
            return redirect()->to('/admin/seo')
                ->with('info', 'Success - sitemap.xml was submitted to IndexNow');
        } else {
            return redirect()->to('/admin/seo')
                ->with('warning', 'Failed to submit URLs. HTTP Code: ' . $httpCode)
                ->with('response', $response);
        }
        
    }

}

The submission fails which is fine. Curl has no errors, however, httpCode replies with an error (eg not 200) which is fine but I cannot get the script to redirect back to /admin/seo where I want to display the errors. I always end up at a blank screen at https://www.example.com/admin/seo/submitIndexNow. I know for a fact that the script handles the HTTP response correctly and get to the redirect portion of the script. In fact, it gets to the warning part. If I place something like echo 'here'.die(); just before the return direct, it works… I just can’t get the redirect to go back to /admin/seo. It insists on staying at https://www.example.com/admin/seo/submitIndexNow. Any help super appreciated.

These are my routes:

$routes->add('/admin/seo', 'Admin\SEO\SEO_Controller::SEO_index');
$routes->add('/admin/seo/submitIndexNow', 'Admin\SEO\SEO_Controller::submitIndexNow');

0
  • 0 0 Answers
  • 102 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

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

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

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.